class.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. wx.setNavigationBarTitle({
  24. title: option.title //页面标题为路由参数
  25. })
  26. this.setData({
  27. title: option.title,
  28. id: option.id
  29. })
  30. this.uid = wx.getStorageSync('uid');;
  31. httpRequestApi.getClassDetail(this.uid, option.id).success(res => {
  32. console.log(res);
  33. this.setData({
  34. title: res.data.data.title,
  35. videoUrl: res.data.data.playUrl,
  36. iconImg: res.data.data.iconImg
  37. })
  38. this.getReadInfo(1, 10);
  39. this.checkLike();
  40. })
  41. },
  42. // 检查是否收藏
  43. checkLike: function () {
  44. httpRequestApi.classIsLike(this.uid, {
  45. targetCode: this.data.id
  46. }).success(res => {
  47. this.setData({
  48. collectFlag: res.data.data
  49. })
  50. })
  51. },
  52. goToReading: function () {
  53. let id = this.data.id;
  54. let title = this.data.title;
  55. wx.navigateTo({
  56. url: `../../main/reading/reading?id=${id}`
  57. })
  58. },
  59. openShare: function (e) {
  60. // this.setData({
  61. // shareFlag: !this.data.shareFlag
  62. // })
  63. this.shareDialog = this.selectComponent("#share-dialog");
  64. const data = {
  65. avatar: this.data.authorAvatar,
  66. author: this.data.author,
  67. iconImg: this.data.iconImg,
  68. title: this.data.title,
  69. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}`
  70. // tip: this.data.tip,
  71. }
  72. this.shareDialog.share(data);
  73. },
  74. onShareAppMessage: function (res) {
  75. if (res.from === 'button') {
  76. // 来自页面内转发按钮
  77. console.log(res.target)
  78. }
  79. return {
  80. title: this.data.title,
  81. path: `pages/main/class/class?id=${this.data.id}&title=${this.data.title}`,
  82. imageUrl: this.data.iconImg
  83. }
  84. },
  85. goToWorks: function (e) {
  86. this.videoCtx = wx.createVideoContext('myVideo', this);
  87. this.videoCtx.stop();
  88. console.log(e);
  89. let readId = e.target.dataset.uid;
  90. let title = this.data.title;
  91. wx.navigateTo({
  92. url: `../../social/works/works?id=${readId}&tilte=${title}`
  93. })
  94. },
  95. collect: function (e) {
  96. // let uid = wx.getStorageSync('uid');
  97. let data = {
  98. targetCode: this.data.id,
  99. title: this.data.title,
  100. iconImg: this.data.iconImg
  101. }
  102. httpRequestApi.collectClass(this.uid, data).success(res => {
  103. this.setData({
  104. collectFlag: !this.data.collectFlag
  105. })
  106. })
  107. },
  108. getReadInfo: function (pageNo, pageSize) {
  109. // const uid = wx.getStorageSync('uid');
  110. const data = {
  111. lessonId: this.data.id,
  112. pageNo: this.data.pageNo,
  113. pageSize: 1
  114. };
  115. httpRequestApi.getClassRead(this.uid, data).success(res => {
  116. const readInfo = res.data.data.list;
  117. const readTemp = [];
  118. readInfo.forEach(item => {
  119. const temp = {};
  120. temp.nickName = item.user.wechatName;
  121. temp.time = formatDate(item.userRead.gmtModified, 3);
  122. temp.avatar = item.user.avatar;
  123. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  124. temp.uid = item.userRead.uid;
  125. temp.id = item.userRead.id;
  126. this.data.works.push(temp);
  127. });
  128. this.setData({
  129. totalNo: res.data.data.totalNo,
  130. total: res.data.data.totalSize,
  131. works: this.data.works
  132. })
  133. });
  134. },
  135. // 下拉加载
  136. onReachBottom: function (e) {
  137. console.log(this.data.totalNo);
  138. this.setData({
  139. pageNo: this.data.pageNo + 1
  140. })
  141. if (this.data.pageNo <= this.data.totalNo) {
  142. this.getReadInfo();
  143. }
  144. }
  145. })