const app=getApp(); var utils=require("../../../utils/http"); var time=60; Page({ /** * 页面的初始数据 */ data: { imgUrl:app.globalData.imgUrl, tid:'', cid:'', trainobj:'', cover:'', summerymsg:'', sumuplist:[], sumupage:1, datashow:false, controls:true, timeout:'' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.showLoading({ title: '加载中...', }) this.setData({ tid:options.tid, cid:options.cid }) this.trainmsg(); this.sumuplistfun(); }, trainmsg:function(){ let that=this; utils.$post({ url: app.globalData.webUrl + 'api/train/courseDetail', header: { 'Authorization':'bearer '+app.globalData.token }, data:{ course_id:that.data.cid }, success: function (res) { if(res.data.code=='0'){ that.setData({ trainobj:res.data.data }) wx.setNavigationBarTitle({ title: res.data.data.title }) if(res.data.data.study_time!=0){ time=res.data.data.study_time*60; that.setData({ timeout:setInterval(function(){ time--; if(time<=0){ clearInterval(that.data.timeout); that.readfun(); } },1000) }) }else{ time=0; } } wx.hideLoading(); } }) }, sumuplistfun:function(){ let that=this; that.setData({ sumupage:1 }) utils.$post({ url: app.globalData.webUrl + 'api/train/watch_feel', header: { 'Authorization':'bearer '+app.globalData.token }, data:{ page:1, course_id:that.data.cid, class_id:that.data.tid, }, success: function (res) { if(res.data.code=='0'){ that.setData({ sumuplist:res.data.data, datashow:true }) } setTimeout(function(){ wx.hideLoading(); },1000) } }) }, summerytap:function(e){ let that=this; that.setData({ summerymsg:e.detail.value }) }, setsumuptap: function () { let that=this; if(!that.data.summerymsg){ wx.showToast({ title: '总结不能为空!', icon: 'none', duration: 2000 }) return false; } wx.showLoading({ title: '添加中...', }) console.log(time) utils.$get({ url: app.globalData.webUrl + 'api/train/commentAdd', header: { 'Authorization':'bearer '+app.globalData.token }, data:{ course_id:that.data.cid, class_id:that.data.tid, content:that.data.summerymsg, read_status:that.data.trainobj.comment_word_num==0?false:that.data.trainobj.study_time==0?true:time<=0?true:false }, success: function (res) { wx.hideLoading(); if(res.data.code=='0'){ that.sumuplistfun(); that.setData({ summerymsg:"" }) wx.showToast({ title: '总结添加成功!', icon: 'success', duration: 2000 }) setTimeout(function(){ time=60; },3000) } } }) }, goodtap:function(e){ var that=this; utils.$post({ url: app.globalData.webUrl + 'api/train/thumbing', header: { 'Authorization':'bearer '+app.globalData.token }, data:{ sumup_id:e.currentTarget.dataset.tid }, success: function (res) { if(res.data.code=='0'){ let sumuplist=that.data.sumuplist; if(res.data.msg.includes('取消点赞')){ sumuplist[e.currentTarget.dataset.idx].thumb--; sumuplist[e.currentTarget.dataset.idx].thumblog=false; }else{ sumuplist[e.currentTarget.dataset.idx].thumb++; sumuplist[e.currentTarget.dataset.idx].thumblog=true; } that.setData({ sumuplist:sumuplist }) wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000 }) } } }) }, readfun:function(){ let that=this; clearInterval(that.data.timeout); utils.$post({ url: app.globalData.webUrl + 'api/train/doneLogging', header: { 'Authorization':'bearer '+app.globalData.token }, data:{ course_id:that.data.cid, class_id:that.data.tid, alertshow:152 }, success: function (res) { } }) }, looktap(e){ wx.previewImage({ current: e.currentTarget.dataset.src, // 当前显示图片的http链接 urls: [e.currentTarget.dataset.src] // 需要预览的图片http链接列表 }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { clearInterval(this.data.timeout); setTimeout(function(){ time=60; },1000) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { let that=this; that.setData({ sumupage:1 }) utils.$post({ url: app.globalData.webUrl + 'api/train/watch_feel', header: { 'Authorization':'bearer '+app.globalData.token }, data:{ course_id:that.data.cid, class_id:that.data.tid, page:1 }, success: function (res) { wx.stopPullDownRefresh(); if(res.data.code=='0'){ that.setData({ sumuplist:res.data.data }) } wx.hideLoading(); } }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { let that=this; let sumupage=that.data.sumupage; sumupage=sumupage*1+1; that.setData({ sumupage:sumupage }) utils.$post({ url: app.globalData.webUrl + 'api/train/watch_feel', header: { 'Authorization':'bearer '+app.globalData.token }, data:{ course_id:that.data.cid, class_id:that.data.tid, page:sumupage, }, success: function (res) { let sumuplist=that.data.sumuplist; if(res.data.code=='0'){ sumuplist=sumuplist.concat(res.data.data); that.setData({ sumuplist:sumuplist }) } wx.hideLoading(); } }) }, /** * 用户点击右上角分享 */ // onShareAppMessage: function () { // } })