// pages/Components/classList/classList.js const app = getApp() const util = require("../../../utils/util") const urlDef = require("../../../utils/urls") Component({ lifetimes: { attached: function () { wx.getSystemInfo({ success: (result) => { this.setData({ height: result.windowHeight }) }, }) } }, pageLifetimes: { show: function () { let action = this.properties.action this.setData({ action: action }) if ('1' == this.data.action) { this.setData({ actionName: '补' }) } else if ('2' == this.data.action) { this.setData({ actionName: '加' }) } else { this.setData({ actionName: '调' }) } } }, /** * 组件的属性列表 */ properties: { showLeaveNum: { //是否显示请假余额 type: Boolean, value: false }, showTime: { //是否显示上课时间 type: Boolean, value: true }, showFlag: { //是否显示上课状态 type: Boolean, value: true }, showBtn: { //是否显示功能按钮 type: Boolean, value: false, }, showRadio: { //是否显示单选按钮 type: Boolean, value: false, }, showLevel: { type: Boolean, value: false, }, date: { type: String }, list: { type: Array, value: [] }, action: { type: String }, source: { type: Object } }, /** * 组件的初始数据 */ data: { animation: null, height: 0, overflow: 'auto', source: null, target: null, key: null, action: null, actionName: null }, /** * 组件的方法列表 */ methods: { toPages: function (e) { let urls = urlDef.urls let stu = wx.getStorageSync('student') let item = e.currentTarget.dataset.item; this.properties.list.map(h => { if (item == null) { if (h.items && h.items.length > 0) { item = h.items.filter(o => o.id == e.currentTarget.dataset.id)[0] } } }) let action = e.currentTarget.dataset.action if (action == '1' || action == '3' || action == '4') { item.curDate = item.beginTime.substring(0, 10) wx.navigateTo({ url: e.currentTarget.dataset.url + '?data=' + JSON.stringify({ source: item, action: (action ? action : 0), dayScope: 14 }), }) } else if (action == '2') { util.apiPost(urls.get_last_classes + '&q.studentId=' + stu.studentId + '&q.classesId=' + item.classesId).then(rs => { if (rs == null) { wx.showToast({ title: '未查询到排课数据', icon: 'none' }) return; } rs.curDate = rs.beginTime.substring(0, 10) rs.classromeId = null; // 加课不用传 教室id wx.navigateTo({ url: e.currentTarget.dataset.url + '?data=' + JSON.stringify({ source: rs, action: (action ? action : 0), dayScope: 14 }), }) }) } }, showChoose: function () { // 判断是否选择了 let key = this.data.key if (key == null || key == undefined) { wx.showToast({ title: '请选择目标课程', icon: 'none' }) return; } let ks = key.split('#') let action = this.data.action this.properties.list.map(o => { if (o.date == ks[0]) { o.items.map(i => { if (i.attendTeacherId == ks[1] && i.bt == ks[2]) { let source = this.properties.source if (source.curDate) { source.date = source.curDate.substring(0, 10) source.week = this.getWeek(source.date) } if (source.beginTime) { source.bt = source.beginTime.substring(11, 16) } if (source.endTime) { source.et = source.endTime.substring(11, 16) } if (i.newDate) { i.date = i.newDate.substring(0, 10) i.week = this.getWeek(i.date) } this.setData({ target: i, source: source, action: action }) } }) } }) this.animation = wx.createAnimation({ timingFunction: 'linear', }) const bottom = 0 this.animation.translateY(bottom).step() this.setData({ overflow: 'hidden', animation: this.animation.export(), bottom }) }, hideChoose: function () { this.animation = wx.createAnimation({ timingFunction: 'linear', }) const bottom = 2000 this.animation.translateY(bottom).step() this.setData({ overflow: 'auto', animation: this.animation.export(), }) setTimeout(() => { this.setData({ bottom }) }, 400); }, getLeaveNumList: function () { wx.navigateTo({ url: '/pages/leaveRecord/leaveRecord', }) }, radioChange: function (e) { this.setData({ key: e.detail.value }) }, getWeek: function (d) { return '星期' + '天一二三四五六'.charAt(new Date(d).getDay()); }, doSave: function () { let that = this wx.showModal({ title: '确认信息', content: '确定要执行' + this.data.actionName + '课申请?', showCancel: true, cancelText: "否", confirmText: "是", success: function (res) { if (res.cancel) { that.hideChoose() } else { that.doRealSave() } } }) }, doRealSave: function () { wx.showLoading({ title: '正在保存数据...', mask: true }) const urls = urlDef.urls; let stu = wx.getStorageSync('student') let data = {} data.orgId = stu.orgId; data.operator = stu.studentId data.studentId = stu.studentId; data.studentName = stu.name if ('1' === this.data.action) { data.leaveId = this.data.source.leaveId; data.attenceStudentId = this.data.source.attenceStudentId; } else { data.attenceStudentId = this.data.source.studentId; } data.oldAttenceTeacherId = this.data.source.attenceTeacherId; data.oldKindId = this.data.source.kindId; data.attendTeacherId = this.data.target.attendTeacherId; data.beginTime = this.data.target.newDate.substring(0, 10) + ' ' + this.data.target.beginTime + ':00'; data.endTime = this.data.target.newDate.substring(0, 10) + ' ' + this.data.target.endTime + ':00'; data.classesId = this.data.target.classesId; data.courseName = this.data.target.courseName; data.classesName = this.data.target.classesName; data.name = this.data.target.classesName; data.kindId = this.data.target.kindId; data.teacherId = this.data.target.teacherId; data.classRoomId = this.data.target.classroomId; let saveURL = urls.classes_switch_save; if ('1' === this.data.action) { saveURL = urls.student_makeup; } if ('2' === this.data.action) { data.classesId = this.data.source.classesId; // 原课程的classesId, 不然找不到当前学生的最后一节课 let gridList = []; gridList.push( { personNum: this.data.target.personNum, attendTeacherId: this.data.target.attendTeacherId, teacherName: this.data.target.teacherName, endDate: this.data.target.endDate, classroomId: this.data.target.classroomId, beginDate: this.data.target.beginDate, classesId: this.data.target.classesId, courseName: this.data.target.courseName, teacherId: this.data.target.teacherId, classesName: this.data.target.classesName, beginTime: this.data.target.newDate.substring(0, 10) + ' ' + this.data.target.beginTime + ':00', courseId: this.data.target.courseId, kindId: this.data.target.kindId, classRoomId: this.data.target.classroomId, endTime: this.data.target.newDate.substring(0, 10) + ' ' + this.data.target.endTime + ':00' } ); data.gridList = gridList; saveURL = urls.add_classes; } util.apiPost(saveURL, data, 'application/json').then((rs) => { wx.hideLoading({}) this.hideChoose() if (rs.message) { wx.showToast({ title: this.data.actionName + '课失败,' + rs.message, icon: 'none' }) return; } wx.showToast({ title: '您已' + this.data.actionName + '课成功!' }) setTimeout(() => { wx.navigateBack({ delta: 1, // 返回上一级页面。 success: function () { console.log('成功!') } }) }, 1000) }) } } })