myworks.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // pages/user/myworks/myworks.js
  2. import APIClient from '../../../utils/APIClient.js'
  3. import {
  4. formatDate
  5. } from '../../../utils/util.js'
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. wareCards: {},
  12. pageNo: 1,
  13. totalNo: 0,
  14. uid: '',
  15. videoList: [],
  16. isFans: false,
  17. isMyself: false,
  18. commentId: '',
  19. },
  20. // 打开评论
  21. openComment: function (e) {
  22. console.log('id', e.detail.activeId)
  23. this.setData({
  24. commentShow: !this.data.commentShow,
  25. commentId: e.detail.activeId,
  26. });
  27. },
  28. toMyWorks: function (e) {
  29. let id = e.currentTarget.dataset.readid;
  30. let title = e.currentTarget.dataset.title;
  31. wx.navigateTo({
  32. url: `../../social/works/works?id=${id}&title=${title}`
  33. });
  34. },
  35. // 关注用户
  36. follow: function () {
  37. let followUid = this.data.uid;
  38. const uid = wx.getStorageSync('uid');
  39. if (this.data.isFans) {
  40. APIClient.cancerFollow(uid, followUid).success((res) => {
  41. this.setData({
  42. isFans: false
  43. })
  44. wx.showToast({
  45. title: '取消关注',
  46. icon: 'success',
  47. duration: 1000
  48. })
  49. });
  50. } else {
  51. APIClient.followUser(uid, followUid).success((res) => {
  52. this.setData({
  53. isFans: true
  54. })
  55. wx.showToast({
  56. title: '关注啦',
  57. icon: 'success',
  58. duration: 1000
  59. })
  60. });
  61. }
  62. },
  63. getResults() {
  64. let pageNo = this.data.pageNo;
  65. let pageSize = 3;
  66. let uid = this.data.uid;
  67. console.log('用户身份', uid);
  68. APIClient.getUserMsg(uid, pageNo, pageSize).success(res => {
  69. console.log(res)
  70. res.data.data.user.birthday = formatDate(res.data.data.user.birthday, 4)
  71. this.setData({
  72. wareCards: res.data.data,
  73. isFans: res.data.data.like
  74. });
  75. console.log(this.data.wareCards)
  76. // wx.hideToast();
  77. this.getUserWorks(uid, pageNo, pageSize)
  78. }).fail(err => {
  79. console.log(err);
  80. });
  81. },
  82. getUserWorks(uid, pageNo, pageSize) {
  83. APIClient.userWorks(uid, pageNo, pageSize).success(res => {
  84. console.log(res)
  85. const recommendRes = res.data.data.list;
  86. if (recommendRes.length === 0) return;
  87. recommendRes.forEach(item => {
  88. const temp = {};
  89. temp.title = item.userRead.title;
  90. temp.summary = item.userRead.summary;
  91. temp.img = item.userRead.iconImg;
  92. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  93. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  94. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  95. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  96. temp.time = formatDate(item.userRead.gmtCreated, 3);
  97. temp.avatar = item.user.avatar;
  98. temp.profession = item.user.profession;
  99. temp.uid = item.user.uid;
  100. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  101. temp.id = item.userRead.id;
  102. temp.type = item.userRead.type;
  103. // temp.avatar = item.user.avatar;
  104. temp.nickName = item.user.wechatName;
  105. temp.isLike = item.isLike;
  106. temp.isFavorite = item.isFavorites;
  107. // recommendWorks.push(temp);
  108. this.data.videoList.push(temp);
  109. });
  110. this.setData({
  111. videoList: this.data.videoList
  112. })
  113. console.log('dangqian', this.data.videoList)
  114. })
  115. },
  116. /**
  117. * 生命周期函数--监听页面加载
  118. */
  119. onLoad: function (options) {
  120. if (options.uid === wx.getStorageSync('uid') || options.uid === 'c7f0a8fdd3a549ea9109a7b7486775f2') {
  121. this.setData({
  122. isMyself: true
  123. })
  124. }
  125. this.setData({
  126. uid: options.uid
  127. }, () => {
  128. console.log(options.uid);
  129. });
  130. // wx.showToast({
  131. // title: '加载中...',
  132. // icon: 'loading'
  133. // });
  134. this.getResults();
  135. },
  136. /**
  137. * 生命周期函数--监听页面初次渲染完成
  138. */
  139. onReady: function () {
  140. },
  141. /**
  142. * 生命周期函数--监听页面显示
  143. */
  144. onShow: function () {
  145. },
  146. /**
  147. * 生命周期函数--监听页面隐藏
  148. */
  149. onHide: function () {
  150. },
  151. /**
  152. * 生命周期函数--监听页面卸载
  153. */
  154. onUnload: function () {
  155. },
  156. /**
  157. * 页面相关事件处理函数--监听用户下拉动作
  158. */
  159. onPullDownRefresh: function () {
  160. },
  161. /**
  162. * 页面上拉触底事件的处理函数
  163. */
  164. onReachBottom: function () {
  165. this.setData({
  166. pageNo: this.data.pageNo + 1
  167. })
  168. if (this.data.pageNo <= this.data.totalNo) {
  169. this.getResults();
  170. }
  171. },
  172. /**
  173. * 用户点击右上角分享
  174. */
  175. onShareAppMessage: function () {
  176. }
  177. })