library_books.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. // president//pages/library_books/library_books.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { GetBooksInlibrary, CallOutList, CallInList, GetBooksTab } 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. hiddenModel: false,
  16. screenModel: false,
  17. pageSize: 5,
  18. isShowPromptModel: true,
  19. pageNo: 1,
  20. isAll: 0,
  21. isSelect: false,
  22. isDown: false,
  23. gradeList: [],
  24. themeList: [],
  25. isLoad: false,
  26. isShai: false,
  27. parentCode: [],
  28. classList: [],
  29. bookList: [],
  30. childList: [],
  31. itemIndex: 0,
  32. isCheck: 0,
  33. number: 0,
  34. themeListindex: '',
  35. stat: 2,
  36. list: [
  37. // {
  38. // "heat": "2",
  39. // "local_image": "/2017/05/07/412623a8c9d6b5a0f92c6152d863c2f2a32d08cc78e72afb7d15d01ca172f9e3.jpg",
  40. // "isbn13": "9787539191508",
  41. // "book_info_id": "000c1b25-285e-42ce-8819-17edfd1ece54",
  42. // "book_size": 2,
  43. // "book_detail_id": "0d2d09cb-7817-4ef2-8fa5-e860810aaa80",
  44. // "theme": "大语文-传统国学",
  45. // "title": "谚语集锦"
  46. // },
  47. // {
  48. // "heat": "0",
  49. // "local_image": "/2017/05/04/79df39e1-af29-4fe7-89ca-944435d0ac4f.jpg",
  50. // "isbn13": "9787543566804",
  51. // "book_info_id": "004881ee-3658-47be-b358-106b1d2d4b57",
  52. // "book_size": 1,
  53. // "book_detail_id": "1b8a2d9f-8550-4437-b14b-eba34b736b8c",
  54. // "theme": "科学探究",
  55. // "title": "人人都有写作天赋/美国中小学生人文和科学阅读系列"
  56. // }
  57. ],
  58. HeaderbookList: [
  59. {
  60. name: '在馆书籍',
  61. amount: '',
  62. unit: '本'
  63. },
  64. {
  65. name: '外借书籍',
  66. amount: '',
  67. unit: '人'
  68. },
  69. ],
  70. footerData: {
  71. actIndex: 0,
  72. list: [
  73. {
  74. text: '在馆书籍',
  75. icon: '../../../assets/zai_guan_shu_ji_gray.png',
  76. actIcon: '../../../assets/zai_guan_shu_ji_blue.png',
  77. url: 'president/pages/library_books/library_books',
  78. zindex: 3
  79. },
  80. {
  81. text: '好书推荐',
  82. icon: '../../../assets/wish_gray.png',
  83. actIcon: '../../../assets/wish_blue.png',
  84. url: 'president/pages/good_books_new/good_books_new',
  85. zindex: 3
  86. },
  87. {
  88. text: '调书清单',
  89. icon: '../../../assets/diao_shu_qing_dan_gray.png',
  90. actIcon: '../../../assets/diao_shu_qing_dan_blue.png',
  91. url: 'president/pages/book_inventory/book_inventory',
  92. zindex: 3
  93. }
  94. ]
  95. },
  96. nodataArray: {
  97. text: "暂无数据"
  98. }
  99. },
  100. /**
  101. * 生命周期函数--监听页面加载
  102. */
  103. onLoad: function (options) {
  104. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  105. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  106. this.setData(options)
  107. },
  108. /**
  109. * 生命周期函数--监听页面初次渲染完成
  110. */
  111. onReady: function () {
  112. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  113. for (const i in obj) {
  114. this[i] = obj[i]
  115. }
  116. },
  117. /**
  118. * 生命周期函数--监听页面显示
  119. */
  120. onShow: function () {
  121. const show = wx.getStorageSync('isfirstLogin')
  122. this.setData({ isfirstLogin: show })
  123. this.getBookHeader(res => {
  124. this.getData(res => {
  125. this.setData({ isLoaded: 1 })
  126. })
  127. })
  128. },
  129. /**
  130. * 生命周期函数--监听页面隐藏
  131. */
  132. onHide: function () {
  133. },
  134. /**
  135. * 生命周期函数--监听页面卸载
  136. */
  137. onUnload: function () {
  138. },
  139. /**
  140. * 页面相关事件处理函数--监听用户下拉动作
  141. */
  142. onPullDownRefresh: function () {
  143. this.setData({ pageNo: 1 })
  144. this.getData(() => {
  145. wx.stopPullDownRefresh()
  146. })
  147. },
  148. /**
  149. * 页面上拉触底事件的处理函数
  150. */
  151. onReachBottom: function () {
  152. const { isAll, isDown } = this.data
  153. if (isAll) {
  154. this.setData({ isDown: true })
  155. return
  156. } else {
  157. this.setData({ isLoad: true, isDown: false })
  158. this.getData(() => {
  159. this.setData({ isLoad: false })
  160. })
  161. }
  162. },
  163. /**
  164. * 搜索页面
  165. */
  166. inputSearchPage: function () {
  167. navigateTo({
  168. url: 'president/pages/search_books/search_books',
  169. })
  170. },
  171. selectNavCtl: function (e) {
  172. const { index } = e.currentTarget.dataset
  173. const {vipId,libId}=this.data
  174. if (index == 0) {
  175. navigateTo({
  176. url: 'president/pages/book_classification/book_classification',
  177. })
  178. }
  179. if (index == 1) {
  180. navigateTo({
  181. url: 'president/pages/borrow_record/borrow_record',paras: { vipId,libId }
  182. })
  183. }
  184. },
  185. /**
  186. * 用户点击右上角分享
  187. */
  188. onShareAppMessage: function () {
  189. if (isFn(sharePage)) return sharePage()
  190. },
  191. /**
  192. * 提示框隐藏
  193. */
  194. screenShowModel: function () {
  195. this.setData({ screenModel: false })
  196. },
  197. /**
  198. * 筛选
  199. */
  200. getScreen: function () {
  201. this.setData({ screenModel: true })
  202. },
  203. /**
  204. * 热度排序
  205. */
  206. selectHot: function () {
  207. const { itemIndex } = this.data
  208. var idx = itemIndex != 1 ? 1 : 0
  209. this.setData({ itemIndex: idx, pageNo: 1 })
  210. wx.showLoading({
  211. title: '加载中',
  212. })
  213. this.getData(() => {
  214. wx.hideLoading();
  215. })
  216. },
  217. /**
  218. * 关闭提示框
  219. */
  220. MessageconfirmClose: function () {
  221. wx.setStorageSync('isfirstLogin', false)
  222. this.setData({ isfirstLogin: false })
  223. },
  224. /**
  225. * 选择年级
  226. */
  227. selectGrade: function (e) {
  228. const { index } = e.currentTarget.dataset
  229. const { isCheck, gradeList, classList } = this.data
  230. const temp = {}
  231. temp[`gradeList[${index}].isCheck`] = gradeList[index].isCheck != 1 ? 1 : 0
  232. this.setData(temp)
  233. if (gradeList[index].isCheck == 1) {
  234. classList.push({
  235. grade: gradeList[index].grade
  236. })
  237. } else if (gradeList[index].isCheck == 0) {
  238. for (var i in classList) {
  239. if (gradeList[index].grade == classList[i].grade) {
  240. classList.splice(i, 1)
  241. }
  242. }
  243. }
  244. this.setData({ classList })
  245. },
  246. /**
  247. * 选择主题
  248. */
  249. selectTheme: function (e) {
  250. const { index, key, type } = e.currentTarget.dataset
  251. const { isCheck, themeList, bookList = [], childList = [] } = this.data
  252. const temp = {}
  253. if (type == 1) {
  254. temp[`themeList[${index}].isCheck`] = themeList[index].isCheck != 1 ? 1 : 0
  255. this.setData(temp)
  256. if (themeList[index].isCheck == 1) {
  257. bookList.push({
  258. code: themeList[index].code,
  259. name: themeList[index].name,
  260. childList
  261. })
  262. } else if (themeList[index].isCheck == 0) {
  263. for (var i in bookList) {
  264. if (themeList[index].code == bookList[i].code) {
  265. bookList.splice(i, 1)
  266. }
  267. }
  268. }
  269. } else {
  270. temp[`themeList[${index}].childList[${key}].isCheck`] = themeList[index].childList[key].isCheck != 1 ? 1 : 0
  271. this.setData(temp)
  272. for (var i in themeList) {
  273. for (var j in themeList[i].childList) {
  274. if (themeList[i].childList[j].isCheck == 1) {
  275. if (themeList[i].code == themeList[index].code) {
  276. childList.push({
  277. code: themeList[i].childList[j].code
  278. })
  279. }
  280. bookList.push({
  281. code: themeList[i].code,
  282. childList
  283. })
  284. }
  285. }
  286. }
  287. }
  288. this.setData({ bookList })
  289. console.log(bookList)
  290. },
  291. /**
  292. * 重置
  293. */
  294. getReset: function () {
  295. const { themeList, gradeList } = this.data
  296. const temp = {}
  297. for (var i in gradeList) {
  298. temp[`gradeList[${i}].isCheck`] = 0
  299. }
  300. for (var i in themeList) {
  301. temp[`themeList[${i}].isCheck`] = 0
  302. for (var j in themeList[i].childList) {
  303. temp[`themeList[${i}].childList[${j}].isCheck`] = 0
  304. }
  305. }
  306. this.setData(temp)
  307. this.setData({ classList: [], bookList: [], isShai: false })
  308. },
  309. /**
  310. * 提交
  311. */
  312. getSubmit: function () {
  313. const { classList, bookList, isSelect, isShai } = this.data
  314. // if (classList.length == 0) {
  315. // wx.showToast({
  316. // title: `请选择年级`,
  317. // icon: 'none'
  318. // })
  319. // return
  320. // }
  321. if (classList.length > 0 || bookList.length > 0) {
  322. this.setData({ isShai: true })
  323. } else {
  324. this.setData({ isShai: false })
  325. }
  326. this.setData({ pageNo: 1, stat: 1 })
  327. this.getData(res => {
  328. this.setData({ isSelect: !isSelect, screenModel: false })
  329. })
  330. },
  331. /**
  332. * 在馆书籍头部与标签
  333. */
  334. getBookHeader: function (cb) {
  335. const continuousFn = { fn: this.getBookHeader, param: { ...arguments } }
  336. const { libId, HeaderbookList } = this.data
  337. GetBooksTab({ data: { libId }, continuousFn }).then(res => {
  338. const { booksSize, serviceVipSize, borrowingSize, themeList, gradeList } = res.data
  339. var temp = {};
  340. temp[`HeaderbookList[${0}].amount`] = booksSize
  341. temp[`HeaderbookList[${1}].amount`] = borrowingSize
  342. this.setData(temp)
  343. wx.setStorageSync('booksSize', booksSize);
  344. this.setData({ themeList, gradeList })
  345. if (isFn(cb)) cb(res)
  346. }).catch(res => {
  347. if (isFn(cb)) cb()
  348. })
  349. },
  350. /**
  351. * 在馆书籍
  352. */
  353. getData: function (cb) {
  354. const continuousFn = { fn: this.getData, param: { ...arguments } }
  355. const { pageNo, pageSize, itemIndex, classList, bookList, stat, libId, number, list = [] } = this.data
  356. GetBooksInlibrary({ data: { libId, pageNo, pageSize, type: ~~itemIndex + 1, stat, gradeList: classList, themeList: bookList }, continuousFn }).then(res => {
  357. const { list } = res.data
  358. let listTemp = []
  359. if (pageNo == 1) {
  360. listTemp = [].concat(list)
  361. } else {
  362. listTemp = [].concat(this.data.list, list)
  363. }
  364. // console.log(listTemp)
  365. this.setData({ list: listTemp, pageNo: list.length == pageSize ? pageNo + 1 : pageNo, isAll: list.length < pageSize })
  366. cb && cb(res)
  367. }).catch(res => {
  368. cb && cb(res)
  369. })
  370. },
  371. })