courseDetail.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. const app = getApp()
  2. const util = require("../../../utils/util");
  3. const api = require('../../../api/api.js');
  4. const user = require('../../../utils/user.js');
  5. import moment from 'moment'
  6. var WxParse = require('../../../lib/wxParse/wxParse.js');
  7. Page({
  8. data: {
  9. isFinished:false,
  10. id:'',
  11. courseid:'',
  12. courseHtml:'',
  13. courseInfo:{
  14. arrangement:{
  15. },
  16. course:{
  17. contentType:''
  18. },
  19. courseSkill:'',
  20. courseVideoList:[
  21. ],
  22. enrolment:{},
  23. relationCourse:[],
  24. }
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. console.log(options);
  31. if(options){
  32. this.setData({
  33. id:options.id,
  34. courseid:options.courseid
  35. });
  36. }
  37. this.getCourseDetail();
  38. },
  39. /**
  40. * 生命周期函数--监听页面初次渲染完成
  41. */
  42. onReady: function () {
  43. },
  44. /**
  45. * 生命周期函数--监听页面显示
  46. */
  47. onShow: function () {
  48. },
  49. videoBegin(e){
  50. console.log(e);
  51. // wx.showModal({
  52. // title: 'start',
  53. // content: JSON.stringify(e),
  54. // showCancel: false,
  55. // confirmText: '确定',
  56. // success: function (res) {
  57. // }
  58. // })
  59. },
  60. videoPlay(e){
  61. console.log(e);
  62. },
  63. videoEnd(e){
  64. console.log(e);
  65. let videoid=e.currentTarget.dataset.videoid;
  66. // wx.showModal({
  67. // title: 'end',
  68. // content: JSON.stringify(e),
  69. // showCancel: false,
  70. // confirmText: '确定',
  71. // success: function (res) {
  72. // }
  73. // });
  74. let userInfo = wx.getStorageSync('userInfo');
  75. util.request(api.addStudyLog, {
  76. courseEmentId:this.data.id,
  77. courseId:this.data.courseid,
  78. videoOssId:videoid,
  79. workerNo: userInfo.workerNo,
  80. workerName:userInfo.workerName
  81. }, 'POST').then(res=> {
  82. if (res.errno === 0) {
  83. wx.showToast({
  84. title: '该视频已完成',
  85. icon:'none'
  86. });
  87. this.getCourseDetail();
  88. }
  89. });
  90. },
  91. getCourseDetail(){
  92. util.request(api.getCourseInfo, {
  93. enrolmentId:this.data.id,
  94. courseId:this.data.courseid
  95. }, 'GET').then(res=> {
  96. if (res.errno === 0) {
  97. this.setData({
  98. courseInfo:res.data,
  99. isFinished:res.data.enrolment.isCompleted==1?true:false
  100. });
  101. if(this.data.courseInfo.course.contentType==1){
  102. let detail=this.data.courseInfo.course.courseContent;
  103. WxParse.wxParse('courseHtml', 'html', detail, this);
  104. }
  105. let list=this.data.courseInfo.courseVideoList;
  106. if(list.length>0){
  107. list.forEach((item,index)=>{
  108. if(index==0){
  109. item.isTiled=true;
  110. }else{
  111. item.isTiled=false;
  112. }
  113. });
  114. this.setData({
  115. 'courseInfo.courseVideoList':list
  116. });
  117. }
  118. }
  119. });
  120. },
  121. goCourseDetail(e){
  122. let courseid=e.currentTarget.dataset.id;
  123. wx.navigateTo({
  124. url: '/pages/upgrade/courseDetail/courseDetail?id='+''+'&courseid='+courseid,
  125. });
  126. },
  127. toggleVideo(e){
  128. let index=e.currentTarget.dataset.index;
  129. let istiled=e.currentTarget.dataset.istiled;
  130. if(!istiled){
  131. let list=this.data.courseInfo.courseVideoList;
  132. list.forEach((item,index)=>{
  133. item.isTiled=false;
  134. });
  135. this.setData({
  136. 'courseInfo.courseVideoList':list
  137. });
  138. let itemData = "courseInfo.courseVideoList[" + index + "].isTiled";
  139. this.setData({
  140. [itemData]:true
  141. });
  142. }
  143. },
  144. switchTab(e){
  145. let tab=e.currentTarget.dataset.tab;
  146. if(this.data.currentTab!=tab){
  147. this.setData({
  148. currentTab:tab
  149. });
  150. }
  151. },
  152. goHistory(){
  153. wx.pageScrollTo({
  154. selector: '.tab-sticky',
  155. duration: 300
  156. })
  157. this.setData({
  158. currentTab:'history'
  159. });
  160. },
  161. goLearn(){
  162. wx.navigateTo({
  163. url: '/pages/upgrade/courseDetail/courseDetail',
  164. })
  165. },
  166. submit(){
  167. util.request(api.complateCourse, {
  168. enrolmentId:this.data.id,
  169. }, 'GET').then(res=> {
  170. if (res.errno === 0) {
  171. this.setData({
  172. isFinished:true,
  173. })
  174. }else{
  175. wx.showToast({
  176. title: res.errmsg,
  177. icon:'none'
  178. })
  179. }
  180. });
  181. },
  182. onHide: function () {
  183. },
  184. onUnload: function () {
  185. },
  186. /**
  187. * 页面相关事件处理函数--监听用户下拉动作
  188. */
  189. onPullDownRefresh: function () {
  190. },
  191. /**
  192. * 页面上拉触底事件的处理函数
  193. */
  194. onReachBottom: function () {
  195. },
  196. /**
  197. * 用户点击右上角分享
  198. */
  199. onShareAppMessage: function () {
  200. },
  201. })