search_headquarters_books.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // president/pages/home/home.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { GetBooksTab, GetBooksInlibrary, CallOutBooks } from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData } = getApp()
  6. const { baseImgUrl, thumbnail } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. thumbnail,
  14. isLoaded: 0,
  15. title: '',
  16. pageSize: 10,
  17. pageNo: 1,
  18. isAll: 0,
  19. isLoad: false,
  20. selextIndex: 0,
  21. gradeListArry: [],
  22. themeListArry: [],
  23. isShow: 0,
  24. isShowPromptModel: true,
  25. itemIndex: 0,
  26. items: ['根据入馆时间排序', '根据书籍借阅量排序', '根据馆藏稀缺度排序'],
  27. list: [
  28. ],
  29. footerData: {
  30. actIndex: 0,
  31. list: [
  32. {
  33. text: '在馆书籍',
  34. icon: '../../../assets/zai_guan_shu_ji_gray.png',
  35. actIcon: '../../../assets/zai_guan_shu_ji_blue.png',
  36. url: 'president/pages/home/home',
  37. zindex: 3
  38. },
  39. {
  40. text: '好书推荐',
  41. icon: '../../../assets/wish_gray.png',
  42. actIcon: '../../../assets/wish_blue.png',
  43. url: 'president/pages/good_books_new/good_books_new',
  44. zindex: 3
  45. },
  46. {
  47. text: '调书清单',
  48. icon: '../../../assets/diao_shu_qing_dan_gray.png',
  49. actIcon: '../../../assets/diao_shu_qing_dan_blue.png',
  50. url: 'president/pages/book_inventory/book_inventory',
  51. zindex: 3
  52. }
  53. ]
  54. },
  55. nodataArray: {
  56. text: "暂无数据"
  57. }
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad: function (options) {
  63. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  64. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  65. this.setData({ options })
  66. const { title } = this.data
  67. this.setData({
  68. title: options.title
  69. })
  70. this.getData(res => {
  71. this.setData({ isLoaded: 1 })
  72. })
  73. },
  74. /**
  75. * 生命周期函数--监听页面初次渲染完成
  76. */
  77. onReady: function () {
  78. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  79. for (const i in obj) {
  80. this[i] = obj[i]
  81. }
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面隐藏
  90. */
  91. onHide: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面卸载
  95. */
  96. onUnload: function () {
  97. },
  98. /**
  99. * 页面相关事件处理函数--监听用户下拉动作
  100. */
  101. onPullDownRefresh: function () {
  102. this.setData({ pageNo: 1 })
  103. this.getData(res => {
  104. wx.stopPullDownRefresh()
  105. })
  106. },
  107. /**
  108. * 页面上拉触底事件的处理函数
  109. */
  110. onReachBottom: function () {
  111. const { isAll, isDown } = this.data
  112. if (isAll) {
  113. this.setData({ isDown: true })
  114. return
  115. } else {
  116. this.setData({ isLoad: true, isDown: false })
  117. this.getData(() => {
  118. this.setData({ isLoad: false })
  119. })
  120. }
  121. },
  122. /**
  123. * 用户点击右上角分享
  124. */
  125. onShareAppMessage: function () {
  126. if (isFn(sharePage)) return sharePage()
  127. },
  128. TipSelect: function (e) {
  129. debugger
  130. const { index } = e.currentTarget.dataset
  131. const { selextIndex } = this.data
  132. if (selextIndex == index) return
  133. this.setData({ selextIndex: index })
  134. this.getData()
  135. },
  136. /**
  137. * 展示选择框
  138. */
  139. showItemCtl: function () {
  140. const { isShow } = this.data
  141. this.setData({ isShow: !isShow })
  142. },
  143. MessageconfirmClose: function () {
  144. const { isShowPromptModel } = this.data
  145. this.setData({ isShowPromptModel: !isShowPromptModel })
  146. },
  147. /**
  148. * 展示选择框
  149. */
  150. selectItemCtl: function (e) {
  151. const { index } = e.currentTarget.dataset
  152. const { itemIndex, items } = this.data
  153. if (index == itemIndex) return
  154. this.setData({ itemIndex: index, isShow: 0, pageNo: 1 })
  155. this.getData()
  156. },
  157. /**
  158. * 获取书籍数据
  159. */
  160. getData: function (cb) {
  161. const continuousFn = { fn: this.getData, param: { ...arguments } }
  162. const { content, options, pageNo, pageSize, itemIndex, title } = this.data
  163. const { libId } = this.data.options;
  164. GetBooksInlibrary({ data: { libId, pageNo, pageSize, type: ~~itemIndex + 1, title }, continuousFn }).then(res => {
  165. const { list } = res.data
  166. let listTemp = []
  167. if (pageNo == 1) {
  168. listTemp = [].concat(list)
  169. } else {
  170. listTemp = [].concat(this.data.list, list)
  171. }
  172. this.setData({ list: listTemp, pageNo: list.length == pageSize ? pageNo + 1 : pageNo, isAll: list.length < pageSize })
  173. cb && cb(res)
  174. }).catch(res => {
  175. cb && cb(res)
  176. })
  177. },
  178. /**
  179. * 输入搜索值
  180. */
  181. inputSearchCtl: function (e) {
  182. const { value } = e.detail
  183. const { title } = this.data
  184. if (title == value) return
  185. const temp = {}
  186. temp[`title`] = value
  187. this.setData(temp)
  188. },
  189. /**
  190. * 清除搜索值
  191. */
  192. clearSearchCtl: function () {
  193. const temp = {}
  194. temp[`title`] = ''
  195. this.setData(temp)
  196. },
  197. /**
  198. * 提交搜索值
  199. */
  200. submitSearchCtl: function () {
  201. const temp = {}
  202. temp[`pageNo`] = 1
  203. this.setData(temp)
  204. this.getData()
  205. },
  206. })