People_search.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // parents/pages/search/search.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { LibSearch, LibManagerSearch} 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. isAll: 0,
  22. addNum:0,
  23. isShow: 0,
  24. list:[],
  25. itemIndex: 0,
  26. items: ['按周阅读量排序', '按借阅热度排序', '按借阅量TOP10排序'],
  27. content: '',
  28. isReturn: 0,
  29. isStaffReturn:0,
  30. isType:false,
  31. managerList:[],
  32. addmanagerList:[],
  33. vipList:[],
  34. nodataArray: {
  35. text: "搜索无结果"
  36. }
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad: function (options) {
  42. if (options.type == 0 || options.type == 1){
  43. this.setData({
  44. isStaffData: 1
  45. });
  46. wx.setNavigationBarTitle({
  47. title: `搜索`,
  48. })
  49. }
  50. if (options.addNum == 1) {
  51. console.log('99')
  52. this.setData({
  53. addNum: 1
  54. });
  55. wx.setNavigationBarTitle({
  56. title: `添加人员`,
  57. })
  58. }
  59. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  60. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  61. this.setData({ options })
  62. console.log(options)
  63. },
  64. /**
  65. * 生命周期函数--监听页面初次渲染完成
  66. */
  67. onReady: function () {
  68. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  69. for (const i in obj) {
  70. this[i] = obj[i]
  71. }
  72. },
  73. /**
  74. * 生命周期函数--监听页面显示
  75. */
  76. onShow: function () {
  77. // this.getData(res => {
  78. // this.setData({ isLoaded: 1 })
  79. // })
  80. },
  81. /**
  82. * 生命周期函数--监听页面隐藏
  83. */
  84. onHide: function () {
  85. },
  86. /**
  87. * 生命周期函数--监听页面卸载
  88. */
  89. onUnload: function () {
  90. },
  91. returnBack:function(){
  92. wx.navigateBack({
  93. })
  94. },
  95. /**
  96. * 页面相关事件处理函数--监听用户下拉动作
  97. */
  98. onPullDownRefresh: function () {
  99. const { isAll, options } = this.data
  100. const { type = 1 } = options
  101. if (type == 1) return
  102. this.setData({ pageNo: 1 })
  103. this.getData(res => {
  104. wx.stopPullDownRefresh()
  105. })
  106. },
  107. /**
  108. * 页面上拉触底事件的处理函数
  109. */
  110. onReachBottom: function () {
  111. const { isAll, options } = this.data
  112. const { type = 1 } = options
  113. if (type == 1 || isAll) return
  114. this.getData()
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function () {
  120. if (isFn(sharePage)) return sharePage()
  121. },
  122. /**
  123. * 选择跳转进入页
  124. */
  125. NavigateToInfo: function (e) {
  126. const { index } = e.currentTarget.dataset
  127. navigateTo({
  128. url: 'president/pages/Personnel_edit/Personnel_edit',
  129. })
  130. },
  131. /**
  132. * 获取搜索数据
  133. */
  134. getData: function (cb) {
  135. const continuousFn = { fn: this.getData, param: { ...arguments } }
  136. const { options, content, managerList=[], vipList=[] } = this.data
  137. const { libId } = options
  138. LibSearch({ data: { name:content, libId, }, continuousFn }).then(res => {
  139. const { managerList, vipList } = res.data
  140. this.setData({ managerList: managerList, vipList: vipList })
  141. console.log(managerList)
  142. console.log(vipList)
  143. cb && cb(res)
  144. }).catch(res => {
  145. cb && cb(res)
  146. })
  147. },
  148. /**
  149. * 获取添加人员搜索数据
  150. */
  151. getaddNumData: function (cb) {
  152. const continuousFn = { fn: this.getaddNumData, param: { ...arguments } }
  153. const { options, content, addmanagerList = [], } = this.data
  154. const { libId } = options
  155. LibManagerSearch({ data: { name: content, libId, }, continuousFn }).then(res => {
  156. const { list} = res.data
  157. this.setData({ addmanagerList: list })
  158. cb && cb(res)
  159. }).catch(res => {
  160. cb && cb(res)
  161. })
  162. },
  163. /**
  164. /**
  165. * 输入搜索值获取添加人员搜索数据
  166. */
  167. inputaddNumSearchCtl: function (e) {
  168. const { value } = e.detail
  169. const { content } = this.data
  170. if (content == value) {
  171. return
  172. }
  173. this.setData({ content: value, isReturn: 1, pageNo: 1 })
  174. this.getaddNumData()
  175. },
  176. /**
  177. * 输入搜索值
  178. */
  179. inputSearchCtl: function (e) {
  180. const { value } = e.detail
  181. const { content, managerList = [], vipList = [] } = this.data
  182. if (content == value) {
  183. return
  184. }
  185. this.setData({ content: value, pageNo: 1, isStaffReturn: 1, managerList:[], vipList:[]})
  186. this.getData()
  187. },
  188. /**
  189. * 清除搜索值
  190. */
  191. clearSearchCtl: function () {
  192. this.setData({ content: '' })
  193. },
  194. /**
  195. * 提交搜索值
  196. */
  197. submitSearchCtl: function () {
  198. this.setData({ isReturn: 1, pageNo: 1 })
  199. this.getData()
  200. },
  201. })