search.js 4.4 KB

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