class.js 7.2 KB

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