home.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // dispatcher/pages/home/home.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { DispatcherIndex, DispatcherAudit } from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData } = getApp()
  6. const { baseImgUrl } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. isLoaded: 0,
  14. pageNo: 1,
  15. pageSize: 10,
  16. isAll: 0,
  17. list: [
  18. // {
  19. // "order_num": "1",
  20. // "username": "12154545",
  21. // "league_name": "福建师大雷锋精神连接方式垃圾分类是就发了是家乐福",
  22. // "reg_time": "1436864169",
  23. // "wish_num": "0",
  24. // }
  25. ]
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. this.getData(res => {
  32. this.setData({ isLoaded: 1 })
  33. })
  34. },
  35. /**
  36. * 生命周期函数--监听页面初次渲染完成
  37. */
  38. onReady: function () {
  39. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  40. for (const i in obj) {
  41. this[i] = obj[i]
  42. }
  43. },
  44. /**
  45. * 生命周期函数--监听页面显示
  46. */
  47. onShow: function () {
  48. },
  49. /**
  50. * 生命周期函数--监听页面隐藏
  51. */
  52. onHide: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面卸载
  56. */
  57. onUnload: function () {
  58. },
  59. /**
  60. * 页面相关事件处理函数--监听用户下拉动作
  61. */
  62. onPullDownRefresh: function () {
  63. this.setData({ pageNo: 1 })
  64. this.getData(res => {
  65. wx.stopPullDownRefresh()
  66. })
  67. },
  68. /**
  69. * 页面上拉触底事件的处理函数
  70. */
  71. onReachBottom: function () {
  72. const { isAll = false } = this.data
  73. if (isAll) return
  74. this.getData()
  75. },
  76. /**
  77. * 用户点击右上角分享
  78. */
  79. onShareAppMessage: function () {
  80. if (isFn(sharePage)) return sharePage()
  81. },
  82. /**
  83. * 获取数据
  84. */
  85. getData: function (cb) {
  86. const continuousFn = { fn: this.getData, param: { ...arguments } }
  87. const { content, pageNo, pageSize, list } = this.data
  88. DispatcherIndex({ data: { content, pageNo, pageSize }, continuousFn }).then(res => {
  89. const newList = res.data.list
  90. let listTemp = []
  91. if (pageNo > 1) {
  92. listTemp = [].concat(list, newList)
  93. } else {
  94. listTemp = [].concat(newList)
  95. }
  96. this.setData({ list: listTemp, pageNo: newList.length == pageSize ? pageNo + 1 : pageNo, isAll: newList.length < pageSize })
  97. cb && cb(res)
  98. }).catch(res => {
  99. cb && cb(res)
  100. })
  101. },
  102. /**
  103. * 选择调度馆
  104. */
  105. selectLiCtl: function (e) {
  106. const { index } = e.currentTarget.dataset
  107. const { list } = this.data
  108. const libId = list[index].id || ''
  109. if (libId) {
  110. getApp().globalData.dispatchLibId = libId
  111. wx.setStorageSync(`dispatchLibId_${getGlobalVal('userId')}`, libId)
  112. redirectTo({ url: 'dispatcher/pages/dispatch_go/dispatch_go', paras: { libId }, zindex: 3 })
  113. } else {
  114. wx.showToast({
  115. title: '该馆无效,请换一个馆',
  116. icon: 'none'
  117. })
  118. }
  119. },
  120. /**
  121. * 输入搜索值
  122. */
  123. inputSearchCtl: function (e) {
  124. const { value } = e.detail
  125. const { content } = this.data
  126. if (content == value) return
  127. this.setData({ content: value })
  128. },
  129. /**
  130. * 清除搜索值
  131. */
  132. clearSearchCtl: function () {
  133. this.setData({ content: '' })
  134. },
  135. /**
  136. * 提交搜索值
  137. */
  138. submitSearchCtl: function () {
  139. this.setData({ pageNo: 1 })
  140. this.getData()
  141. },
  142. /**
  143. * 确认拒绝校长馆申请
  144. */
  145. commitDispatcherAuditCtl: function (e) {
  146. const continuousFn = { fn: this.commitDispatcherAuditCtl, param: { ...arguments } }
  147. const { type = 0, index = 0 } = e.currentTarget.dataset
  148. const { list = [] } = this.data
  149. const { id = '' } = list[index]
  150. if (!type || !id) return
  151. DispatcherAudit({ data: { type, libId: id }, continuousFn }).then(res => {
  152. // wx.showToast({
  153. // title: res.msg || '调度员已确认你馆调书申请,请等待调度员与你联系!',
  154. // icon: 'none',
  155. // duration: 5000
  156. // })
  157. this.getData()
  158. cb && cb(res)
  159. }).catch(res => {
  160. // wx.showToast({
  161. // title: res.data.msg || '你馆阅读会员数量还不足35名,请继续加油达到目标哦~',
  162. // icon: 'none',
  163. // duration: 5000
  164. // })
  165. cb && cb(res)
  166. })
  167. }
  168. })