123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- // 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()
- })
- }
-
- })
|