const app = require('../../utils/util.js'); const tools = require('../../utils/tools.js'); Page({ data: { isRz: false, showMore: false, //更多 showzs: false, //证书显示 show: false, //协议显示 notice: "暂无未读通知", classInfo: {}, //班级信息 kcArr: [], //课程列表 sfmArr: [], //换算时分秒数组 studentName: "", //学生名字 status: '', //状态 myCanvasId: 0, //画布id byzsbj: "../../images/zsbj.jpg", //结业证背景 用于合成图片 IngCourseArr: [], //如果有正在进行的课就存一下 istask: false, //判断班级群是否添加 istask1: false, //学员登记表是否完成 istask2: false, //课程是否完成 istask3: false, //期末考试是否完成 istask4: false, //综合反馈是否完成 currentId: null, currentName: "" }, // 查询我是否认证 isRz(sessionKey) { wx.request({ url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey', method: "post", data: { sessionKey }, success: (res) => { if (res.data.code == 0 && (res.data.data !== null || res.data.data !== "")) { this.setData({ isRz: false }) this.isClass(sessionKey) } else { this.setData({ isRz: true }) } } }) }, escRz() { wx.switchTab({ url: '/pages/index/index', }) }, goRz() { wx.navigateTo({ url: '/pages/Identity/Identity', }) }, // 查询我是否有班&&班级名字 isClass(sessionKey) { wx.request({ url: app.globalData.publicUrl + '/wx/student/selMyClas', method: "post", data: { sessionKey }, success: (res) => { if (res.data.code == 0) { this.setData({ classInfo: res.data.data }) this.isAgree(sessionKey); this.getMynotice(sessionKey); this.getMycourse(sessionKey); this.checkTaskList(sessionKey); this.checkTaskList3(sessionKey, res.data.data.id); this.checkTaskList4(sessionKey, res.data.data.id); } else { if (res.data.msg == "运行时异常:学员不可同时存在两个班级中。") { wx.showModal({ content: "学员不可同时存在多个班级中哦", showCancel: false, success(res) { if (res.confirm) { wx.switchTab({ url: '../index/index' }) } } }) return false; } else { wx.showModal({ content: "您当前还没有正在开放的班级!", showCancel: false, success(res) { if (res.confirm) { wx.switchTab({ url: '../index/index' }) } } }) return false; } } } }) }, // 协议是否已同意 isAgree(sessionKey) { wx.request({ url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey', method: "post", data: { sessionKey }, success: (res) => { if (res.data.code == 0 && res.data.data) { if (res.data.data.agreement == 0) { this.setData({ studentName: res.data.data.studentName, show: false }); } else { this.setData({ studentName: res.data.data.studentName, show: true }); } } } }) }, // 点击同意协议 并且记一下 hidePopup() { wx.request({ url: app.globalData.publicUrl + '/wx/student/verification', method: "post", data: { sessionKey: this.data.sessionKey }, success: (res) => { this.setData({ show: false }); } }) }, moreThink() { wx.switchTab({ url: '../index/index' }) }, // 检查班级群是否加了 && 学员登记任务check checkTaskList(sessionKey) { wx.request({ url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey', method: "post", data: { sessionKey }, success: (res) => { if (res.data.code == 0) { console.log(res) this.setData({ studentName: res.data.data.studentName, }) if (res.data.data.joinClas == 0) { this.setData({ istask: true }) } if (res.data.data.register == 0) { this.setData({ istask1: true }) } } } }) }, // 期末考试任务检查 checkTaskList3(sessionKey, id) { wx.request({ url: app.globalData.publicUrl + '/wx/exam/clasExamstatus', method: "post", data: { sessionKey: sessionKey, clasId: id }, success: (res) => { if (res.data.code == 0 && res.data.status == 1) { this.setData({ istask3: true }) } } }) }, // 综合反馈任务check checkTaskList4(sessionKey, id) { wx.request({ url: app.globalData.publicUrl + '/wx/exam/status', method: "post", data: { sessionKey: sessionKey, clasId: id }, success: (res) => { if (res.data.code == 0 && res.data.status == 1) { this.setData({ istask4: true }) } } }) }, // 页面上显示的我的未读通知 getMynotice(sessionKey) { wx.request({ url: app.globalData.publicUrl + '/wx/eduNoticeSee/list', method: "post", data: { sessionKey: sessionKey, isSee: 1 // isNotice: 0 }, success: (res) => { if (res.data.code == 0) { if (res.data.list && res.data.list.length !== 0) this.setData({ notice: res.data.list[0].noticeContent }); } } }) }, // 跳转通知页 gomyNotice() { wx.navigateTo({ url: '../myNotice/myNotice' }) }, // 学员登记表 goWrite() { if (this.data.classInfo.id == -1) { wx.navigateTo({ url: '../studentRegistration/studentRegistration' }) } else { if (!this.data.istask) { wx.showModal({ showCancel: false, content: "请先去扫描二维码加入班级群吧", success(res) { if (res.confirm) { wx.switchTab({ url: '../myMission/myMission' }) } } }) return false } wx.navigateTo({ url: '../studentRegistration/studentRegistration' }) } }, // 学院介绍 toAdd1() { wx.navigateTo({ url: '../schoolIntrouce/schoolIntrouce' }) }, // 学员名单 toAdd2() { wx.navigateTo({ url: '../studentList/studentList?id=' + this.data.classInfo.id }) }, // 项目组名单 toAdd3() { wx.navigateTo({ url: '../groupsList/groupsList' }) }, // 我的课程 getMycourse(sessionKey) { wx.request({ url: app.globalData.publicUrl + '/wx/course/selectBySessionKey', method: "post", data: { sessionKey: sessionKey }, success: (res) => { console.log(res, "我的课程") this.setData({ kcArr: res.data.list, istask2: res.data.allDone, currentName: "", currentId: null }); for (let i = 0; i < res.data.list.length; i++) { if (res.data.list[i].isLive == -1) { // 这个节课未全部完成 if (res.data.list[i].isDone == "0") { // 这个视频已经进行了 看一半或者看完了 if (res.data.list[i].isStudyDone == 0 || res.data.list[i].isStudyDone == 1) { this.setData({ currentName: res.data.list[i].courseName, currentId: res.data.list[i].id }) } } } } let result = []; if (res.data.list) for (let i = 0; i < res.data.list.length; i++) { result.push({ courseTime: res.data.list[i].courseTime }); } const timesArr = result.map((item) => { return item.courseTime; }); let sfmArr = []; for (let i = 0; i < timesArr.length; i++) { let value = timesArr[i]; const resultValue = this.handler(value); sfmArr.push({ courseTime: resultValue }) this.setData({ sfmArr: sfmArr }) } } }) }, // 时间换算 handler(value) { //换算为秒 进制1000 const second = Math.floor(value / 1000); //判断是否够1秒 if (second < 1) { return "0秒"; } const secondValue = second % 60; // 秒 const minutes = Math.floor(second / 60); //判断是否够1分钟 if (minutes < 1) { return `${secondValue}秒`; } const minutesValue = minutes % 60; //分 const hours = Math.floor(minutes / 60); //判断是否够1小时 if (hours < 1) { return `${minutesValue}分${secondValue}秒`; } const hoursValue = hours % 60; //小时 return `${hoursValue}时${minutesValue}分${secondValue}秒`; }, // 查看更多列表展开 listToggle: function () { this.setData({ showMore: !this.data.showMore }) }, // 去学习 goStudy(e) { let id = e.currentTarget.dataset.item.id //此课程的id let courseUrl = e.currentTarget.dataset.item.courseUrl //此课程的id let courseName = e.currentTarget.dataset.item.courseName //此课程的id let courseInfo = e.currentTarget.dataset.item.courseInfo //此课程的id if (this.data.classInfo.id == -1) { if (e.currentTarget.dataset.item.isLive == 1) { if (e.currentTarget.dataset.item.isActive == 1) { wx.navigateTo({ url: '../zbDetails/zbDetails?id=' + id }) } else if (e.currentTarget.dataset.item.isActive == -1) { if (courseUrl == null || courseUrl == "") { wx.showModal({ showCancel: false, content: "直播回放还未上传噢" }) } else { wx.navigateTo({ url: '../livePlayback/livePlayback?courseName=' + courseName + '&courseUrl=' + courseUrl + '&courseInfo=' + courseInfo }) } } else { wx.showModal({ showCancel: false, content: "直播还未开始哦" }) return false; } } else { wx.navigateTo({ url: '../dbDetails/dbDetails?id=' + id }) } } else { console.log(this.data.istask) if (!this.data.istask) { wx.showModal({ showCancel: false, content: "请先去扫描二维码加入班级群吧", success(res) { if (res.confirm) { wx.switchTab({ url: '../myMission/myMission' }) } } }) return false } if (!this.data.istask1) { wx.showModal({ showCancel: false, content: "请先填写学员登记表再来学习哦!" }) return false } // 直播 if (e.currentTarget.dataset.item.isLive == 1) { if (e.currentTarget.dataset.item.isActive == 1) { wx.navigateTo({ url: '../zbDetails/zbDetails?id=' + id }) } else if (e.currentTarget.dataset.item.isActive == -1) { if (courseUrl == null || courseUrl == "") { wx.showModal({ showCancel: false, content: "直播回放还未上传噢" }) } else { wx.navigateTo({ url: '../livePlayback/livePlayback?courseName=' + courseName + '&courseUrl=' + courseUrl + '&courseInfo=' + courseInfo }) } } else { wx.showModal({ showCancel: false, content: "直播还未开始哦" }) return false; } } else { if (this.data.currentId != null) { // 没学或者没学完 if (e.currentTarget.dataset.item.isDone == 0) { if (id == this.data.currentId) { wx.navigateTo({ url: '../dbDetails/dbDetails?id=' + id }) } else { // 有未完成的但不是我 就不能跳转 wx.showModal({ showCancel: false, content: "您的" + this.data.currentName + "课还未学完,快去学习吧" }) } } else { // 我看完了这个视频 还能看 wx.navigateTo({ url: '../dbDetails/dbDetails?id=' + id }) } } else { wx.navigateTo({ url: '../dbDetails/dbDetails?id=' + id }) } } } }, // 去考试 gokhAnswer(e) { wx.showLoading({ mask: true, title: '加载中', }) if (this.data.classInfo.id == -1) { this.examination(e.currentTarget.dataset.item.id); wx.hideLoading(); } else { wx.hideLoading(); if (!this.data.istask) { wx.showModal({ showCancel: false, content: "请先去扫描二维码加入班级群吧", success(res) { if (res.confirm) { wx.switchTab({ url: '../myMission/myMission' }) } } }) return false } if (!this.data.istask1) { wx.showModal({ showCancel: false, content: "请先填写学员登记表再来学习哦!" }) return false } let isStudyDone = e.currentTarget.dataset.item.isStudyDone if (isStudyDone != 1) { wx.showModal({ showCancel: false, content: "您当前的学习课程还未完成哦,请先完成再来考试吧!" }) return false } else { this.examination(e.currentTarget.dataset.item.id); } } }, // 考试方法单拿出来 examination(id) { wx.request({ url: app.globalData.publicUrl + '/wx/exam/examList', method: "post", data: { sessionKey: this.data.sessionKey, courseId: id, clasId: this.data.classInfo.id }, success: (res) => { if (res.data.code == 0) { if (res.data.list.length == 0) { wx.showModal({ showCancel: false, content: '老师还未出考试题哦' }) } else { console.log(res, '1111') if (res.data.list[0]) { if (res.data.list[0].answersId) { this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'answerAfterclass'); } else { this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'answerAfterclass'); } } } } } }) }, //去评价 gopjClass(e) { if (this.data.classInfo.id == -1) { this.evaluate(e.currentTarget.dataset.item.id) } else { if (!this.data.istask) { wx.showModal({ showCancel: false, content: "请先去扫描二维码加入班级群吧", success(res) { if (res.confirm) { wx.switchTab({ url: '../myMission/myMission' }) } } }) return false } if (!this.data.istask1) { wx.showModal({ showCancel: false, content: "请先填写学员登记表再来学习哦!" }) return false } let isStudyDone = e.currentTarget.dataset.item.isStudyDone if (isStudyDone != 1) { wx.showModal({ showCancel: false, content: "您的学习课程还未完成哦,请先完成再来评价吧!" }) return false } else { this.evaluate(e.currentTarget.dataset.item.id) } } }, // 评价方法单拿出来 evaluate(id) { wx.request({ url: app.globalData.publicUrl + '/wx/exam/quesExamList', method: "post", data: { sessionKey: this.data.sessionKey, courseId: id, clasId: this.data.classInfo.id }, success: (res) => { if (res.data.code == 0) { if (res.data.list.length == 0) { wx.showModal({ showCancel: false, content: '老师还未出评价模板哦' }) } else { if (res.data.list[0]) { if (res.data.list[0].answersId) { this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'evaluationCourse'); } else { this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'evaluationCourse'); } } } } } }) }, // 查看详情成绩 gockcj(e) { console.log(e.currentTarget.dataset.item.isExamId) if (e.currentTarget.dataset.item.isExamId) { wx.request({ url: app.globalData.publicUrl + '/wx/answer/detail', method: "post", data: { answersId: e.currentTarget.dataset.item.isExamId }, success: (res) => { if (res.data.list[0] && res.data.list[0].answerScore >= 0 && res.data.list[0].answerScore != null) { wx.navigateTo({ url: '/pages/grade/grade?answersId=' + e.currentTarget.dataset.item.isExamId, }) } else { wx.showModal({ showCancel: false, content: '当前老师批阅中,请耐心等待' }) } }, fail: () => { wx.showModal({ showCancel: false, content: '当前老师批阅中,请耐心等待' }) } }) } }, // 查看详情评价 gockpj(e) { wx.navigateTo({ url: '/pages/evaluationCourseDetail/evaluationCourseDetail?answersId=' + e.currentTarget.dataset.item.isFeedbackId, }) }, // 期末考试 goQmks() { if (this.data.classInfo.id == -1) { wx.request({ url: app.globalData.publicUrl + '/wx/exam/examList', method: "post", data: { sessionKey: this.data.sessionKey, clasId: this.data.classInfo.id }, success: (res) => { if (res.data.code == 0) { if (res.data.list.length == 0) { wx.showModal({ showCancel: false, content: '期末考试还未开始哦!' }) } else { if (res.data.list[0].answersId) { if (res.data.list[0].status == '1') { wx.request({ url: app.globalData.publicUrl + '/wx/answer/detail', method: "post", data: { answersId: res.data.list[0].answersId }, success: (res1) => { if (res1.data.list[0].answerScore >= 0 && res1.data.list[0].answerScore != null) { wx.navigateTo({ url: '/pages/grade/grade?answersId=' + res.data.list[0].answersId, }) } else { wx.showModal({ showCancel: false, content: '当前老师批阅中,请耐心等待' }) } } }) } else { this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'answerAfterclass'); } } else { this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'answerAfterclass'); } } } } }) } else { if (!this.data.istask) { wx.showModal({ showCancel: false, content: "请先去扫描二维码加入班级群吧", success(res) { if (res.confirm) { wx.switchTab({ url: '../myMission/myMission' }) } } }) return false } if (!this.data.istask2) { wx.showModal({ showCancel: false, content: "您的课程任务还未全部完成哦!请先去完成再来期末考试吧!" }) return false } wx.request({ url: app.globalData.publicUrl + '/wx/exam/examList', method: "post", data: { sessionKey: this.data.sessionKey, clasId: this.data.classInfo.id }, success: (res) => { if (res.data.code == 0) { if (res.data.list.length == 0) { wx.showModal({ showCancel: false, content: '期末考试还未开始哦!' }) } else { if (res.data.list[0].answersId) { if (res.data.list[0].status == '1') { wx.request({ url: app.globalData.publicUrl + '/wx/answer/detail', method: "post", data: { answersId: res.data.list[0].answersId }, success: (res1) => { if (res1.data.list[0].answerScore >= 0 && res1.data.list[0].answerScore != null) { wx.navigateTo({ url: '/pages/grade/grade?answersId=' + res.data.list[0].answersId, }) } else { wx.showModal({ showCancel: false, content: '当前老师批阅中,请耐心等待' }) } } }) } else { this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'answerAfterclass'); } } else { this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'answerAfterclass'); } } } } }) } }, // 综合反馈表 goWrite2() { if (this.data.istask4) { wx.request({ url: app.globalData.publicUrl + '/wx/exam/quesExamList', method: "post", data: { sessionKey: this.data.sessionKey, questSub: '1', clasId: this.data.classInfo.id }, success: (res) => { if (res.data.code == 0) { if (res.data.list[0]) { if (res.data.list[0].answersId) { wx.navigateTo({ url: '/pages/feedBackDetail/feedBackDetail?answersId=' + res.data.list[0].answersId, }) } else { this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'feedBack'); } } } } }) } else { wx.request({ url: app.globalData.publicUrl + '/wx/exam/quesExamList', method: "post", data: { sessionKey: this.data.sessionKey, questSub: '1', clasId: this.data.classInfo.id }, success: (res) => { if (res.data.code == 0) { if (res.data.list.length == 0) { wx.showModal({ showCancel: false, content: '当前综合反馈还不可以填写哦!' }) } else { if (res.data.list[0].answersId) { if (res.data.list[0].status == '1') { wx.navigateTo({ url: '/pages/feedBackDetail/feedBackDetail?answersId=' + res.data.list[0].answersId, }) } else { this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'feedBack'); } } else { this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'feedBack'); } } } } }) } }, // 我的积分 goMyPoints() { wx.navigateTo({ url: '../myPoints/myPoints' }) }, // 领取结业证 lq() { if (this.data.classInfo.id == -1) { wx.showLoading({ mask: true, title: '加载中', }) this.setData({ myCanvasId: this.data.myCanvasId + 1 }) let str = this.data.studentName + "同志于" + this.data.classInfo.beginDate + " 至 " + this.data.classInfo.endDate + "参加学习完成规定培训内容,准予结业,特发此证。" let strArr = []; let a = str.slice(0, 16); let b = str.slice(16, 36); let c = str.slice(36, 56); strArr.push(a, b, c); const ctx = wx.createCanvasContext(this.data.myCanvasId); ctx.drawImage(this.data.byzsbj, 0, 0, 300, 415); //里面的参数无非就是图片放置的位置即图片的横纵坐标,图片的宽高 ctx.setFillStyle("#000"); ctx.setFontSize(16); //字大小 ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 let leftPositionAarr = [60, 30, 30, 30] for (let i = 0; i < strArr.length; i++) { ctx.fillText(strArr[i], leftPositionAarr[i], 160 + i * 30); } // ctx.fillText(str, 150, 160); //150:canvas画布宽300,取1/2,中间,280:纵向位置 ctx.draw(); wx.hideLoading(); this.setData({ showzs: true }); wx.request({ url: app.globalData.publicUrl + '/wx/student/wxGraduation', method: "post", data: { sessionKey: this.data.sessionKey }, success: (res) => { console.log(res.data, "领取结业证提交") } }) } else { if (!this.data.istask) { wx.showModal({ showCancel: false, content: "请先去扫描二维码加入班级群吧", success(res) { if (res.confirm) { wx.switchTab({ url: '../myMission/myMission' }) } } }) return false } if (!this.data.istask3) { wx.showModal({ showCancel: false, content: "您的期末考试还未完成哦!" }) return false } wx.showLoading({ mask: true, title: '加载中', }) this.setData({ myCanvasId: this.data.myCanvasId + 1 }) let str = this.data.studentName + "同志于" + this.data.classInfo.beginDate + " 至 " + this.data.classInfo.endDate + "参加学习完成规定培训内容,准予结业,特发此证。" let strArr = []; let a = str.slice(0, 16); let b = str.slice(16, 36); let c = str.slice(36, 56); strArr.push(a, b, c); const ctx = wx.createCanvasContext(this.data.myCanvasId); ctx.drawImage(this.data.byzsbj, 0, 0, 300, 415); //里面的参数无非就是图片放置的位置即图片的横纵坐标,图片的宽高 ctx.setFillStyle("#000"); ctx.setFontSize(16); //字大小 ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 let leftPositionAarr = [60, 30, 30, 30] for (let i = 0; i < strArr.length; i++) { ctx.fillText(strArr[i], leftPositionAarr[i], 160 + i * 30); } ctx.draw(); wx.hideLoading(); this.setData({ showzs: true }); wx.request({ url: app.globalData.publicUrl + '/wx/student/wxGraduation', method: "post", data: { sessionKey: this.data.sessionKey }, success: (res) => { console.log(res.data, "领取结业证提交") } }) } }, // 存储结业证 saveZs() { wx.canvasToTempFilePath({ //把当前画布指定区域的内容导出生成指定大小的图片 canvasId: this.data.myCanvasId, success(res) { wx.authorize({ //向用户发起授权请求 scope: 'scope.writePhotosAlbum', //保存相册授权 success: () => { wx.saveImageToPhotosAlbum({ //保存图片到系统相册 filePath: res.tempFilePath, success: () => { wx.showToast({ title: '图片保存成功' }) } }) } }) } }) }, // 证书隐藏 onClose1() { this.setData({ showzs: false }); }, toPath(id, paperId, answersId, address, status) { wx.navigateTo({ url: '/pages/' + address + '/' + address + '?id=' + id + '&paperId=' + paperId + '&answersId=' + answersId + '&status=' + status, }) }, beginKao(id, paperId, sessionKey, address) { wx.request({ url: app.globalData.publicUrl + '/wx/exam/begin', method: "post", data: { sessionKey: sessionKey, id: id, paperId: paperId }, success: (res) => { if (res.data.code == 0) { this.setData({ status: res.data.status }) this.toPath(id, paperId, res.data.answersId, address); } } }) }, async onShow() { // wx.showLoading({ // title: '加载中', // mask:true // }) const sessionKey = await tools.checkSessionAndLogin(); this.setData({ sessionKey }); this.isRz(sessionKey) } })