Members_search.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // parents/pages/search/search.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { AgencyVipList} from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, hasLibraryService, hasVipService } = getApp()
  6. const { baseImgUrl, thumbnail, qrcodeInvalidToastText, borrowToastText, reservationsToastText, wishToastText } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. thumbnail,
  13. baseImgUrl,
  14. borrowToastText,
  15. reservationsToastText,
  16. wishToastText,
  17. isLoaded: 1,
  18. isStaffData: 0,
  19. pageSize: 10,
  20. pageNo: 1,
  21. isResult: false,
  22. isAll: 0,
  23. isDown: false,
  24. isShow: 0,
  25. list:[],
  26. itemIndex: 0,
  27. items: ['按周阅读量排序', '按借阅热度排序', '按借阅量TOP10排序'],
  28. content: '',
  29. isReturn: 0,
  30. nodataArray: {
  31. text: "搜索无结果"
  32. }
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad: function (options) {
  38. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  39. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  40. this.setData(options)
  41. },
  42. /**
  43. * 生命周期函数--监听页面初次渲染完成
  44. */
  45. onReady: function () {
  46. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  47. for (const i in obj) {
  48. this[i] = obj[i]
  49. }
  50. },
  51. /**
  52. * 生命周期函数--监听页面显示
  53. */
  54. onShow: function () {
  55. // this.getData(res => {
  56. // this.setData({ isLoaded: 1 })
  57. // })
  58. },
  59. /**
  60. * 生命周期函数--监听页面隐藏
  61. */
  62. onHide: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面卸载
  66. */
  67. onUnload: function () {
  68. },
  69. returnBack:function(){
  70. wx.navigateBack({
  71. })
  72. },
  73. /**
  74. * 页面相关事件处理函数--监听用户下拉动作
  75. */
  76. onPullDownRefresh: function () {
  77. const { isAll, options } = this.data
  78. const { type = 1 } = options
  79. if (type == 1) return
  80. this.setData({ pageNo: 1 })
  81. this.getData(res => {
  82. wx.stopPullDownRefresh()
  83. })
  84. },
  85. /**
  86. * 页面上拉触底事件的处理函数
  87. */
  88. onReachBottom: function () {
  89. const { isAll, options } = this.data
  90. const { type = 1 } = options
  91. if (type == 1 || isAll) return
  92. this.getData()
  93. },
  94. /**
  95. * 用户点击右上角分享
  96. */
  97. onShareAppMessage: function () {
  98. if (isFn(sharePage)) return sharePage()
  99. },
  100. /**
  101. * 选择跳转进入页
  102. */
  103. NavigateToInfo: function (e) {
  104. const { index } = e.currentTarget.dataset
  105. navigateTo({
  106. url: 'president/pages/Personnel_edit/Personnel_edit',
  107. })
  108. },
  109. /**
  110. * 获取搜索数据
  111. */
  112. /**
  113. * 获取书籍数据
  114. */
  115. getData: function (cb) {
  116. const continuousFn = { fn: this.getData, param: { ...arguments } }
  117. const { pageNo, pageSize, list, libId, childName, content } = this.data
  118. AgencyVipList({ data: { libId, pageNo, pageSize, childName: content }, continuousFn }).then(res => {
  119. const { list } = res.data
  120. let listTemp = []
  121. if (pageNo == 1) {
  122. listTemp = [].concat(list)
  123. } else {
  124. listTemp = [].concat(this.data.list, list)
  125. }
  126. const correctListTemp = (res => {
  127. console.log(res)
  128. var d = []
  129. for (let i in res) {
  130. res[i].number = 0
  131. }
  132. return res
  133. })(listTemp)
  134. this.setData({ list: correctListTemp, pageNo: list.length == pageSize ? pageNo + 1 : pageNo, isAll: list.length < pageSize })
  135. cb && cb(res)
  136. }).catch(res => {
  137. cb && cb(res)
  138. })
  139. },
  140. /**
  141. * 输入搜索值
  142. */
  143. inputSearchCtl: function (e) {
  144. const { value } = e.detail
  145. const { content } = this.data
  146. if (content == value) {
  147. return
  148. }
  149. this.setData({ content: value, pageNo: 1})
  150. this.setData({ isResult: true })
  151. this.getData()
  152. },
  153. /**
  154. * 清除搜索值
  155. */
  156. clearSearchCtl: function () {
  157. this.setData({ content: '' })
  158. },
  159. /**
  160. * 提交搜索值
  161. */
  162. submitSearchCtl: function () {
  163. this.setData({ isReturn: 1, pageNo: 1 })
  164. this.getData()
  165. },
  166. })