myworks.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // pages/user/myworks/myworks.js
  2. import APIClient from '../../../utils/APIClient.js'
  3. import { formatDate } from '../../../utils/util.js'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. wareCards: {},
  10. pageNo: 1,
  11. totalNo: 0,
  12. uid: '',
  13. worksList: [],
  14. isFans: false,
  15. isMyself: false,
  16. },
  17. toMyWorks: function(e){
  18. let id = e.currentTarget.dataset.id;
  19. let title = e.currentTarget.dataset.title;
  20. wx.navigateTo({
  21. url: `../../social/works/works?id=${id}&title=${title}`
  22. });
  23. },
  24. // 关注用户
  25. follow: function () {
  26. let followUid = this.data.uid;
  27. const uid = wx.getStorageSync('uid');
  28. if (this.data.isFans) {
  29. APIClient.cancerFollow(uid, followUid).success((res) => {
  30. this.setData({
  31. isFans: false
  32. })
  33. wx.showToast({
  34. title: '取消关注',
  35. icon: 'success',
  36. duration: 1000
  37. })
  38. });
  39. } else {
  40. APIClient.followUser(uid, followUid).success((res) => {
  41. this.setData({
  42. isFans: true
  43. })
  44. wx.showToast({
  45. title: '关注啦',
  46. icon: 'success',
  47. duration: 1000
  48. })
  49. });
  50. }
  51. },
  52. getResults(){
  53. let pageNo = this.data.pageNo;
  54. let pageSize = 3;
  55. let uid = this.data.uid;
  56. console.log('用户身份',uid);
  57. APIClient.getUserMsg(uid, pageNo, pageSize).success(res => {
  58. console.log(res)
  59. res.data.data.user.birthday = formatDate(res.data.data.user.birthday,4)
  60. this.setData({
  61. wareCards: res.data.data,
  62. isFans: res.data.data.like
  63. });
  64. console.log(this.data.wareCards)
  65. // wx.hideToast();
  66. }).fail(err => {
  67. console.log(err);
  68. });
  69. APIClient.userWorks(uid, pageNo, pageSize).success(res => {
  70. console.log(res)
  71. this.setData({
  72. worksList: this.data.worksList.concat(res.data.data.list),
  73. totalNo: res.data.data.totalNo
  74. });
  75. // wx.hideToast();
  76. }).fail(err => {
  77. console.log(err);
  78. });
  79. },
  80. /**
  81. * 生命周期函数--监听页面加载
  82. */
  83. onLoad: function (options) {
  84. if(options.uid === wx.getStorageSync('uid') || options.uid === 'c7f0a8fdd3a549ea9109a7b7486775f2'){
  85. this.setData({
  86. isMyself: true
  87. })
  88. }
  89. this.setData({
  90. uid: options.uid
  91. },() => {
  92. console.log(options.uid);
  93. });
  94. // wx.showToast({
  95. // title: '加载中...',
  96. // icon: 'loading'
  97. // });
  98. this.getResults();
  99. },
  100. /**
  101. * 生命周期函数--监听页面初次渲染完成
  102. */
  103. onReady: function () {
  104. },
  105. /**
  106. * 生命周期函数--监听页面显示
  107. */
  108. onShow: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面隐藏
  112. */
  113. onHide: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面卸载
  117. */
  118. onUnload: function () {
  119. },
  120. /**
  121. * 页面相关事件处理函数--监听用户下拉动作
  122. */
  123. onPullDownRefresh: function () {
  124. },
  125. /**
  126. * 页面上拉触底事件的处理函数
  127. */
  128. onReachBottom: function () {
  129. this.setData({
  130. pageNo: this.data.pageNo + 1
  131. })
  132. if (this.data.pageNo <= this.data.totalNo) {
  133. this.getResults();
  134. }
  135. },
  136. /**
  137. * 用户点击右上角分享
  138. */
  139. onShareAppMessage: function () {
  140. }
  141. })