// pages/past_record/past_record.js import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber, formatDate } from '../../utils/util.js' import { RenewStudentList, FindSaleServiceList,AddBatchCorrectService} from '../../utils/api.js' const { navigateTo, redirectTo, navigateBack } = routers() const { globalData } = getApp() const { baseImgUrl, thumbnail } = globalData const app=getApp() Page({ /** * 页面的初始数据 */ data: { baseImgUrl, thumbnail, pageNo: 1, pageSize: 3, startTime: formatDate(new Date()), isAll: false, isLoaded:false, hiddenModel:false, dateIndex:0, number:1, conflictModel:false, exchangeNum:0, list: [ ] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { options.libId = wx.getStorageSync('libId')||options.libId; this.setData(options) if(options.selectStudentList){ this.setData({list:JSON.parse(options.selectStudentList),vipIdList:JSON.parse(options.vipIdList)}) }else if(options.classIdList){ this.setData({classIdList:JSON.parse(options.classIdList)}) this.getStudentData() } this.sureSaleServiceList() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { const obj = { navigateTo, redirectTo, navigateBack, viewImage } for (const i in obj) { this[i] = obj[i] } }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { if (app.sharePageDefaultCtl) { return app.sharePageDefaultCtl() } }, /** * 底部导航跳转 */ redirectCtl: app.redirectCtl, /** * 路由跳转 */ navigateCtl: app.navigateCtl, /** * 提示框隐藏 */ allShowModel: function () { this.setData({ hiddenModel: false, conflictModel:false}) }, /** * 提示框弹出 */ childShowModel: function () { this.setData({ hiddenModel: true }) }, /** * 获取学生续费数据 */ getStudentData: function (cb) { const continuousFn = { fn: this.getStudentData, param: { ...arguments } } const { pageNo, pageSize, libId,classIdList}=this.data; var that=this; RenewStudentList({ data: { libId,classIdList}, continuousFn }).then(res => { const {list}=res.data var vipIdList=[] for(var i in list){ vipIdList.push(list[i].vipId) } this.setData({ vipIdList, list, isLoaded: true }) if (isFn(cb)) cb() }).catch(res => { this.setData({ isLoaded: true }) if (isFn(cb)) cb() }) }, /** * 查询可购买服务信息 */ sureSaleServiceList: function (cb) { const continuousFn = { fn: this.sureSaleServiceList, param: { ...arguments } } const { libId, dateIndex, vipId } = this.data; FindSaleServiceList({ data: { libId}, continuousFn }).then(res => { const { list } = res.data const tempList = (res => { for (let i in res) { res[i]['number'] = 1 } return res })(list || []) var temp = {}; temp[`priceType`] = list[dateIndex].priceType; temp[`exchangeNum`] = list[dateIndex].exchangeNum; this.setData(temp); this.setData({ payList:list,isLoaded: true }) if (isFn(cb)) cb() }).catch(res => { this.setData({ isLoaded: true }) if (isFn(cb)) cb() }) }, // 选择卡类型 selectCardType: function (e) { const { payList, priceType } = this.data; const { index, type, price } = e.currentTarget.dataset; this.setData({ priceType: type, dateIndex: index }) var temp = {}; for (var i in payList) { temp[`payList[${i}].status`] = '' } temp[`number`] = payList[index].number; temp[`priceType`] = payList[index].priceType; temp[`exchangeNum`] = payList[index].exchangeNum; temp[`payList[${index}].status`] = 'active'; this.setData(temp); }, // 加月卡数量 plusNum: function () { const { payList, dateIndex,list,exchangeNum} = this.data; if(list.length==0){ wx.showToast({ title: '此班级无学生', icon: 'none', duration:1000 }) return } var temp = {} let numbers = payList[dateIndex].number; if (numbers < 12) { numbers = numbers + 1; } else { numbers = numbers; } this.setData({ number: numbers }) if((list.length*numbers)>exchangeNum){ wx.showToast({ title: '抱歉,你的塾币不足', icon: 'none', duration:1000 }) return } temp[`payList[${dateIndex}].number`] = numbers; this.setData(temp) }, // 减月卡数量 arrowNum: function () { const { payList, dateIndex,list,exchangeNum} = this.data; console.log(exchangeNum) var temp = {} let numbers = payList[dateIndex].number; if (numbers > 1) { numbers = numbers - 1; } else { numbers = 1 } this.setData({ number: numbers }) temp[`payList[${dateIndex}].number`] = numbers; this.setData(temp) }, /** * 添加批改服务 */ sureAddCorrectService: function (cb) { const continuousFn = { fn: this.sureAddCorrectService, param: { ...arguments } } const {vipIdList,libId, number, priceType,list,exchangeNum} = this.data; if(list.length==0){ wx.showToast({ title: '此班级无学生', icon: 'none', duration:1000 }) return } if((list.length*number)>exchangeNum){ wx.showToast({ title: '抱歉,你的塾币不足', icon: 'none', duration:1000 }) return } AddBatchCorrectService({ data: {libId, number, priceType,vipIdList}, continuousFn }).then(res => { wx.showToast({ title: '服务添加成功', icon: 'none', duration:1000 }) setTimeout(function(){ wx.navigateBack({}) },1000) if (isFn(cb)) cb() }).catch(res => { if (isFn(cb)) cb() }) } })