// pages/experienceList/experienceList.js const app = getApp() var util = require("../../../utils/util.js") Page({ data: { collegeId: '', c_code: '', showPayTime: '', timer: null, video_length: '', testFinish: '' }, onLoad: function(options) { console.log(options) this.setData({ navH: app.globalData.navHeight, collegeId: options.collegeId, c_code: options.code, testFinish: options.testFinish }) this.init(options.collegeId) }, init(id) { const that = this util.postData('/college/queryCoreDetail', { openid: app.globalData.openid, collegeId: id }) .then(res => { console.log(res) this.setData({ info: res }) if (res.status == 9) { } else { // var hour = time.split(':')[0]; let min = res.countdown.split(':')[0]; let sec = res.countdown.split(':')[1]; let s = Number(min * 60) + Number(sec); // console.log(s); //130 this.getTime(s) } }) .catch(err => { console.log(err); }) }, gototest() { wx.navigateTo({ url: "/pages/testing/testing?core_id=" + this.data.collegeId + '&testFinish=' + this.data.testFinish }) }, thumbsUp() { const that = this; // console.log(app.globalData.userphone,that.data.collegeId) util.postData('/college/corePositive', { openid: app.globalData.openid, c_code: that.data.c_code }) .then(res => { console.log(res) if (res == '1') { wx.showToast({ title: '点赞成功', icon: 'none', duration: 2000 }) let res2 = { ...this.data.info, positive: this.data.info.positive + 1, ispositive: 8 } this.setData({ info: res2 }) } else { wx.showToast({ title: '您已经点过赞了~', icon: 'none', duration: 2000 }) } }) .catch(err => { console.log(err); }) }, // 获取计算的时间 getShowTime(maxtime) { const that = this; let minutes = Math.floor((maxtime % 3600) / 60).toString().padStart(2, '0'); let seconds = Math.floor(maxtime % 60).toString().padStart(2, '0'); this.setData({ showPayTime: `${minutes}:${seconds}` }) console.log(this.data.showPayTime); // let min = this.data.showPayTime.split(':')[0]; // let sec = this.data.showPayTime.split(':')[1]; // let s = Number(min * 60) + Number(sec); // console.log(s); //130 util.postData('/college/coreLearningUpdate', { openid: app.globalData.openid, c_code: that.data.c_code, rate: that.data.showPayTime }) .then(res => { // console.log(res) }) .catch(err => { console.log(err); }) }, // 倒计时 getTime(maxtime, callback) { const that = this; this.getShowTime(maxtime); let Timer = setInterval(() => { if (!!maxtime && maxtime >= 0) { this.getShowTime(maxtime); --maxtime; } else { util.postData('/college/coreLearningFinish', { openid: app.globalData.openid, c_code: that.data.c_code }) .then(res => { console.log(res) }) .catch(err => { console.log(err); }) this.setData({ showPayTime: '00:00' }) clearInterval(Timer); } }, 1000) this.setData({ timer: Timer }) }, onUnload: function() { // console.log('onUnload') console.log(this.data.timer) if (this.data.timer) { this.setData({ showPayTime: '' }) clearInterval(this.data.timer); } }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { } })