class.js 5.4 KB

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