good_books_new.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. // president//pages/good_books_new/good_books_new.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { GoodBooksToRead, CallInBooks, DeleteBooks, 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. screenModel:false,
  16. pageSize: 5,
  17. pageNo: 1,
  18. isAll: 0,
  19. isSelect:false,
  20. isLoad:false,
  21. gradeList:[],
  22. themeList:[],
  23. parentCode:[],
  24. classList:[],
  25. bookList:[],
  26. childList:[],
  27. itemIndex: 0,
  28. isCheck:0,
  29. number:0,
  30. stat:2,
  31. isShai:false,
  32. isDown:false,
  33. list: [],
  34. footerData: {
  35. actIndex: 1,
  36. list: [
  37. {
  38. text: '在馆书籍',
  39. icon: '../../../assets/zai_guan_shu_ji_gray.png',
  40. actIcon: '../../../assets/zai_guan_shu_ji_blue.png',
  41. url: 'president/pages/library_books/library_books',
  42. zindex: 3
  43. },
  44. {
  45. text: '好书推荐',
  46. icon: '../../../assets/wish_gray.png',
  47. actIcon: '../../../assets/wish_blue.png',
  48. url: 'president/pages/good_books_new/good_books_new',
  49. zindex: 3
  50. },
  51. {
  52. text: '调书清单',
  53. icon: '../../../assets/diao_shu_qing_dan_gray.png',
  54. actIcon: '../../../assets/diao_shu_qing_dan_blue.png',
  55. url: 'president/pages/book_inventory/book_inventory',
  56. zindex: 3
  57. }
  58. ]
  59. },
  60. nodataArray: {
  61. text: "暂无数据"
  62. }
  63. },
  64. /**
  65. * 生命周期函数--监听页面加载
  66. */
  67. onLoad: function (options) {
  68. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
  69. options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
  70. this.setData(options)
  71. this.getBooksTab()
  72. this.getData(res => {
  73. this.setData({ isLoaded: 1 })
  74. })
  75. },
  76. /**
  77. * 生命周期函数--监听页面初次渲染完成
  78. */
  79. onReady: function () {
  80. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  81. for (const i in obj) {
  82. this[i] = obj[i]
  83. }
  84. },
  85. /**
  86. * 生命周期函数--监听页面显示
  87. */
  88. onShow: function () {
  89. // debugger
  90. const show = wx.getStorageSync('hiddenModel')
  91. this.setData({ hiddenModel: show })
  92. },
  93. /**
  94. * 生命周期函数--监听页面隐藏
  95. */
  96. onHide: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面卸载
  100. */
  101. onUnload: function () {
  102. },
  103. /**
  104. * 页面相关事件处理函数--监听用户下拉动作
  105. */
  106. onPullDownRefresh: function () {
  107. this.setData({ pageNo:1})
  108. this.getData(() => {
  109. wx.stopPullDownRefresh()
  110. })
  111. },
  112. /**
  113. * 页面上拉触底事件的处理函数
  114. */
  115. onReachBottom: function () {
  116. const { isAll, isDown } = this.data
  117. if (isAll) {
  118. this.setData({ isDown: true })
  119. return
  120. } else {
  121. this.setData({ isLoad: true, isDown: false })
  122. this.getData(() => {
  123. this.setData({ isLoad: false })
  124. })
  125. }
  126. },
  127. /**
  128. * 用户点击右上角分享
  129. */
  130. onShareAppMessage: function () {
  131. if (isFn(sharePage)) return sharePage()
  132. },
  133. /**
  134. * 提示框隐藏
  135. */
  136. allShowModel: function () {
  137. wx.setStorageSync('hiddenModel', false)
  138. this.setData({ hiddenModel: false })
  139. },
  140. screenShowModel:function(){
  141. this.setData({ screenModel: false })
  142. },
  143. /**
  144. * 随机调书
  145. */
  146. getRondam:function(){
  147. wx.setStorageSync('hiddenModel', true)
  148. this.setData({ hiddenModel: true })
  149. },
  150. /**
  151. * 筛选
  152. */
  153. getScreen:function(){
  154. this.setData({ screenModel: true })
  155. },
  156. /**
  157. * 热度排序
  158. */
  159. selectHot:function(){
  160. const {itemIndex} = this.data
  161. var idx = itemIndex != 1 ? 1 : 0
  162. this.setData({ itemIndex: idx, pageNo: 1})
  163. wx.showLoading({
  164. title: '加载中',
  165. })
  166. this.getData(() => {
  167. wx.hideLoading();
  168. })
  169. },
  170. /**
  171. * 调入
  172. */
  173. addBook:function(e){
  174. const { isbn13, detailid, infoid, size, number, index } = e.currentTarget.dataset
  175. const continuousFn = { fn: this.addBook, param: { ...arguments } }
  176. const { libId,list} = this.data
  177. var numbers = number;
  178. // console.log(list)
  179. var temp = {};
  180. if (numbers < size){
  181. numbers = numbers + 1;
  182. this.setData({ number: numbers })
  183. temp[`list[${index}].number`] = numbers
  184. this.setData(temp)
  185. CallInBooks({ data: { libId, bookInfoId: infoid,isbn13 }, continuousFn }).then(res => {
  186. wx.showToast({
  187. title: `已加入调入清单`,
  188. icon: 'none'
  189. })
  190. // this.getData()
  191. })
  192. }else{
  193. if (size == 1) {
  194. wx.showToast({
  195. title: `该书籍库存只有一本了,无法再添加了`,
  196. icon: 'none'
  197. })
  198. } else {
  199. wx.showToast({
  200. title: `已达上限`,
  201. icon: 'none'
  202. })
  203. }
  204. return
  205. }
  206. },
  207. /**
  208. * 删除
  209. */
  210. subtractionBook: function (e) {
  211. const { isbn13, detailid, infoid, size,number,index} = e.currentTarget.dataset
  212. const continuousFn = { fn: this.subtractionBook, param: { ...arguments } }
  213. const { list, libId} = this.data
  214. let ids=[];
  215. ids.push(
  216. infoid
  217. )
  218. var numbers = number;
  219. var temp={};
  220. // console.log(number, index)
  221. if (numbers >0) {
  222. numbers = numbers - 1;
  223. this.setData({ number: numbers })
  224. temp[`list[${index}].number`] = numbers
  225. this.setData(temp)
  226. DeleteBooks({ data: { ids, libId}, continuousFn }).then(res => {
  227. wx.showToast({
  228. title: `删除成功`,
  229. icon:'none'
  230. })
  231. // this.getData()
  232. })
  233. } else {
  234. wx.showToast({
  235. title: `已经删除`,
  236. icon: 'none'
  237. })
  238. return
  239. }
  240. },
  241. /**
  242. * 选择年级
  243. */
  244. selectGrade: function (e) {
  245. const { index } = e.currentTarget.dataset
  246. const { isCheck, gradeList, classList } = this.data
  247. const temp = {}
  248. temp[`gradeList[${index}].isCheck`] = gradeList[index].isCheck != 1 ? 1 : 0
  249. this.setData(temp)
  250. if (gradeList[index].isCheck == 1) {
  251. classList.push({
  252. grade: gradeList[index].grade
  253. })
  254. } else if (gradeList[index].isCheck == 0){
  255. for (var i in classList){
  256. if (gradeList[index].grade == classList[i].grade){
  257. classList.splice(i,1)
  258. }
  259. }
  260. }
  261. this.setData({ classList })
  262. },
  263. /**
  264. * 选择主题
  265. */
  266. selectTheme: function (e) {
  267. const { index, key, type } = e.currentTarget.dataset
  268. const { isCheck, themeList, bookList = [], childList = [] } = this.data
  269. const temp = {}
  270. if (type == 1) {
  271. temp[`themeList[${index}].isCheck`] = themeList[index].isCheck != 1 ? 1 : 0
  272. this.setData(temp)
  273. if (themeList[index].isCheck == 1) {
  274. bookList.push({
  275. code: themeList[index].code,
  276. childList
  277. })
  278. } else if (themeList[index].isCheck == 0){
  279. for (var i in bookList) {
  280. if (themeList[index].code == bookList[i].code) {
  281. bookList.splice(i, 1)
  282. }
  283. }
  284. }
  285. } else {
  286. temp[`themeList[${index}].childList[${key}].isCheck`] = themeList[index].childList[key].isCheck != 1 ? 1 : 0
  287. this.setData(temp)
  288. for (var i in themeList) {
  289. for (var j in themeList[i].childList) {
  290. if (themeList[i].childList[j].isCheck == 1) {
  291. if (themeList[i].code == themeList[index].code) {
  292. childList.push({
  293. code: themeList[i].childList[j].code
  294. })
  295. }
  296. bookList.push({
  297. code: themeList[i].code,
  298. childList
  299. })
  300. }
  301. }
  302. }
  303. }
  304. this.setData({ bookList })
  305. // console.log(bookList)
  306. },
  307. /**
  308. * 重置
  309. */
  310. getReset:function(){
  311. const { themeList, gradeList } = this.data
  312. const temp = {}
  313. for (var i in gradeList) {
  314. temp[`gradeList[${i}].isCheck`] = 0
  315. }
  316. for (var i in themeList) {
  317. temp[`themeList[${i}].isCheck`] = 0
  318. for (var j in themeList[i].childList){
  319. temp[`themeList[${i}].childList[${j}].isCheck`] =0
  320. }
  321. }
  322. this.setData(temp)
  323. this.setData({ classList: [], bookList: [], isShai: false})
  324. },
  325. /**
  326. * 提交
  327. */
  328. getSubmit:function(){
  329. const { classList, bookList, isSelect, isShai } = this.data
  330. // console.log(isShai)
  331. if (classList.length > 0 || bookList.length > 0) {
  332. this.setData({ isShai: true })
  333. } else {
  334. this.setData({ isShai: false })
  335. }
  336. // if (bookList.length == 0) {
  337. // wx.showToast({
  338. // title: `请选择主题`,
  339. // icon: 'none'
  340. // })
  341. // return
  342. // }
  343. this.setData({ pageNo: 1, stat: 1})
  344. this.getData(res => {
  345. this.setData({ isSelect: true, screenModel: false})
  346. })
  347. },
  348. /**
  349. * 返回好书推荐
  350. */
  351. backBook:function(){
  352. this.setData({ isLoaded: 0, pageNo:1,isSelect: false, classList: [], bookList: [], stat:2 })
  353. this.getReset()
  354. this.getData(res => {
  355. this.setData({ isLoaded: 1})
  356. })
  357. },
  358. /**
  359. * 好书推荐
  360. */
  361. getData: function (cb) {
  362. const continuousFn = { fn: this.getData, param: { ...arguments } }
  363. const { pageNo, pageSize, itemIndex, classList, bookList, stat} = this.data
  364. GoodBooksToRead({ data: { pageNo, pageSize, type: ~~itemIndex + 1, stat, gradeList: classList, themeList: bookList}, continuousFn }).then(res => {
  365. const { list } = res.data
  366. const correctListTemp = (res => {
  367. // console.log(res)
  368. var d = []
  369. for (let i in res) {
  370. res[i].number = 0
  371. }
  372. return res
  373. })(list)
  374. let listTemp = []
  375. if (pageNo == 1) {
  376. listTemp = [].concat(correctListTemp)
  377. } else {
  378. listTemp = [].concat(this.data.list, correctListTemp)
  379. }
  380. // console.log(listTemp)
  381. this.setData({ list: listTemp, pageNo: list.length == pageSize ? pageNo + 1 : pageNo, isAll: list.length < pageSize })
  382. cb && cb(res)
  383. }).catch(res => {
  384. cb && cb(res)
  385. })
  386. },
  387. /**
  388. * 筛选
  389. */
  390. getBooksTab:function(){
  391. const continuousFn = { fn: this.getBooksTab, param: { ...arguments } }
  392. const { libId } = this.data
  393. GetBooksTab({ data: { libId}, continuousFn }).then(res => {
  394. const { gradeList, themeList}=res.data;
  395. this.setData({ gradeList, themeList})
  396. })
  397. },
  398. /**
  399. * 进入主题
  400. */
  401. enterTheme:function(e){
  402. const { child,theme } = e.currentTarget.dataset
  403. const { classList} = this.data
  404. navigateTo({
  405. url: 'president/pages/part_call_in/part_call_in?gradeList=' + JSON.stringify(classList) + '&childTheme=' + child + '&theme=' + theme
  406. })
  407. }
  408. })