mycollection.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. this.data.videoList.push(temp);
  72. });
  73. this.setData({
  74. videoList: this.data.videoList
  75. }, () => {
  76. console.log(this.data.videoList)
  77. })
  78. },
  79. goToReading: function (e) {
  80. console.log('去朗读', e)
  81. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  82. wx.navigateTo({
  83. url: `../../pages/reading/reading?id=${id}`
  84. });
  85. },
  86. // 评论区点击
  87. commentTap: function (e) {
  88. console.log('点击评论区', e)
  89. if (e.target.dataset.type === 'blank') {
  90. if (this.data.commentShow && this.data.commentId) {
  91. httpRequestApi.getClassDetail(this.data.commentId).success(res => {
  92. console.log('评论回显', res.data.data.userRead.commentAmount)
  93. let str = `videoList[${this.data.commentIndex}].commentAmount`;
  94. this.setData({
  95. [str]: res.data.data.userRead.commentAmount
  96. })
  97. })
  98. }
  99. this.setData({
  100. commentShow: false
  101. })
  102. }
  103. },
  104. // 打开评论
  105. openComment: function (e) {
  106. //
  107. console.log('id', e.detail.activeId)
  108. this.setData({
  109. commentShow: !this.data.commentShow,
  110. commentId: e.detail.activeId,
  111. commentIndex: e.detail.activeIndex
  112. // commentList: []
  113. });
  114. // this.getReply(e.detail.activeId);
  115. },
  116. // 发布回复
  117. sendReply: function (e) {
  118. console.log('triger', e.detail.content);
  119. let data = {
  120. columnId: this.data.commentId,
  121. colunmNames: 'what',
  122. detailDesc: e.detail.content,
  123. // productId: this.data.productId
  124. }
  125. httpRequestApi.postReply(this.uid, data).success(res => {
  126. console.log(res)
  127. this.setData({
  128. pageNo: 1,
  129. commentList: []
  130. }, () => {
  131. this.getReply(this.data.commentId);
  132. })
  133. });
  134. },
  135. commentTouchMove: function (e) {
  136. return;
  137. },
  138. /**
  139. * 生命周期函数--监听页面初次渲染完成
  140. */
  141. onReady: function () {
  142. },
  143. /**
  144. * 生命周期函数--监听页面显示
  145. */
  146. onShow: function () {
  147. },
  148. /**
  149. * 生命周期函数--监听页面隐藏
  150. */
  151. onHide: function () {
  152. },
  153. /**
  154. * 生命周期函数--监听页面卸载
  155. */
  156. onUnload: function () {
  157. },
  158. /**
  159. * 页面相关事件处理函数--监听用户下拉动作
  160. */
  161. onPullDownRefresh: function () {
  162. },
  163. /**
  164. * 页面上拉触底事件的处理函数
  165. */
  166. onReachBottom: function () {
  167. },
  168. collectTap: function (e) {
  169. const index = e.detail.index;
  170. let str = `videoList[${index}].isFavorite`;
  171. let str2 = `videoList[${index}].favoritesAmount`;
  172. let favoritesAmount = e.detail.isCollect ? this.data.videoList[index].favoritesAmount + 1 : this.data.videoList[index].favoritesAmount - 1
  173. this.setData({
  174. [str]: e.detail.isCollect,
  175. [str2]: favoritesAmount
  176. })
  177. },
  178. likeTap: function (e) {
  179. console.log('点赞', e)
  180. const index = e.detail.index;
  181. let likeStr = `videoList[${index}].isLike`;
  182. let likeNumStr = `videoList[${index}].likes`;
  183. this.setData({
  184. [likeStr]: true,
  185. [likeNumStr]: this.data.videoList[index].likes + 1
  186. })
  187. },
  188. openShare: function (e) {
  189. console.log('用户点击分享按钮', e)
  190. this.setData({
  191. shareTitle: e.detail.currentTarget.dataset.title,
  192. shareId: e.detail.currentTarget.dataset.id,
  193. shareImg: e.detail.currentTarget.dataset.shareimg
  194. })
  195. },
  196. /**
  197. * 用户点击右上角分享
  198. */
  199. onShareAppMessage: function (res) {
  200. console.log('用户点分享', res)
  201. if (res.from === 'button') {
  202. return {
  203. title: '请欣赏我的课文朗读作品,点赞+评论。',
  204. path: `/pages/index/index?readId=${this.data.shareId}`,
  205. imageUrl: this.data.shareImg
  206. }
  207. } else {
  208. return {
  209. title: '课文朗读,从未如此有趣。',
  210. path: '/pages/index/index',
  211. }
  212. }
  213. },
  214. addShareAmount: function (e) {
  215. console.log('+++++1', e)
  216. let str = `videoList[${e.detail.index}].shareAmount`;
  217. this.setData({
  218. [str]: this.data.videoList[e.detail.index].shareAmount + 1
  219. })
  220. }
  221. })