trainmsg.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. const app=getApp();
  2. var utils=require("../../../utils/http");
  3. var time=60;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. imgUrl:app.globalData.imgUrl,
  10. tid:'',
  11. cid:'',
  12. trainobj:'',
  13. cover:'',
  14. summerymsg:'',
  15. sumuplist:[],
  16. sumupage:1,
  17. datashow:false,
  18. controls:true,
  19. timeout:''
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. wx.showLoading({
  26. title: '加载中...',
  27. })
  28. this.setData({
  29. tid:options.tid,
  30. cid:options.cid
  31. })
  32. this.trainmsg();
  33. this.sumuplistfun();
  34. },
  35. trainmsg:function(){
  36. let that=this;
  37. utils.$post({
  38. url: app.globalData.webUrl + 'api/train/courseDetail',
  39. header: {
  40. 'Authorization':'bearer '+app.globalData.token
  41. },
  42. data:{
  43. course_id:that.data.cid
  44. },
  45. success: function (res) {
  46. if(res.data.code=='0'){
  47. that.setData({
  48. trainobj:res.data.data
  49. })
  50. wx.setNavigationBarTitle({
  51. title: res.data.data.title
  52. })
  53. if(res.data.data.study_time!=0){
  54. time=res.data.data.study_time*60;
  55. that.setData({
  56. timeout:setInterval(function(){
  57. time--;
  58. if(time<=0){
  59. clearInterval(that.data.timeout);
  60. that.readfun();
  61. }
  62. },1000)
  63. })
  64. }else{
  65. time=0;
  66. }
  67. }
  68. wx.hideLoading();
  69. }
  70. })
  71. },
  72. sumuplistfun:function(){
  73. let that=this;
  74. that.setData({
  75. sumupage:1
  76. })
  77. utils.$post({
  78. url: app.globalData.webUrl + 'api/train/watch_feel',
  79. header: {
  80. 'Authorization':'bearer '+app.globalData.token
  81. },
  82. data:{
  83. page:1,
  84. course_id:that.data.cid,
  85. class_id:that.data.tid,
  86. },
  87. success: function (res) {
  88. if(res.data.code=='0'){
  89. that.setData({
  90. sumuplist:res.data.data,
  91. datashow:true
  92. })
  93. }
  94. setTimeout(function(){
  95. wx.hideLoading();
  96. },1000)
  97. }
  98. })
  99. },
  100. summerytap:function(e){
  101. let that=this;
  102. that.setData({
  103. summerymsg:e.detail.value
  104. })
  105. },
  106. setsumuptap: function () {
  107. let that=this;
  108. if(!that.data.summerymsg){
  109. wx.showToast({
  110. title: '总结不能为空!',
  111. icon: 'none',
  112. duration: 2000
  113. })
  114. return false;
  115. }
  116. wx.showLoading({
  117. title: '添加中...',
  118. })
  119. console.log(time)
  120. utils.$get({
  121. url: app.globalData.webUrl + 'api/train/commentAdd',
  122. header: {
  123. 'Authorization':'bearer '+app.globalData.token
  124. },
  125. data:{
  126. course_id:that.data.cid,
  127. class_id:that.data.tid,
  128. content:that.data.summerymsg,
  129. read_status:that.data.trainobj.comment_word_num==0?false:that.data.trainobj.study_time==0?true:time<=0?true:false
  130. },
  131. success: function (res) {
  132. wx.hideLoading();
  133. if(res.data.code=='0'){
  134. that.sumuplistfun();
  135. that.setData({
  136. summerymsg:""
  137. })
  138. wx.showToast({
  139. title: '总结添加成功!',
  140. icon: 'success',
  141. duration: 2000
  142. })
  143. setTimeout(function(){
  144. time=60;
  145. },3000)
  146. }
  147. }
  148. })
  149. },
  150. goodtap:function(e){
  151. var that=this;
  152. utils.$post({
  153. url: app.globalData.webUrl + 'api/train/thumbing',
  154. header: {
  155. 'Authorization':'bearer '+app.globalData.token
  156. },
  157. data:{
  158. sumup_id:e.currentTarget.dataset.tid
  159. },
  160. success: function (res) {
  161. if(res.data.code=='0'){
  162. let sumuplist=that.data.sumuplist;
  163. if(res.data.msg.includes('取消点赞')){
  164. sumuplist[e.currentTarget.dataset.idx].thumb--;
  165. sumuplist[e.currentTarget.dataset.idx].thumblog=false;
  166. }else{
  167. sumuplist[e.currentTarget.dataset.idx].thumb++;
  168. sumuplist[e.currentTarget.dataset.idx].thumblog=true;
  169. }
  170. that.setData({
  171. sumuplist:sumuplist
  172. })
  173. wx.showToast({
  174. title: res.data.msg,
  175. icon: 'none',
  176. duration: 2000
  177. })
  178. }
  179. }
  180. })
  181. },
  182. readfun:function(){
  183. let that=this;
  184. clearInterval(that.data.timeout);
  185. utils.$post({
  186. url: app.globalData.webUrl + 'api/train/doneLogging',
  187. header: {
  188. 'Authorization':'bearer '+app.globalData.token
  189. },
  190. data:{
  191. course_id:that.data.cid,
  192. class_id:that.data.tid,
  193. alertshow:152
  194. },
  195. success: function (res) {
  196. }
  197. })
  198. },
  199. looktap(e){
  200. wx.previewImage({
  201. current: e.currentTarget.dataset.src, // 当前显示图片的http链接
  202. urls: [e.currentTarget.dataset.src] // 需要预览的图片http链接列表
  203. })
  204. },
  205. /**
  206. * 生命周期函数--监听页面初次渲染完成
  207. */
  208. onReady: function () {
  209. },
  210. /**
  211. * 生命周期函数--监听页面显示
  212. */
  213. onShow: function () {
  214. },
  215. /**
  216. * 生命周期函数--监听页面隐藏
  217. */
  218. onHide: function () {
  219. },
  220. /**
  221. * 生命周期函数--监听页面卸载
  222. */
  223. onUnload: function () {
  224. clearInterval(this.data.timeout);
  225. setTimeout(function(){
  226. time=60;
  227. },1000)
  228. },
  229. /**
  230. * 页面相关事件处理函数--监听用户下拉动作
  231. */
  232. onPullDownRefresh: function () {
  233. let that=this;
  234. that.setData({
  235. sumupage:1
  236. })
  237. utils.$post({
  238. url: app.globalData.webUrl + 'api/train/watch_feel',
  239. header: {
  240. 'Authorization':'bearer '+app.globalData.token
  241. },
  242. data:{
  243. course_id:that.data.cid,
  244. class_id:that.data.tid,
  245. page:1
  246. },
  247. success: function (res) {
  248. wx.stopPullDownRefresh();
  249. if(res.data.code=='0'){
  250. that.setData({
  251. sumuplist:res.data.data
  252. })
  253. }
  254. wx.hideLoading();
  255. }
  256. })
  257. },
  258. /**
  259. * 页面上拉触底事件的处理函数
  260. */
  261. onReachBottom: function () {
  262. let that=this;
  263. let sumupage=that.data.sumupage;
  264. sumupage=sumupage*1+1;
  265. that.setData({
  266. sumupage:sumupage
  267. })
  268. utils.$post({
  269. url: app.globalData.webUrl + 'api/train/watch_feel',
  270. header: {
  271. 'Authorization':'bearer '+app.globalData.token
  272. },
  273. data:{
  274. course_id:that.data.cid,
  275. class_id:that.data.tid,
  276. page:sumupage,
  277. },
  278. success: function (res) {
  279. let sumuplist=that.data.sumuplist;
  280. if(res.data.code=='0'){
  281. sumuplist=sumuplist.concat(res.data.data);
  282. that.setData({
  283. sumuplist:sumuplist
  284. })
  285. }
  286. wx.hideLoading();
  287. }
  288. })
  289. },
  290. /**
  291. * 用户点击右上角分享
  292. */
  293. // onShareAppMessage: function () {
  294. // }
  295. })