search_books.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. // president/pages/home/home.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { BookDetailView, GetLibraryTopTen, 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. isResult:false,
  20. GrangeList: ['学前段', '低年段', '中年段', '高年段'],
  21. bookList: [
  22. {
  23. name: '在馆书籍',
  24. amount: '',
  25. unit: '本'
  26. },
  27. {
  28. name: '服务期会员',
  29. amount: '',
  30. unit: '人'
  31. },
  32. {
  33. name: '在借书籍',
  34. amount: '',
  35. unit: '本'
  36. },
  37. ],
  38. isShow: 0,
  39. itemIndex: 0,
  40. items: ['根据入馆时间排序', '根据书籍借阅量排序', '根据馆藏稀缺度排序'],
  41. list: [
  42. // {
  43. // "heat": "1",
  44. // "local_image": "",
  45. // "isbn13": "9787539158013",
  46. // "book_info_id": "992f05d8-ab46-11e8-93e1-00163e0c97b1",
  47. // "book_detail_id": "08be3ac9-a526-11e8-93e1-00163e0c97b1",
  48. // "theme": "大语文-传统国学",
  49. // "title": "新课标小学语文阅读丛书"
  50. // },
  51. // {
  52. // "heat": "2",
  53. // "local_image": "",
  54. // "isbn13": "97878072112663",
  55. // "book_info_id": "992fc438-ab46-11e8-93e1-00163e0c97b1",
  56. // "book_detail_id": "08be828c-a526-11e8-93e1-00163e0c97b1",
  57. // "theme": "情感梦想",
  58. // "title": "儿童职业启蒙美绘本-我要当建筑师"
  59. // }
  60. ],
  61. footerData: {
  62. actIndex: 0,
  63. list: [
  64. {
  65. text: '在馆书籍',
  66. icon: '../../../assets/zai_guan_shu_ji_gray.png',
  67. actIcon: '../../../assets/zai_guan_shu_ji_blue.png',
  68. url: 'president/pages/home/home',
  69. zindex: 3
  70. },
  71. {
  72. text: '好书推荐',
  73. icon: '../../../assets/wish_gray.png',
  74. actIcon: '../../../assets/wish_blue.png',
  75. url: 'president/pages/good_books_new/good_books_new',
  76. zindex: 3
  77. },
  78. {
  79. text: '调书清单',
  80. icon: '../../../assets/diao_shu_qing_dan_gray.png',
  81. actIcon: '../../../assets/diao_shu_qing_dan_blue.png',
  82. url: 'president/pages/book_inventory/book_inventory',
  83. zindex: 3
  84. }
  85. ]
  86. },
  87. nodataArray: {
  88. text: "暂无数据~"
  89. }
  90. },
  91. /**
  92. * 生命周期函数--监听页面加载
  93. */
  94. onLoad: function (options) {
  95. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  96. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  97. this.setData({ options })
  98. this.getData(res => {
  99. this.setData({ isLoaded: 1 })
  100. })
  101. },
  102. /**
  103. * 生命周期函数--监听页面初次渲染完成
  104. */
  105. onReady: function () {
  106. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  107. for (const i in obj) {
  108. this[i] = obj[i]
  109. }
  110. },
  111. /**
  112. * 生命周期函数--监听页面显示
  113. */
  114. onShow: function () {
  115. },
  116. /**
  117. * 生命周期函数--监听页面隐藏
  118. */
  119. onHide: function () {
  120. },
  121. /**
  122. * 生命周期函数--监听页面卸载
  123. */
  124. onUnload: function () {
  125. },
  126. /**
  127. * 页面相关事件处理函数--监听用户下拉动作
  128. */
  129. onPullDownRefresh: function () {
  130. // this.setData({ pageNo: 1 })
  131. // this.getData(res => {
  132. // wx.stopPullDownRefresh()
  133. // })
  134. },
  135. /**
  136. * 页面上拉触底事件的处理函数
  137. */
  138. onReachBottom: function () {
  139. // const { isAll } = this.data
  140. // if (isAll) return
  141. // this.getData()
  142. },
  143. /**
  144. * 用户点击右上角分享
  145. */
  146. onShareAppMessage: function () {
  147. if (isFn(sharePage)) return sharePage()
  148. },
  149. /**
  150. * 展示选择框
  151. */
  152. showItemCtl: function () {
  153. const { isShow } = this.data
  154. this.setData({ isShow: !isShow })
  155. },
  156. /**
  157. * 展示选择框
  158. */
  159. selectItemCtl: function (e) {
  160. const { index } = e.currentTarget.dataset
  161. const { itemIndex, items } = this.data
  162. if (index == itemIndex) return
  163. this.setData({ itemIndex: index, isShow: 0, pageNo: 1 })
  164. this.getData()
  165. },
  166. /**
  167. * 获取书籍数据
  168. */
  169. getData: function (cb) {
  170. const continuousFn = { fn: this.getData, param: { ...arguments } }
  171. const { content, options, pageNo, pageSize, itemIndex, title } = this.data
  172. const { libId } = this.data.options;
  173. GetLibraryTopTen({ data: { libId, title }, continuousFn }).then(res => {
  174. const { list } = res.data
  175. let listTemp = []
  176. if (pageNo == 1) {
  177. listTemp = [].concat(list)
  178. } else {
  179. listTemp = [].concat(this.data.list, list)
  180. }
  181. this.setData({ list: listTemp, pageNo: list.length == pageSize ? pageNo + 1 : pageNo, isAll: list.length < pageSize })
  182. cb && cb(res)
  183. }).catch(res => {
  184. cb && cb(res)
  185. })
  186. },
  187. /**
  188. * 调出书籍
  189. */
  190. getBooksCtl: function (e) {
  191. const { index } = e.currentTarget.dataset;
  192. const continuousFn = { fn: this.getBooksCtl, param: { ...arguments } }
  193. const { list, options } = this.data
  194. const { libId } = options
  195. const { book_info_id, book_detail_id, isbn13 } = list[index]
  196. CallOutBooks({ data: { libId, bookInfoId: book_info_id, bookDetailId: book_detail_id, isbn13 }, continuousFn }).then(res => {
  197. wx.showToast({
  198. title: `已加入调出列表`
  199. })
  200. this.getData()
  201. })
  202. },
  203. /**
  204. * 输入搜索值
  205. */
  206. inputSearchCtl: function (e) {
  207. const { value } = e.detail
  208. const { title } = this.data
  209. if (title == value) return
  210. const temp = {}
  211. temp[`title`] = value
  212. this.setData(temp)
  213. },
  214. /**
  215. * 清除搜索值
  216. */
  217. clearSearchCtl: function () {
  218. const temp = {}
  219. temp[`title`] = ''
  220. this.setData(temp)
  221. },
  222. /**
  223. * 提交搜索值
  224. */
  225. submitSearchCtl: function () {
  226. const { title } = this.data
  227. if (!title){
  228. wx.showToast({
  229. title: `书名不能为空`,
  230. icon: 'none'
  231. })
  232. return
  233. }
  234. navigateTo({
  235. url: 'president/pages/search_headquarters_books/search_headquarters_books?title=' + title,
  236. })
  237. },
  238. /**
  239. * 搜索页面
  240. */
  241. BooksInfoPage: function (e) {
  242. const { title } = e.currentTarget.dataset
  243. navigateTo({
  244. url: 'president/pages/book_Imformation/book_Imformation?title='+ title ,
  245. })
  246. },
  247. })