warehouse_serch.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import http from '../../../base/httputil'
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 组件的初始数据
  6. */
  7. data: {
  8. host: app.globalData.host,
  9. warehouseList: [],
  10. /**
  11. * 控制上拉到底部时是否出现 "数据加载中..."
  12. */
  13. hidden: true,
  14. /**
  15. * 数据是否正在加载中,避免数据多次加载
  16. */
  17. loadingData: false,
  18. isRefresh: true,
  19. total: 0,
  20. pageNum: 1, // 页码
  21. serchValue: "",
  22. longitude: '',
  23. latitude: ''
  24. },
  25. onLoad() {
  26. // this.list(null)
  27. let that=this
  28. wx.getLocation({
  29. type: 'wgs84',
  30. success: function (res) {
  31. that.setData({
  32. longitude: res.longitude,
  33. latitude: res.latitude
  34. })
  35. //that.loadData()
  36. }
  37. })
  38. },
  39. // 仓库详细页
  40. bindViewDetails(e) {
  41. let warehouse_details = e.currentTarget.dataset.index
  42. wx.navigateTo({
  43. url: '../details/warehouse_details?details=' + JSON.stringify(warehouse_details)
  44. })
  45. },
  46. searchEnterprise(e) {
  47. var obj = new Object()
  48. this.setData({
  49. serchValue: e.detail.value,
  50. warehouseList: [],
  51. hidden: true,
  52. loadingData: false,
  53. isRefresh: true,
  54. total: 0,
  55. pageNum: 1, // 页
  56. })
  57. obj.warehouseName = e.detail.value
  58. obj.pageNum = this.data.pageNum
  59. obj.pageSize = 10
  60. obj.reasonable = false
  61. obj.longitude=this.data.longitude
  62. obj.latitude=this.data.latitude
  63. this.list(obj)
  64. },
  65. list(data) {
  66. http.send_get("/system/AppWarehouseController/getWarehouseList", data, this.getWareHouseListSuccess)
  67. },
  68. getWareHouseListSuccess(res) {
  69. if (res.code == 200) {
  70. // 显示加载图标
  71. wx.showLoading({
  72. title: '玩命加载中',
  73. })
  74. var that = this
  75. if (res.data.rows.length == 0) {
  76. wx.showToast({
  77. title: '暂无更多数据',
  78. icon: "none"
  79. })
  80. }
  81. if (this.data.isRefresh) {
  82. this.setData({
  83. warehouseList: res.data.rows,
  84. total: res.data.total
  85. })
  86. // 隐藏导航栏加载框
  87. setTimeout(function () {
  88. that.setData({
  89. loadingData: false
  90. });
  91. wx.hideNavigationBarLoading();
  92. // 停止下拉动作
  93. wx.stopPullDownRefresh();
  94. wx.hideLoading()
  95. }, 1000)
  96. } else {
  97. this.setData({
  98. warehouseList: this.data.warehouseList.concat(res.data.rows)
  99. })
  100. // 隐藏加载框
  101. setTimeout(function () {
  102. that.setData({
  103. hidden: true,
  104. loadingData: false
  105. });
  106. wx.hideLoading();
  107. }, 1000)
  108. }
  109. } else {
  110. console.log("@@!", "请求失败")
  111. }
  112. },
  113. onPullDownRefresh: function () {
  114. // 显示顶部刷新图标
  115. if (this.data.serchValue == "") {
  116. wx.showToast({
  117. title: '请输入搜索内容',
  118. icon: 'error'
  119. })
  120. return
  121. }
  122. wx.showNavigationBarLoading();
  123. var that = this;
  124. var loadingData = this.data.loadingData
  125. if (loadingData) {
  126. return;
  127. }
  128. that.setData({
  129. pageNum: 1,
  130. isRefresh: true
  131. })
  132. let obj = new Object()
  133. obj.pageNum = this.data.pageNum
  134. obj.warehouseName = this.data.serchValue
  135. obj.pageSize = 10
  136. obj.reasonable = false
  137. obj.longitude=this.data.longitude
  138. obj.latitude=this.data.latitude
  139. this.list(obj)
  140. },
  141. /**
  142. * 页面上拉触底事件的处理函数
  143. */
  144. onReachBottom: function () {
  145. let that = this
  146. var loadingData = that.data.loadingData
  147. var hidden = that.data.hidden
  148. // 页数+1
  149. that.setData({
  150. pageNum: that.data.pageNum + 1,
  151. isRefresh: false
  152. })
  153. if (hidden) {
  154. that.setData({
  155. hidden: false
  156. });
  157. console.info(that.data.hidden);
  158. }
  159. if (loadingData) {
  160. return;
  161. }
  162. that.setData({
  163. loadingData: true
  164. });
  165. //console.log("@@@@"+Math.ceil(this.data.total/10))
  166. // if(Math.ceil(that.data.total/10)>=that.data.pageNum){
  167. // that.loadData();
  168. let obj = new Object()
  169. obj.pageNum = that.data.pageNum
  170. obj.warehouseName = that.data.serchValue
  171. obj.pageSize = 10
  172. obj.reasonable = false
  173. obj.longitude=that.data.longitude
  174. obj.latitude=that.data.latitude
  175. that.list(obj)
  176. // }else{
  177. // setTimeout(function () {
  178. // that.setData({
  179. // hidden: true,
  180. // });
  181. // }, 2000)
  182. // }
  183. },
  184. })