myworks.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. res.data.data.user.birthday = formatDate(res.data.data.user.birthday,4)
  59. this.setData({
  60. wareCards: res.data.data,
  61. isFans: res.data.data.like
  62. });
  63. console.log(this.data.wareCards)
  64. // wx.hideToast();
  65. }).fail(err => {
  66. console.log(err);
  67. });
  68. APIClient.userWorks(uid, pageNo, pageSize).success(res => {
  69. this.setData({
  70. worksList: this.data.worksList.concat(res.data.data.list),
  71. totalNo: res.data.data.totalNo
  72. });
  73. // wx.hideToast();
  74. }).fail(err => {
  75. console.log(err);
  76. });
  77. },
  78. /**
  79. * 生命周期函数--监听页面加载
  80. */
  81. onLoad: function (options) {
  82. if(options.uid === wx.getStorageSync('uid') || options.uid === 'c7f0a8fdd3a549ea9109a7b7486775f2'){
  83. this.setData({
  84. isMyself: true
  85. })
  86. }
  87. this.setData({
  88. uid: options.uid
  89. },() => {
  90. console.log(options.uid);
  91. });
  92. // wx.showToast({
  93. // title: '加载中...',
  94. // icon: 'loading'
  95. // });
  96. this.getResults();
  97. },
  98. /**
  99. * 生命周期函数--监听页面初次渲染完成
  100. */
  101. onReady: function () {
  102. },
  103. /**
  104. * 生命周期函数--监听页面显示
  105. */
  106. onShow: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面隐藏
  110. */
  111. onHide: function () {
  112. },
  113. /**
  114. * 生命周期函数--监听页面卸载
  115. */
  116. onUnload: function () {
  117. },
  118. /**
  119. * 页面相关事件处理函数--监听用户下拉动作
  120. */
  121. onPullDownRefresh: function () {
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom: function () {
  127. this.setData({
  128. pageNo: this.data.pageNo + 1
  129. })
  130. if (this.data.pageNo <= this.data.totalNo) {
  131. this.getResults();
  132. }
  133. },
  134. /**
  135. * 用户点击右上角分享
  136. */
  137. onShareAppMessage: function () {
  138. }
  139. })