class.js 7.1 KB

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