class.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. console.log(this.data.works)
  109. // this.videoCtx = wx.createVideoContext('myVideo', this);
  110. if(this.videoCtx){
  111. this.videoCtx.stop();
  112. }
  113. console.log(e);
  114. let readId = e.target.dataset.id;
  115. let title = this.data.title;
  116. wx.navigateTo({
  117. url: `../../social/works/works?id=${readId}&title=${title}`
  118. })
  119. },
  120. collect: function (e) {
  121. // let uid = wx.getStorageSync('uid');
  122. let data = {
  123. targetCode: this.data.id,
  124. title: this.data.title,
  125. iconImg: this.data.iconImg
  126. }
  127. httpRequestApi.collectClass(this.uid, data).success(res => {
  128. this.setData({
  129. collectFlag: !this.data.collectFlag
  130. })
  131. })
  132. },
  133. getReadInfo: function (pageNo, pageSize) {
  134. // const uid = wx.getStorageSync('uid');
  135. const data = {
  136. lessonId: this.data.id,
  137. pageNo: this.data.pageNo,
  138. pageSize: 10
  139. };
  140. httpRequestApi.getClassRead(this.uid, data).success(res => {
  141. const readInfo = res.data.data.list;
  142. const readTemp = [];
  143. readInfo.forEach(item => {
  144. const temp = {};
  145. temp.nickName = item.user.wechatName;
  146. temp.time = formatDate(item.userRead.gmtModified, 3);
  147. temp.avatar = item.user.avatar;
  148. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  149. temp.uid = item.userRead.uid;
  150. temp.id = item.userRead.id;
  151. this.data.works.push(temp);
  152. });
  153. this.setData({
  154. totalNo: res.data.data.totalNo,
  155. total: res.data.data.totalSize,
  156. works: this.data.works
  157. })
  158. });
  159. },
  160. // 下拉加载
  161. onReachBottom: function (e) {
  162. console.log(this.data.totalNo);
  163. this.setData({
  164. pageNo: this.data.pageNo + 1
  165. })
  166. if (this.data.pageNo <= this.data.totalNo) {
  167. this.getReadInfo();
  168. }
  169. }
  170. })