mycollection.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import httpRequestApi from '../../utils/APIClient';
  2. import {
  3. formatDate
  4. } from '../../utils/util';
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. collection_data: [],
  11. line1: '您还没有收藏过哦',
  12. line2: '快去收藏自己喜欢的吧',
  13. videoList: [],
  14. commentShow: false,
  15. statusbarobj: {
  16. isshowbtn: false, //是否显示按钮
  17. title: "小学语文朗读配音", //标题
  18. },
  19. },
  20. toClass: function (e) {
  21. let targetCode = e.currentTarget.dataset.targetcode;
  22. let title = e.currentTarget.dataset.title;
  23. // wx.navigateTo({
  24. // url: `../../main/class/class?id=${targetCode}&title=${title}`
  25. // });
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (option) {
  31. console.log(option.title);
  32. if (option.title) {
  33. wx.setNavigationBarTitle({
  34. title: '我的收藏' //页面标题为路由参数
  35. });
  36. this.setData({
  37. title: option.title
  38. });
  39. }
  40. httpRequestApi.myFavorites().success(res => {
  41. this.formatWorksList(res.data.data.list)
  42. });
  43. },
  44. formatWorksList(list) {
  45. list.forEach(item => {
  46. const temp = {};
  47. temp.title = item.userRead.title;
  48. temp.summary = item.userRead.summary;
  49. temp.img = item.userRead.iconImg;
  50. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  51. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  52. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  53. temp.shareAmount = item.userRead.shareAmount;
  54. temp.favoritesAmount = item.userRead.favoritesAmount;
  55. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  56. temp.time = formatDate(item.userRead.gmtCreated, 3);
  57. temp.avatar = item.user.avatar;
  58. temp.profession = item.user.profession;
  59. temp.uid = item.user.uid;
  60. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  61. temp.id = item.userRead.id;
  62. temp.type = item.userRead.type;
  63. temp.nickName = item.user.wechatName;
  64. temp.isLike = item.isLike;
  65. temp.isFans = true;
  66. temp.isFavorite = true;
  67. temp.coverImg = item.userRead.coverImg;
  68. temp.shareImg = item.userRead.shareImg;
  69. temp.grade = item.userRead.grade;
  70. temp.videoShow = false;
  71. item.isActivity && (temp.activity = true);
  72. this.data.videoList.push(temp);
  73. });
  74. this.setData({
  75. videoList: this.data.videoList
  76. }, () => {
  77. console.log(this.data.videoList)
  78. })
  79. },
  80. goToReading: function (e) {
  81. console.log('去朗读', e)
  82. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  83. wx.navigateTo({
  84. url: `../../pages/reading/reading?id=${id}`
  85. });
  86. },
  87. // 评论区点击
  88. commentTap: function (e) {
  89. console.log('点击评论区', e)
  90. if (e.target.dataset.type === 'blank') {
  91. if (this.data.commentShow && this.data.commentId) {
  92. httpRequestApi.getClassDetail(this.data.commentId).success(res => {
  93. console.log('评论回显', res.data.data.userRead.commentAmount)
  94. let str = `videoList[${this.data.commentIndex}].commentAmount`;
  95. this.setData({
  96. [str]: res.data.data.userRead.commentAmount
  97. })
  98. })
  99. }
  100. this.setData({
  101. commentShow: false
  102. })
  103. }
  104. },
  105. // 打开评论
  106. openComment: function (e) {
  107. //
  108. console.log('id', e.detail.activeId)
  109. this.setData({
  110. commentShow: !this.data.commentShow,
  111. commentId: e.detail.activeId,
  112. commentIndex: e.detail.activeIndex
  113. // commentList: []
  114. });
  115. // this.getReply(e.detail.activeId);
  116. },
  117. // 发布回复
  118. sendReply: function (e) {
  119. console.log('triger', e.detail.content);
  120. let data = {
  121. columnId: this.data.commentId,
  122. colunmNames: 'what',
  123. detailDesc: e.detail.content,
  124. // productId: this.data.productId
  125. }
  126. httpRequestApi.postReply(this.uid, data).success(res => {
  127. console.log(res)
  128. this.setData({
  129. pageNo: 1,
  130. commentList: []
  131. }, () => {
  132. this.getReply(this.data.commentId);
  133. })
  134. });
  135. },
  136. commentTouchMove: function (e) {
  137. return;
  138. },
  139. /**
  140. * 生命周期函数--监听页面初次渲染完成
  141. */
  142. onReady: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面显示
  146. */
  147. onShow: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面隐藏
  151. */
  152. onHide: function () {
  153. },
  154. /**
  155. * 生命周期函数--监听页面卸载
  156. */
  157. onUnload: function () {
  158. },
  159. /**
  160. * 页面相关事件处理函数--监听用户下拉动作
  161. */
  162. onPullDownRefresh: function () {
  163. },
  164. /**
  165. * 页面上拉触底事件的处理函数
  166. */
  167. onReachBottom: function () {
  168. },
  169. collectTap: function (e) {
  170. const index = e.detail.index;
  171. let str = `videoList[${index}].isFavorite`;
  172. let str2 = `videoList[${index}].favoritesAmount`;
  173. let favoritesAmount = e.detail.isCollect ? this.data.videoList[index].favoritesAmount + 1 : this.data.videoList[index].favoritesAmount - 1
  174. this.setData({
  175. [str]: e.detail.isCollect,
  176. [str2]: favoritesAmount
  177. })
  178. },
  179. likeTap: function (e) {
  180. console.log('点赞', e)
  181. const index = e.detail.index;
  182. let likeStr = `videoList[${index}].isLike`;
  183. let likeNumStr = `videoList[${index}].likes`;
  184. this.setData({
  185. [likeStr]: true,
  186. [likeNumStr]: this.data.videoList[index].likes + 1
  187. })
  188. },
  189. openShare: function (e) {
  190. console.log('用户点击分享按钮', e)
  191. this.setData({
  192. shareTitle: e.detail.currentTarget.dataset.title,
  193. shareId: e.detail.currentTarget.dataset.id,
  194. shareImg: e.detail.currentTarget.dataset.shareimg,
  195. ifTapActivity: e.detail.currentTarget.dataset.activity
  196. })
  197. },
  198. /**
  199. * 用户点击右上角分享
  200. */
  201. onShareAppMessage: function (res) {
  202. console.log('用户点分享', res)
  203. if (res.from === 'button') {
  204. return {
  205. title: '请欣赏我的课文朗读作品,点赞+评论。',
  206. path: `/pages/index/index?readId=${this.data.shareId}&activity=${this.data.ifTapActivity}`,
  207. imageUrl: this.data.shareImg
  208. }
  209. } else {
  210. return {
  211. title: '课文朗读,从未如此有趣。',
  212. path: '/pages/index/index',
  213. }
  214. }
  215. },
  216. addShareAmount: function (e) {
  217. console.log('+++++1', e)
  218. let str = `videoList[${e.detail.index}].shareAmount`;
  219. this.setData({
  220. [str]: this.data.videoList[e.detail.index].shareAmount + 1
  221. })
  222. }
  223. })