const app = require('../../utils/util.js'); Page({ /** * 页面的初始数据 */ data: { showewm: false, showzs: false, kcArr: [], ewmurl: '', sfmArr: [], className: '', istask1: false, istask2: false, istask3: false, istask4: false, istask5: false }, selectBtn0() { this.setData({ select: 0 }); }, selectBtn1() { this.setData({ select: 1 }); }, gokhAnswer() { wx.navigateTo({ url: '../answerAfterclass/answerAfterclass' }) }, gopjClass() { wx.navigateTo({ url: '../evaluationCourse/evaluationCourse' }) }, startAnswer() { wx.navigateTo({ url: '/pages/answerAfterclass/answerAfterclass', }) }, goWrite() { // wx.showModal({ // showCancel: false, // content: "敬请期待", // success(res) {} // }) wx.navigateTo({ url: '../studentRegistration/studentRegistration' }) }, goWrite2() { // wx.showModal({ // showCancel: false, // content: "敬请期待", // success(res) {} // }) wx.navigateTo({ url: '../feedBack/feedBack' }) }, lq() { // wx.showModal({ // showCancel: false, // content: "此功能暂时还未开放哦", // success(res) {} // }) this.setData({ showzs: true }); }, // 跳转直播点播页面 goStudy(e) { let id = e.currentTarget.dataset.item.id if (e.currentTarget.dataset.item.isLive == 1) { if (e.currentTarget.dataset.item.isActive == 1) { wx.navigateTo({ url: '../zbDetails/zbDetails?id=' + id }) } else { wx.showModal({ showCancel: false, content: "直播还未开始哦", success(res) {} }) } } else { wx.navigateTo({ url: '../dbDetails/dbDetails?id=' + id }) } }, getMycourse(sessionKey) { var _this = this; wx.request({ url: app.globalData.publicUrl + '/wx/course/selectBySessionKey', method: "post", data: { sessionKey: sessionKey }, success: function (res) { if (res.data.code == 0 && res.data.list.length !== 0) { _this.setData({ kcArr: res.data.list, istask3: res.data.allDone }); let result = []; if (res.data.list) for (var 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}秒`; }, // 学员身份认证 检查第一个任务 checkTaskList(sessionKey) { var _this = this; wx.request({ url: app.globalData.publicUrl2 + '/wx/student/selStudentSessionKey', method: "post", data: { sessionKey: sessionKey }, success: function (res) { console.log(res.data, "wwwwww") if (res.data.code == 0) { if (res.data.data.remark == 1) { _this.setData({ istask1: true }) } } } }) }, // 查询我是否有班&&班级名字 isClass(sessionKey) { var _this = this; wx.request({ url: app.globalData.publicUrl2 + '/wx/student/selMyClas', method: "post", data: { sessionKey: sessionKey }, success: function (res) { console.log(res, "我是返回是否有班级") if (res.data.code == 0) { _this.setData({ className: res.data.data.clasName, ewmurl: res.data.data.codeImg }) } else { wx.showModal({ content: "您当前还没有开放的班级!", showCancel: false, success(res) { if (res.confirm) { wx.switchTab({ url: '../index/index' }) } } }) return false; } } }) }, // 记录二维码已经点击 ewmClick(sessionKey) { let _this = this; wx.request({ url: app.globalData.publicUrl2 + '/wx/student/wxGroup', method: "post", data: { sessionKey: sessionKey }, success: function (res) { console.log(res) _this.setData({ showewm: true, istask1: true }) } }) }, // ewmGet(sessionKey) { // let _this = this; // wx.request({ // url: app.globalData.publicUrl2 + '/wx/student/selAllClas', // method: "post", // data: { // sessionKey: sessionKey // }, // success: function (res) { // console.log(res.data.data, "22222222") // var filterArr = res.data.data.claList.filter(o => o.isActive == 5) // console.log(filterArr, "111111111111") // if (filterArr.length !== 0) { // _this.setData({ // ewmurl: filterArr[0].codeImg // }) // } // } // }) // }, showEwm() { var sessionKey = ""; var _this = this; wx.checkSession({ success: () => { console.log("我有缓存") sessionKey = wx.getStorageSync('sessionKey'); // console.log(sessionKey) _this.ewmClick(sessionKey) // _this.ewmGet(sessionKey) }, fail() { console.log("我没有缓存并去登录请求") wx.login({ success(res) { console.log(res); var code = res.code wx.request({ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', method: "get", data: { code }, success: function (res) { sessionKey = res.data.sessionKey; wx.setStorageSync('sessionKey', res.data.sessionKey); _this.ewmClick(sessionKey) // _this.ewmGet(sessionKey) } }) } }) } }) }, onShow() { var _this = this; wx.checkSession({ success: () => { console.log("我有缓存") var sessionKey = wx.getStorageSync('sessionKey'); console.log(sessionKey, "我有缓存") if (sessionKey == "") { wx.login({ success(res) { console.log(res); var code = res.code wx.request({ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', method: "get", data: { code }, success: function (res) { sessionKey = res.data.sessionKey; wx.setStorageSync('sessionKey', res.data.sessionKey); _this.checkTaskList(sessionKey) _this.isClass(sessionKey); _this.getMycourse(sessionKey); } }) } }) } else { _this.checkTaskList(sessionKey) _this.isClass(sessionKey); _this.getMycourse(sessionKey); } }, fail() { console.log("我没有缓存并去登录请求") wx.login({ success(res) { console.log(res); var code = res.code wx.request({ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', method: "get", data: { code }, success: function (res) { wx.setStorageSync('sessionKey', res.data.sessionKey); var sessionKey = res.data.sessionKey; _this.checkTaskList(sessionKey) _this.isClass(sessionKey); _this.getMycourse(sessionKey); } }) } }) } }) }, onClose() { wx.hideLoading() this.setData({ showewm: false }); }, onClose1() { this.setData({ showzs: false }); }, /** * 生命周期函数--监听页面初次渲染完成 */ saveImg() { let _this = this; console.log(_this.data.ewmurl) wx.getSetting({ success(res) { if (!res.authSetting['scope.writePhotosAlbum']) { wx.authorize({ scope: 'scope.writePhotosAlbum', success() { console.log(res, "我点击同意啦") wx.showLoading({ title: '保存中...' }) var imgSrc = _this.data.ewmurl; wx.downloadFile({ url: imgSrc, success: function (res) { console.log(res, '我下载完成啦'); //图片保存到本地 wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success: function (data) { console.log(data, '我保存成功啦') wx.hideLoading(); wx.showToast({ title: '保存成功', icon: 'success', duration: 2000 }) }, fail: function (err) { console.log(err, '我保存失败啦') wx.hideLoading(); if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") { console.log("当初用户拒绝,再次发起授权") wx.openSetting({ success(settingdata) { console.log(settingdata) if (settingdata.authSetting['scope.writePhotosAlbum']) { console.log('获取权限成功,给出再次点击图片保存到相册的提示。') } else { console.log('获取权限失败,给出不给权限就无法正常使用的提示') } } }) } }, complete(res) { console.log(res); } }) } }) console.log('授权成功') } }) } else { var imgSrc = _this.data.ewmurl wx.downloadFile({ url: imgSrc, success: function (res) { console.log(res, '我下载完成啦'); wx.hideLoading(); //图片保存到本地 wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success: function (data) { console.log(data, '我保存成功啦') wx.hideLoading(); wx.showToast({ title: '保存成功', icon: 'success', duration: 2000 }) }, fail: function (err) { console.log(err, '我保存失败啦') wx.hideLoading(); if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") { console.log("当初用户拒绝,再次发起授权") wx.openSetting({ success(settingdata) { console.log(settingdata) if (settingdata.authSetting['scope.writePhotosAlbum']) { console.log('获取权限成功,给出再次点击图片保存到相册的提示。') } else { console.log('获取权限失败,给出不给权限就无法正常使用的提示') } } }) } }, complete(res) { console.log(res); } }) } }) } } }) }, onReady: function () { }, /** * 生命周期函数--监听页面显示 */ // onShow: function () { // }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })