123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- // president//pages/good_books_new/good_books_new.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
- import { GoodBooksToRead, CallInBooks, DeleteBooks, GetBooksTab} from '../../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData } = getApp()
- const { baseImgUrl, thumbnail } = globalData
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- baseImgUrl,
- thumbnail,
- isLoaded: 0,
- screenModel:false,
- pageSize: 5,
- pageNo: 1,
- isAll: 0,
- isSelect:false,
- isLoad:false,
- gradeList:[],
- themeList:[],
- parentCode:[],
- classList:[],
- bookList:[],
- childList:[],
- itemIndex: 0,
- isCheck:0,
- number:0,
- stat:2,
- isShai:false,
- isDown:false,
- list: [],
- footerData: {
- actIndex: 1,
- list: [
- {
- text: '在馆书籍',
- icon: '../../../assets/zai_guan_shu_ji_gray.png',
- actIcon: '../../../assets/zai_guan_shu_ji_blue.png',
- url: 'president/pages/library_books/library_books',
- zindex: 3
- },
- {
- text: '好书推荐',
- icon: '../../../assets/wish_gray.png',
- actIcon: '../../../assets/wish_blue.png',
- url: 'president/pages/good_books_new/good_books_new',
- zindex: 3
- },
- {
- text: '调书清单',
- icon: '../../../assets/diao_shu_qing_dan_gray.png',
- actIcon: '../../../assets/diao_shu_qing_dan_blue.png',
- url: 'president/pages/book_inventory/book_inventory',
- zindex: 3
- }
- ]
- },
- nodataArray: {
- text: "暂无数据"
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
- options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
- this.setData(options)
- this.getBooksTab()
- this.getData(res => {
- this.setData({ isLoaded: 1 })
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- const obj = { navigateTo, redirectTo, navigateBack, viewImage }
- for (const i in obj) {
- this[i] = obj[i]
- }
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- // debugger
- const show = wx.getStorageSync('hiddenModel')
- this.setData({ hiddenModel: show })
-
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- this.setData({ pageNo:1})
- this.getData(() => {
- wx.stopPullDownRefresh()
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- const { isAll, isDown } = this.data
- if (isAll) {
- this.setData({ isDown: true })
- return
- } else {
- this.setData({ isLoad: true, isDown: false })
- this.getData(() => {
- this.setData({ isLoad: false })
- })
- }
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- if (isFn(sharePage)) return sharePage()
- },
- /**
- * 提示框隐藏
- */
- allShowModel: function () {
- wx.setStorageSync('hiddenModel', false)
- this.setData({ hiddenModel: false })
- },
- screenShowModel:function(){
- this.setData({ screenModel: false })
- },
- /**
- * 随机调书
- */
- getRondam:function(){
- wx.setStorageSync('hiddenModel', true)
- this.setData({ hiddenModel: true })
- },
- /**
- * 筛选
- */
- getScreen:function(){
- this.setData({ screenModel: true })
- },
- /**
- * 热度排序
- */
- selectHot:function(){
- const {itemIndex} = this.data
- var idx = itemIndex != 1 ? 1 : 0
- this.setData({ itemIndex: idx, pageNo: 1})
- wx.showLoading({
- title: '加载中',
- })
- this.getData(() => {
- wx.hideLoading();
- })
- },
- /**
- * 调入
- */
- addBook:function(e){
- const { isbn13, detailid, infoid, size, number, index } = e.currentTarget.dataset
- const continuousFn = { fn: this.addBook, param: { ...arguments } }
- const { libId,list} = this.data
- var numbers = number;
- // console.log(list)
- var temp = {};
- if (numbers < size){
- numbers = numbers + 1;
- this.setData({ number: numbers })
- temp[`list[${index}].number`] = numbers
- this.setData(temp)
- CallInBooks({ data: { libId, bookInfoId: infoid,isbn13 }, continuousFn }).then(res => {
- wx.showToast({
- title: `已加入调入清单`,
- icon: 'none'
- })
- // this.getData()
- })
- }else{
- if (size == 1) {
- wx.showToast({
- title: `该书籍库存只有一本了,无法再添加了`,
- icon: 'none'
- })
- } else {
- wx.showToast({
- title: `已达上限`,
- icon: 'none'
- })
- }
- return
- }
- },
- /**
- * 删除
- */
- subtractionBook: function (e) {
- const { isbn13, detailid, infoid, size,number,index} = e.currentTarget.dataset
- const continuousFn = { fn: this.subtractionBook, param: { ...arguments } }
- const { list, libId} = this.data
- let ids=[];
- ids.push(
- infoid
- )
- var numbers = number;
- var temp={};
- // console.log(number, index)
- if (numbers >0) {
- numbers = numbers - 1;
- this.setData({ number: numbers })
- temp[`list[${index}].number`] = numbers
- this.setData(temp)
- DeleteBooks({ data: { ids, libId}, continuousFn }).then(res => {
- wx.showToast({
- title: `删除成功`,
- icon:'none'
- })
- // this.getData()
- })
- } else {
- wx.showToast({
- title: `已经删除`,
- icon: 'none'
- })
- return
- }
- },
- /**
- * 选择年级
- */
- selectGrade: function (e) {
- const { index } = e.currentTarget.dataset
- const { isCheck, gradeList, classList } = this.data
- const temp = {}
- temp[`gradeList[${index}].isCheck`] = gradeList[index].isCheck != 1 ? 1 : 0
- this.setData(temp)
- if (gradeList[index].isCheck == 1) {
- classList.push({
- grade: gradeList[index].grade
- })
- } else if (gradeList[index].isCheck == 0){
- for (var i in classList){
- if (gradeList[index].grade == classList[i].grade){
- classList.splice(i,1)
- }
- }
- }
- this.setData({ classList })
- },
- /**
- * 选择主题
- */
- selectTheme: function (e) {
- const { index, key, type } = e.currentTarget.dataset
- const { isCheck, themeList, bookList = [], childList = [] } = this.data
- const temp = {}
- if (type == 1) {
- temp[`themeList[${index}].isCheck`] = themeList[index].isCheck != 1 ? 1 : 0
- this.setData(temp)
- if (themeList[index].isCheck == 1) {
- bookList.push({
- code: themeList[index].code,
- childList
- })
- } else if (themeList[index].isCheck == 0){
- for (var i in bookList) {
- if (themeList[index].code == bookList[i].code) {
- bookList.splice(i, 1)
- }
- }
- }
-
- } else {
- temp[`themeList[${index}].childList[${key}].isCheck`] = themeList[index].childList[key].isCheck != 1 ? 1 : 0
- this.setData(temp)
- for (var i in themeList) {
- for (var j in themeList[i].childList) {
- if (themeList[i].childList[j].isCheck == 1) {
- if (themeList[i].code == themeList[index].code) {
- childList.push({
- code: themeList[i].childList[j].code
- })
- }
- bookList.push({
- code: themeList[i].code,
- childList
- })
- }
- }
- }
- }
- this.setData({ bookList })
- // console.log(bookList)
- },
- /**
- * 重置
- */
- getReset:function(){
- const { themeList, gradeList } = this.data
- const temp = {}
- for (var i in gradeList) {
- temp[`gradeList[${i}].isCheck`] = 0
- }
- for (var i in themeList) {
- temp[`themeList[${i}].isCheck`] = 0
- for (var j in themeList[i].childList){
- temp[`themeList[${i}].childList[${j}].isCheck`] =0
- }
- }
- this.setData(temp)
- this.setData({ classList: [], bookList: [], isShai: false})
- },
- /**
- * 提交
- */
- getSubmit:function(){
- const { classList, bookList, isSelect, isShai } = this.data
- // console.log(isShai)
- if (classList.length > 0 || bookList.length > 0) {
- this.setData({ isShai: true })
- } else {
- this.setData({ isShai: false })
- }
- // if (bookList.length == 0) {
- // wx.showToast({
- // title: `请选择主题`,
- // icon: 'none'
- // })
- // return
- // }
- this.setData({ pageNo: 1, stat: 1})
- this.getData(res => {
- this.setData({ isSelect: true, screenModel: false})
- })
-
- },
- /**
- * 返回好书推荐
- */
- backBook:function(){
- this.setData({ isLoaded: 0, pageNo:1,isSelect: false, classList: [], bookList: [], stat:2 })
- this.getReset()
- this.getData(res => {
- this.setData({ isLoaded: 1})
- })
- },
- /**
- * 好书推荐
- */
- getData: function (cb) {
- const continuousFn = { fn: this.getData, param: { ...arguments } }
- const { pageNo, pageSize, itemIndex, classList, bookList, stat} = this.data
- GoodBooksToRead({ data: { pageNo, pageSize, type: ~~itemIndex + 1, stat, gradeList: classList, themeList: bookList}, continuousFn }).then(res => {
- const { list } = res.data
- const correctListTemp = (res => {
- // console.log(res)
- var d = []
- for (let i in res) {
- res[i].number = 0
- }
- return res
- })(list)
- let listTemp = []
- if (pageNo == 1) {
- listTemp = [].concat(correctListTemp)
- } else {
- listTemp = [].concat(this.data.list, correctListTemp)
- }
- // console.log(listTemp)
- this.setData({ list: listTemp, pageNo: list.length == pageSize ? pageNo + 1 : pageNo, isAll: list.length < pageSize })
- cb && cb(res)
- }).catch(res => {
- cb && cb(res)
- })
- },
- /**
- * 筛选
- */
- getBooksTab:function(){
- const continuousFn = { fn: this.getBooksTab, param: { ...arguments } }
- const { libId } = this.data
- GetBooksTab({ data: { libId}, continuousFn }).then(res => {
- const { gradeList, themeList}=res.data;
- this.setData({ gradeList, themeList})
- })
- },
- /**
- * 进入主题
- */
- enterTheme:function(e){
- const { child,theme } = e.currentTarget.dataset
- const { classList} = this.data
- navigateTo({
- url: 'president/pages/part_call_in/part_call_in?gradeList=' + JSON.stringify(classList) + '&childTheme=' + child + '&theme=' + theme
- })
-
- }
- })
|