class.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import httpRequestApi from '../../../utils/APIClient';
  2. import {
  3. formatDate
  4. } from '../../../utils/util';
  5. const app = getApp()
  6. Page({
  7. data: {
  8. fullScreenBtn: false,
  9. playBtn: true,
  10. gesture: true,
  11. centerBtn: true,
  12. controls: true,
  13. videoLoad: false,
  14. autoPlay: true,
  15. videoUrl: '',
  16. poster: '',
  17. works: [],
  18. total: '',
  19. title: '',
  20. id: '',
  21. iconImg: '',
  22. pageNo: 1,
  23. totalNo: 0,
  24. collectFlag: false,
  25. goBackHome: false,
  26. lazyVideoUrl: '',
  27. isIOS: app.globalData.isIOS,
  28. modalType: "text",
  29. modalText: [{
  30. text: '您还不是本课程的会员',
  31. type: 'bigOrange'
  32. },
  33. {
  34. text: '您可以开团,拼团成功获得使用权',
  35. type: 'normal'
  36. }
  37. ],
  38. modalBtnText:'去开团',
  39. isModalShow: false,
  40. productId: 0,
  41. },
  42. onLoad: function (option) {
  43. console.log(option);
  44. if (option.scene || option.shareCard) {
  45. this.setData({
  46. goBackHome: true
  47. })
  48. }
  49. this.setData({
  50. // title: option.title,
  51. id: option.id
  52. })
  53. this.uid = wx.getStorageSync('uid');;
  54. httpRequestApi.getClassDetail(this.uid, option.id).success(res => {
  55. console.log(res);
  56. const classId = this.data.id;
  57. httpRequestApi.userIntoPage('pages/main/class/class','官方课程页面').success((res)=>{
  58. })
  59. this.setData({
  60. title: res.data.data.lesson.title,
  61. videoUrl: res.data.data.lesson.playUrl,
  62. iconImg: res.data.data.lesson.iconImg,
  63. productId: res.data.data.product.id
  64. })
  65. wx.setNavigationBarTitle({
  66. title: res.data.data.lesson.title //页面标题为路由参数
  67. })
  68. this.getReadInfo(1, 10);
  69. this.checkLike();
  70. })
  71. },
  72. // video组件在获得url时迅速退出页面会导致小程序闪退,官方还没修复(11/28),处理办法:懒加载思路,在用户点击时再获取videoUrl
  73. // setVideoUrl: function(){
  74. // console.log('视频地址>>>>>>>>',this.data.lazyVideoUrl)
  75. // this.setData({
  76. // videoUrl: this.data.lazyVideoUrl,
  77. // })
  78. // },
  79. videoPlayHandler: function () {
  80. this.setData({
  81. videoLoad: true
  82. }, () => {
  83. this.videoCtx = wx.createVideoContext('classVideo', this);
  84. this.videoCtx.play();
  85. })
  86. },
  87. // 检查是否收藏
  88. checkLike: function () {
  89. httpRequestApi.classIsLike(this.uid, {
  90. targetCode: this.data.id
  91. }).success(res => {
  92. this.setData({
  93. collectFlag: res.data.data
  94. })
  95. })
  96. },
  97. goToReading: function () {
  98. let classId = this.data.id;
  99. // httpRequestApi.checkLesson(classId).success(res => {
  100. // const productId = res.data.data[0];
  101. // this.setData({
  102. // productId
  103. // })
  104. // });
  105. httpRequestApi.areYouSuper(this.data.productId).success(res => {
  106. if (res.data.success) {
  107. wx.navigateTo({
  108. url: `../../main/reading/reading?id=${this.data.id}`
  109. })
  110. } else {
  111. // ios用户 并且没有购买过此书
  112. // if (app.globalData.isIOS) {
  113. // wx.showModal({
  114. // title: '暂不支持',
  115. // content: '十分抱歉,由于相关规定,您暂时无法在这里朗读',
  116. // success(res) {
  117. // if (res.confirm) {
  118. // console.log('用户点击确定')
  119. // } else if (res.cancel) {
  120. // console.log('用户点击取消')
  121. // }
  122. // }
  123. // })
  124. // return;
  125. // }
  126. this.setData({
  127. isModalShow: true
  128. })
  129. // wx.showModal({
  130. // title: '您未购买过本书,不能朗读',
  131. // content: '超值团购进行中,快去看看',
  132. // success(res) {
  133. // if (res.confirm) {
  134. // console.log('用户点击确定')
  135. // wx.navigateTo({
  136. // url: `../../groupPage/grade-details/grade-details?productId=${productId}`
  137. // })
  138. // } else if (res.cancel) {
  139. // console.log('用户点击取消')
  140. // }
  141. // }
  142. // })
  143. }
  144. })
  145. },
  146. modalConfirmHandler: function () {
  147. this.setData({
  148. isModalShow: false
  149. })
  150. wx.navigateTo({
  151. url: `../../groupPage/grade-details/grade-details?productId=${this.data.productId}`
  152. })
  153. },
  154. modalCloseHandler: function (){
  155. this.setData({
  156. isModalShow: false
  157. })
  158. },
  159. openShare: function (e) {
  160. // this.setData({
  161. // shareFlag: !this.data.shareFlag
  162. // })
  163. this.shareDialog = this.selectComponent("#share-dialog");
  164. const data = {
  165. avatar: this.data.authorAvatar,
  166. author: this.data.author,
  167. iconImg: this.data.iconImg,
  168. title: this.data.title,
  169. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}`
  170. // tip: this.data.tip,
  171. }
  172. this.shareDialog.share(data);
  173. },
  174. onShareAppMessage: function (res) {
  175. console.log(this.data.productId)
  176. if (res.from === 'button') {
  177. // 来自页面内转发按钮
  178. console.log(res.target)
  179. }
  180. return {
  181. title: '老师同学都在玩的配音show,你还在等什么?',
  182. path: `pages/main/class/class?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
  183. imageUrl: `https://efunbox.lingjiao.cn/reader/resource/share/lesson_${this.data.productId}.jpg`
  184. }
  185. },
  186. goToWorks: function (e) {
  187. console.log(this.data.works)
  188. // this.videoCtx = wx.createVideoContext('myVideo', this);
  189. if (this.videoCtx) {
  190. this.videoCtx.stop();
  191. }
  192. console.log(e);
  193. let readId = e.currentTarget.dataset.id;
  194. let title = this.data.title;
  195. wx.navigateTo({
  196. url: `../../social/works/works?id=${readId}&title=${title}`
  197. })
  198. },
  199. collect: function (e) {
  200. // let uid = wx.getStorageSync('uid');
  201. let data = {
  202. targetCode: this.data.id,
  203. // title: this.data.title,
  204. // iconImg: this.data.iconImg
  205. }
  206. httpRequestApi.collectClass(this.uid, data).success(res => {
  207. this.setData({
  208. collectFlag: !this.data.collectFlag
  209. })
  210. })
  211. },
  212. getReadInfo: function (pageNo, pageSize) {
  213. // const uid = wx.getStorageSync('uid');
  214. const data = {
  215. lessonId: this.data.id,
  216. pageNo: this.data.pageNo,
  217. pageSize: 10
  218. };
  219. httpRequestApi.getClassRead(this.uid, data).success(res => {
  220. const readInfo = res.data.data.list;
  221. const readTemp = [];
  222. readInfo.forEach(item => {
  223. const temp = {};
  224. temp.nickName = item.user.wechatName;
  225. temp.time = formatDate(item.userRead.gmtModified, 3);
  226. temp.avatar = item.user.avatar;
  227. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  228. temp.uid = item.userRead.uid;
  229. temp.id = item.userRead.id;
  230. console.log(item.userRead)
  231. this.data.works.push(temp);
  232. });
  233. this.setData({
  234. totalNo: res.data.data.totalNo,
  235. total: res.data.data.totalSize,
  236. works: this.data.works
  237. })
  238. });
  239. },
  240. // 下拉加载
  241. onReachBottom: function (e) {
  242. console.log(this.data.totalNo);
  243. this.setData({
  244. pageNo: this.data.pageNo + 1
  245. })
  246. if (this.data.pageNo <= this.data.totalNo) {
  247. this.getReadInfo();
  248. }
  249. },
  250. onHide: function () {
  251. let videoCtx = wx.createVideoContext('classVideo', this);
  252. videoCtx.stop();
  253. },
  254. })