good_books.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. // president/pages/good_books/good_books.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { GoodBooksToRead, CallOutBooks, CallInBooks } 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. navIndex: 0,
  16. navList: [
  17. {
  18. text: '主题系列',
  19. title: '',
  20. list: [],
  21. stat: 1,
  22. pageSize: 5,
  23. pageNo: 1,
  24. isAll: 0,
  25. isShow: 0,
  26. itemIndex: 0,
  27. items: ['根据入馆时间排序', '根据主题总体借阅量排序'],
  28. nodataArray: {
  29. text: '暂没有本次借阅书单',
  30. image: '../../../assets/nodata_1.png',
  31. hasNodataBtn: 1,
  32. btnText: '扫码借书'
  33. }
  34. },
  35. {
  36. text: '好书推荐',
  37. title: '',
  38. list: [],
  39. stat: 2,
  40. pageSize: 5,
  41. pageNo: 1,
  42. isAll: 0,
  43. isShow: 0,
  44. itemIndex: 0,
  45. items: ['根据入馆时间排序', '根据主题总体借阅量排序'],
  46. nodataArray: {
  47. text: '暂没有正在借阅书单',
  48. image: '../../../assets/nodata_2.png',
  49. hasNodataBtn: 1,
  50. btnText: '扫码借书'
  51. }
  52. }
  53. ],
  54. footerData: {
  55. actIndex: 1,
  56. list: [
  57. {
  58. text: '在馆书籍',
  59. icon: '../../../assets/zai_guan_shu_ji_gray.png',
  60. actIcon: '../../../assets/zai_guan_shu_ji_blue.png',
  61. url: 'president/pages/home/home',
  62. zindex: 3
  63. },
  64. {
  65. text: '好书推荐',
  66. icon: '../../../assets/wish_gray.png',
  67. actIcon: '../../../assets/wish_blue.png',
  68. url: 'president/pages/good_books_new/good_books_new',
  69. zindex: 3
  70. },
  71. {
  72. text: '调书清单',
  73. icon: '../../../assets/diao_shu_qing_dan_gray.png',
  74. actIcon: '../../../assets/diao_shu_qing_dan_blue.png',
  75. url: 'president/pages/book_inventory/book_inventory',
  76. zindex: 3
  77. }
  78. ]
  79. },
  80. nodataArray: {
  81. text: "暂无数据"
  82. }
  83. },
  84. /**
  85. * 生命周期函数--监听页面加载
  86. */
  87. onLoad: function (options) {
  88. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  89. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  90. this.setData({ options })
  91. this.getData(res => {
  92. this.setData({ isLoaded: 1 })
  93. })
  94. },
  95. /**
  96. * 生命周期函数--监听页面初次渲染完成
  97. */
  98. onReady: function () {
  99. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  100. for (const i in obj) {
  101. this[i] = obj[i]
  102. }
  103. },
  104. /**
  105. * 生命周期函数--监听页面显示
  106. */
  107. onShow: function () {
  108. },
  109. /**
  110. * 生命周期函数--监听页面隐藏
  111. */
  112. onHide: function () {
  113. },
  114. /**
  115. * 生命周期函数--监听页面卸载
  116. */
  117. onUnload: function () {
  118. },
  119. /**
  120. * 页面相关事件处理函数--监听用户下拉动作
  121. */
  122. onPullDownRefresh: function () {
  123. const temp = {}
  124. temp[`navList[${navIndex}].pageNo`] = 1
  125. this.setData(temp)
  126. this.getData(() => {
  127. wx.stopPullDownRefresh()
  128. })
  129. },
  130. /**
  131. * 页面上拉触底事件的处理函数
  132. */
  133. onReachBottom: function () {
  134. const { navIndex, navList } = this.data
  135. const { isAll } = navList[navIndex]
  136. if (isAll) return
  137. this.getData()
  138. },
  139. /**
  140. * 用户点击右上角分享
  141. */
  142. onShareAppMessage: function () {
  143. if (isFn(sharePage)) return sharePage()
  144. },
  145. /**
  146. * 选择导航栏
  147. */
  148. selectNavCtl: function (e) {
  149. const { index } = e.currentTarget.dataset
  150. const { navIndex, navList } = this.data
  151. if (navIndex == index) return
  152. this.setData({ navIndex: index })
  153. const { list } = navList[index]
  154. if (list.length > 0) return
  155. this.getData()
  156. },
  157. /**
  158. * 输入搜索值
  159. */
  160. inputSearchCtl: function (e) {
  161. const { value } = e.detail
  162. const { navIndex, navList } = this.data
  163. const { title } = navList[navIndex]
  164. if (title == value) return
  165. const temp = {}
  166. temp[`navList[${navIndex}].title`] = value
  167. this.setData(temp)
  168. },
  169. /**
  170. * 清除搜索值
  171. */
  172. clearSearchCtl: function () {
  173. const { navIndex, navList } = this.data
  174. const temp = {}
  175. temp[`navList[${navIndex}].title`] = ''
  176. this.setData(temp)
  177. },
  178. /**
  179. * 提交搜索值
  180. */
  181. submitSearchCtl: function () {
  182. const { navIndex, navList } = this.data
  183. const temp = {}
  184. temp[`navList[${navIndex}].pageNo`] = 1
  185. this.setData(temp)
  186. this.getData()
  187. },
  188. /**
  189. * 展示选择框
  190. */
  191. toggleItemCtl: function () {
  192. const { navIndex, navList } = this.data
  193. const { isShow } = navList[navIndex]
  194. const temp = {}
  195. temp[`navList[${navIndex}].isShow`] = !isShow
  196. this.setData(temp)
  197. },
  198. /**
  199. * 展示选择框
  200. */
  201. selectItemCtl: function (e) {
  202. const { index } = e.currentTarget.dataset
  203. const { navIndex, navList } = this.data
  204. const { itemIndex, items } = navList[navIndex]
  205. const temp = {}
  206. temp[`navList[${navIndex}].itemIndex`] = index
  207. temp[`navList[${navIndex}].isShow`] = 0
  208. temp[`navList[${navIndex}].pageNo`] = 1
  209. this.setData(temp)
  210. this.getData()
  211. },
  212. /**
  213. * 主题系列的书籍
  214. */
  215. getData: function (cb) {
  216. const continuousFn = { fn: this.getData, param: { ...arguments } }
  217. const { navIndex, navList } = this.data
  218. const { pageNo, pageSize, itemIndex, stat, title, list } = navList[navIndex]
  219. GoodBooksToRead({ data: { pageNo, pageSize, type: ~~itemIndex + 1, stat, title }, continuousFn }).then(res => {
  220. const newList = res.data.list
  221. let tempList = []
  222. if (pageNo == 1) {
  223. tempList = [].concat(newList)
  224. } else {
  225. tempList = [].concat(list, newList)
  226. }
  227. const temp = {}
  228. temp[`navList[${navIndex}].list`] = tempList
  229. temp[`navList[${navIndex}].pageNo`] = newList.length == pageSize ? ~~pageNo + 1 : pageNo
  230. temp[`navList[${navIndex}].isAll`] = newList.length < pageSize
  231. this.setData(temp)
  232. cb && cb(res)
  233. }).catch(res => {
  234. cb && cb(res)
  235. })
  236. },
  237. /**
  238. * 调出书籍
  239. */
  240. getBooksCtl: function (e) {
  241. const continuousFn = { fn: this.getBooksCtl, param: { ...arguments } }
  242. const { index } = e.currentTarget.dataset
  243. const { options, navIndex, navList } = this.data
  244. const { libId } = options
  245. const { list } = navList[navIndex]
  246. const { book_detail_id, book_info_id, isbn13 } = list[index]
  247. CallInBooks({ data: { libId, bookInfoId: book_info_id, bookDetailId: book_detail_id, isbn13 }, continuousFn}).then(res => {
  248. wx.showToast({
  249. title: `已加入调入列表`
  250. })
  251. this.getData()
  252. })
  253. }
  254. })