class.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import httpRequestApi from '../../../utils/APIClient';
  2. import {
  3. formatDate
  4. } from '../../../utils/util';
  5. Page({
  6. data: {
  7. fullScreenBtn: false,
  8. playBtn: false,
  9. gesture: true,
  10. videoUrl: '',
  11. poster: '',
  12. works: [],
  13. total: '',
  14. title: '',
  15. id: '',
  16. iconImg: '',
  17. pageNo: 1,
  18. totalNo: 0,
  19. collectFlag: false,
  20. goBackHome: false
  21. },
  22. onLoad: function (option) {
  23. console.log(option);
  24. if(option.scene){
  25. this.setData({
  26. goBackHome: true
  27. })
  28. }
  29. this.setData({
  30. // title: option.title,
  31. id: option.id
  32. })
  33. this.uid = wx.getStorageSync('uid');;
  34. httpRequestApi.getClassDetail(this.uid, option.id).success(res => {
  35. console.log(res);
  36. this.setData({
  37. title: res.data.data.title,
  38. videoUrl: res.data.data.playUrl,
  39. iconImg: res.data.data.iconImg
  40. },()=>{
  41. wx.setNavigationBarTitle({
  42. title: res.data.data.title //页面标题为路由参数
  43. })
  44. })
  45. this.getReadInfo(1, 10);
  46. this.checkLike();
  47. })
  48. },
  49. // 检查是否收藏
  50. checkLike: function () {
  51. httpRequestApi.classIsLike(this.uid, {
  52. targetCode: this.data.id
  53. }).success(res => {
  54. this.setData({
  55. collectFlag: res.data.data
  56. })
  57. })
  58. },
  59. goToReading: function () {
  60. let classId = this.data.id;
  61. httpRequestApi.checkLesson(classId).success(res=>{
  62. const productId = res.data.data[0];
  63. httpRequestApi.areYouSuper(res.data.data).success(res => {
  64. if(res.data.success){
  65. wx.navigateTo({
  66. url: `../../main/reading/reading?id=${classId}`
  67. })
  68. } else {
  69. wx.showModal({
  70. title: '您未购买过本书,不能朗读',
  71. content: '超值团购进行中,快去看看',
  72. success (res) {
  73. if (res.confirm) {
  74. console.log('用户点击确定')
  75. wx.navigateTo({
  76. url: `../../groupPage/grade-details/grade-details?productId=${productId}`
  77. })
  78. } else if (res.cancel) {
  79. console.log('用户点击取消')
  80. }
  81. }
  82. })
  83. }
  84. })
  85. });
  86. },
  87. openShare: function (e) {
  88. // this.setData({
  89. // shareFlag: !this.data.shareFlag
  90. // })
  91. this.shareDialog = this.selectComponent("#share-dialog");
  92. const data = {
  93. avatar: this.data.authorAvatar,
  94. author: this.data.author,
  95. iconImg: this.data.iconImg,
  96. title: this.data.title,
  97. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}`
  98. // tip: this.data.tip,
  99. }
  100. this.shareDialog.share(data);
  101. },
  102. onShareAppMessage: function (res) {
  103. if (res.from === 'button') {
  104. // 来自页面内转发按钮
  105. console.log(res.target)
  106. }
  107. return {
  108. title: this.data.title,
  109. path: `pages/main/class/class?id=${this.data.id}&title=${this.data.title}`,
  110. imageUrl: this.data.iconImg
  111. }
  112. },
  113. goToWorks: function (e) {
  114. console.log(this.data.works)
  115. // this.videoCtx = wx.createVideoContext('myVideo', this);
  116. if(this.videoCtx){
  117. this.videoCtx.stop();
  118. }
  119. console.log(e);
  120. let readId = e.target.dataset.id;
  121. let title = this.data.title;
  122. wx.navigateTo({
  123. url: `../../social/works/works?id=${readId}&title=${title}`
  124. })
  125. },
  126. collect: function (e) {
  127. // let uid = wx.getStorageSync('uid');
  128. let data = {
  129. targetCode: this.data.id,
  130. // title: this.data.title,
  131. // iconImg: this.data.iconImg
  132. }
  133. httpRequestApi.collectClass(this.uid, data).success(res => {
  134. this.setData({
  135. collectFlag: !this.data.collectFlag
  136. })
  137. })
  138. },
  139. getReadInfo: function (pageNo, pageSize) {
  140. // const uid = wx.getStorageSync('uid');
  141. const data = {
  142. lessonId: this.data.id,
  143. pageNo: this.data.pageNo,
  144. pageSize: 10
  145. };
  146. httpRequestApi.getClassRead(this.uid, data).success(res => {
  147. const readInfo = res.data.data.list;
  148. const readTemp = [];
  149. readInfo.forEach(item => {
  150. const temp = {};
  151. temp.nickName = item.user.wechatName;
  152. temp.time = formatDate(item.userRead.gmtModified, 3);
  153. temp.avatar = item.user.avatar;
  154. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  155. temp.uid = item.userRead.uid;
  156. temp.id = item.userRead.id;
  157. this.data.works.push(temp);
  158. });
  159. this.setData({
  160. totalNo: res.data.data.totalNo,
  161. total: res.data.data.totalSize,
  162. works: this.data.works
  163. })
  164. });
  165. },
  166. // 下拉加载
  167. onReachBottom: function (e) {
  168. console.log(this.data.totalNo);
  169. this.setData({
  170. pageNo: this.data.pageNo + 1
  171. })
  172. if (this.data.pageNo <= this.data.totalNo) {
  173. this.getReadInfo();
  174. }
  175. }
  176. })