class.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 id = this.data.id;
  55. let title = this.data.title;
  56. wx.navigateTo({
  57. url: `../../main/reading/reading?id=${id}`
  58. })
  59. },
  60. openShare: function (e) {
  61. // this.setData({
  62. // shareFlag: !this.data.shareFlag
  63. // })
  64. this.shareDialog = this.selectComponent("#share-dialog");
  65. const data = {
  66. avatar: this.data.authorAvatar,
  67. author: this.data.author,
  68. iconImg: this.data.iconImg,
  69. title: this.data.title,
  70. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}`
  71. // tip: this.data.tip,
  72. }
  73. this.shareDialog.share(data);
  74. },
  75. onShareAppMessage: function (res) {
  76. if (res.from === 'button') {
  77. // 来自页面内转发按钮
  78. console.log(res.target)
  79. }
  80. return {
  81. title: this.data.title,
  82. path: `pages/main/class/class?id=${this.data.id}&title=${this.data.title}`,
  83. imageUrl: this.data.iconImg
  84. }
  85. },
  86. goToWorks: function (e) {
  87. this.videoCtx = wx.createVideoContext('myVideo', this);
  88. this.videoCtx.stop();
  89. console.log(e);
  90. let readId = e.target.dataset.uid;
  91. let title = this.data.title;
  92. wx.navigateTo({
  93. url: `../../social/works/works?id=${readId}&tilte=${title}`
  94. })
  95. },
  96. collect: function (e) {
  97. // let uid = wx.getStorageSync('uid');
  98. let data = {
  99. targetCode: this.data.id,
  100. title: this.data.title,
  101. iconImg: this.data.iconImg
  102. }
  103. httpRequestApi.collectClass(this.uid, data).success(res => {
  104. this.setData({
  105. collectFlag: !this.data.collectFlag
  106. })
  107. })
  108. },
  109. getReadInfo: function (pageNo, pageSize) {
  110. // const uid = wx.getStorageSync('uid');
  111. const data = {
  112. lessonId: this.data.id,
  113. pageNo: this.data.pageNo,
  114. pageSize: 1
  115. };
  116. httpRequestApi.getClassRead(this.uid, data).success(res => {
  117. const readInfo = res.data.data.list;
  118. const readTemp = [];
  119. readInfo.forEach(item => {
  120. const temp = {};
  121. temp.nickName = item.user.wechatName;
  122. temp.time = formatDate(item.userRead.gmtModified, 3);
  123. temp.avatar = item.user.avatar;
  124. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  125. temp.uid = item.userRead.uid;
  126. temp.id = item.userRead.id;
  127. this.data.works.push(temp);
  128. });
  129. this.setData({
  130. totalNo: res.data.data.totalNo,
  131. total: res.data.data.totalSize,
  132. works: this.data.works
  133. })
  134. });
  135. },
  136. // 下拉加载
  137. onReachBottom: function (e) {
  138. console.log(this.data.totalNo);
  139. this.setData({
  140. pageNo: this.data.pageNo + 1
  141. })
  142. if (this.data.pageNo <= this.data.totalNo) {
  143. this.getReadInfo();
  144. }
  145. }
  146. })