search.js 4.7 KB

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