search.js 4.0 KB

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