search.js 4.4 KB

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