123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- // president//pages/random_books/random_books.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
- import { RandomBook, GetBooksTab } from '../../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData } = getApp()
- const { baseImgUrl, thumbnail } = globalData
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- screenModel: false,
- submitModel:false,
- isCheck:0,
- title:'',
- classList:[],
- bookList:[],
- numList:[
- {
- text:'100',
- isCheck:''
- },
- {
- text: '120',
- isCheck: ''
- },
- {
- text: '150',
- isCheck: ''
- },
- {
- text: '',
- isCheck: ''
- },
- ]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`)
- options.libId = getGlobalVal('list').length > 0 ? getGlobalVal('list')[0].libId : ''
- this.setData(options)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.getBooksTab()
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- /**
- * 提示框隐藏
- */
- screenShowModel: function () {
- this.setData({ screenModel: false,submitModel:false })
- },
- /**
- * 筛选
- */
- getScreen: function () {
- this.setData({ screenModel: true })
- },
- /**
- * 筛选
- */
- getBooksTab: function () {
- const continuousFn = { fn: this.subtractionBook, param: { ...arguments } }
- const { libId } = this.data
- GetBooksTab({ data: { libId }, continuousFn }).then(res => {
- const { gradeList, themeList } = res.data;
- this.setData({ gradeList, themeList })
- })
- },
- /**
- * 随机调书
- */
- submitBook:function(){
- const { bookSize, bookList, classList } = this.data
- if (!bookSize) {
- wx.showToast({
- title: `请填写数量`,
- icon:'none'
- })
- return
- }
- // if (classList.length == 0) {
- // wx.showToast({
- // title: `请选择年级`,
- // icon: 'none'
- // })
- // return
- // }
- // if (bookList.length == 0) {
- // wx.showToast({
- // title: `请选择主题`,
- // icon: 'none'
- // })
- // return
- // }
- this.setData({ submitModel: true })
- },
- /**
- * 选择书本数量
- */
- selectNum:function(e){
- const { index } = e.currentTarget.dataset
- const { numList } = this.data
- const temp = {}
- for (var i in numList) {
- temp[`numList[${i}].isCheck`] = ''
- }
- temp[`numList[${index}].isCheck`] = numList[index].isCheck == "" ? "active" : ''
- this.setData(temp)
- for (var i in numList) {
- if (numList[i].isCheck == 'active') {
- this.setData({ bookSize: numList[i].text })
- }
- }
-
- },
- /**
- * 选择年级
- */
- selectGrade: function (e) {
- const { index } = e.currentTarget.dataset
- const { isCheck, gradeList, classList,title } = this.data
- const temp = {}
- temp[`gradeList[${index}].isCheck`] = gradeList[index].isCheck != 1 ? 1 : 0
- this.setData(temp)
- if (gradeList[index].isCheck == 1) {
- this.setData({ title: gradeList[index].grade + ',' + title + '' })
- 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 = [],title } = 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) {
- this.setData({ title: title + '' + themeList[index].name + ',' })
- 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: [],title:'' })
- },
- /**
- * 提交
- */
- getSubmit: function () {
- const { themeList, gradeList} = this.data
- this.setData({screenModel: false })
- },
- /**
- * 输入搜索值
- */
- inputSearchCtl: function (e) {
- const { value } = e.detail
- if (value<151){
- this.setData({ bookSize: value })
- }else{
- wx.showToast({
- title: `调书数量不能大于150本`,
- icon:'none'
- })
- }
-
- console.log(value)
- },
- /**
- * 筛选
- */
- getRandomBook: function () {
- const continuousFn = { fn: this.subtractionBook, param: { ...arguments } }
- const { libId, bookSize, bookList, classList } = this.data
- console.log(libId, bookSize, bookList, classList)
- RandomBook({ data: { libId, bookSize, gradeList: classList, themeList: bookList }, continuousFn }).then(res => {
- this.setData({ submitModel: false, classList: [], bookList: [] })
- wx.showToast({
- title: `提交成功`
- })
- })
- },
- })
|