warehouse_serch.js 4.3 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. }
  111. },
  112. onPullDownRefresh: function () {
  113. // 显示顶部刷新图标
  114. if (this.data.serchValue == "") {
  115. wx.showToast({
  116. title: '请输入搜索内容',
  117. icon: 'error'
  118. })
  119. return
  120. }
  121. wx.showNavigationBarLoading();
  122. var that = this;
  123. var loadingData = this.data.loadingData
  124. if (loadingData) {
  125. return;
  126. }
  127. that.setData({
  128. pageNum: 1,
  129. isRefresh: true
  130. })
  131. let obj = new Object()
  132. obj.pageNum = this.data.pageNum
  133. obj.warehouseName = this.data.serchValue
  134. obj.pageSize = 10
  135. obj.reasonable = false
  136. obj.longitude=this.data.longitude
  137. obj.latitude=this.data.latitude
  138. this.list(obj)
  139. },
  140. /**
  141. * 页面上拉触底事件的处理函数
  142. */
  143. onReachBottom: function () {
  144. let that = this
  145. var loadingData = that.data.loadingData
  146. var hidden = that.data.hidden
  147. // 页数+1
  148. that.setData({
  149. pageNum: that.data.pageNum + 1,
  150. isRefresh: false
  151. })
  152. if (hidden) {
  153. that.setData({
  154. hidden: false
  155. });
  156. console.info(that.data.hidden);
  157. }
  158. if (loadingData) {
  159. return;
  160. }
  161. that.setData({
  162. loadingData: true
  163. });
  164. //console.log("@@@@"+Math.ceil(this.data.total/10))
  165. // if(Math.ceil(that.data.total/10)>=that.data.pageNum){
  166. // that.loadData();
  167. let obj = new Object()
  168. obj.pageNum = that.data.pageNum
  169. obj.warehouseName = that.data.serchValue
  170. obj.pageSize = 10
  171. obj.reasonable = false
  172. obj.longitude=that.data.longitude
  173. obj.latitude=that.data.latitude
  174. that.list(obj)
  175. // }else{
  176. // setTimeout(function () {
  177. // that.setData({
  178. // hidden: true,
  179. // });
  180. // }, 2000)
  181. // }
  182. },
  183. })