warehouse_serch.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. },
  23. onLoad() {
  24. // this.list(null)
  25. },
  26. // 仓库详细页
  27. bindViewDetails(e) {
  28. let warehouse_details = e.currentTarget.dataset.index
  29. wx.navigateTo({
  30. url: '../details/warehouse_details?details=' + JSON.stringify(warehouse_details)
  31. })
  32. },
  33. searchEnterprise(e) {
  34. var obj = new Object()
  35. this.setData({
  36. serchValue: e.detail.value,
  37. warehouseList: [],
  38. hidden: true,
  39. loadingData: false,
  40. isRefresh: true,
  41. total: 0,
  42. pageNum: 1, // 页
  43. })
  44. obj.warehouseName = e.detail.value
  45. obj.pageNum = this.data.pageNum
  46. obj.pageSize = 10
  47. obj.reasonable = false
  48. this.list(obj)
  49. },
  50. list(data) {
  51. http.send_get("/system/AppWarehouseController/getWarehouseList", data, this.getWareHouseListSuccess)
  52. },
  53. getWareHouseListSuccess(res) {
  54. if (res.code == 200) {
  55. // 显示加载图标
  56. wx.showLoading({
  57. title: '玩命加载中',
  58. })
  59. var that = this
  60. if (res.data.rows.length == 0) {
  61. wx.showToast({
  62. title: '暂无更多数据',
  63. icon: "none"
  64. })
  65. }
  66. if (this.data.isRefresh) {
  67. this.setData({
  68. warehouseList: res.data.rows,
  69. total: res.data.total
  70. })
  71. // 隐藏导航栏加载框
  72. setTimeout(function () {
  73. that.setData({
  74. loadingData: false
  75. });
  76. wx.hideNavigationBarLoading();
  77. // 停止下拉动作
  78. wx.stopPullDownRefresh();
  79. wx.hideLoading()
  80. }, 1000)
  81. } else {
  82. this.setData({
  83. warehouseList: this.data.warehouseList.concat(res.data.rows)
  84. })
  85. // 隐藏加载框
  86. setTimeout(function () {
  87. that.setData({
  88. hidden: true,
  89. loadingData: false
  90. });
  91. wx.hideLoading();
  92. }, 1000)
  93. }
  94. } else {
  95. console.log("@@!", "请求失败")
  96. }
  97. },
  98. onPullDownRefresh: function () {
  99. // 显示顶部刷新图标
  100. if (this.data.serchValue == "") {
  101. wx.showToast({
  102. title: '请输入搜索内容',
  103. icon: 'error'
  104. })
  105. return
  106. }
  107. wx.showNavigationBarLoading();
  108. var that = this;
  109. var loadingData = this.data.loadingData
  110. if (loadingData) {
  111. return;
  112. }
  113. that.setData({
  114. pageNum: 1,
  115. isRefresh: true
  116. })
  117. let obj = new Object()
  118. obj.pageNum = this.data.pageNum
  119. obj.pageSize = 10
  120. obj.reasonable = false
  121. this.list(obj)
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom: function () {
  127. let that = this
  128. var loadingData = that.data.loadingData
  129. var hidden = that.data.hidden
  130. // 页数+1
  131. that.setData({
  132. pageNum: that.data.pageNum + 1,
  133. isRefresh: false
  134. })
  135. if (hidden) {
  136. that.setData({
  137. hidden: false
  138. });
  139. console.info(that.data.hidden);
  140. }
  141. if (loadingData) {
  142. return;
  143. }
  144. that.setData({
  145. loadingData: true
  146. });
  147. //console.log("@@@@"+Math.ceil(this.data.total/10))
  148. // if(Math.ceil(that.data.total/10)>=that.data.pageNum){
  149. // that.loadData();
  150. let obj = new Object()
  151. obj.pageNum = that.data.pageNum
  152. obj.pageSize = 10
  153. obj.reasonable = false
  154. that.list(obj)
  155. // }else{
  156. // setTimeout(function () {
  157. // that.setData({
  158. // hidden: true,
  159. // });
  160. // }, 2000)
  161. // }
  162. },
  163. })