class.js 4.6 KB

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