myworks.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. if (this.data.isFans) {
  28. APIClient.cancerFollow(this.uid, followUid).success((res) => {
  29. this.setData({
  30. isFans: false
  31. })
  32. wx.showToast({
  33. title: '取消关注',
  34. icon: 'success',
  35. duration: 1000
  36. })
  37. });
  38. } else {
  39. APIClient.followUser(this.uid, followUid).success((res) => {
  40. this.setData({
  41. isFans: true
  42. })
  43. wx.showToast({
  44. title: '关注啦',
  45. icon: 'success',
  46. duration: 1000
  47. })
  48. });
  49. }
  50. },
  51. getResults(){
  52. let pageNo = this.data.pageNo;
  53. let pageSize = 3;
  54. let uid = this.data.uid;
  55. console.log('用户身份',uid);
  56. APIClient.getUserMsg(uid, pageNo, pageSize).success(res => {
  57. res.data.data.user.birthday = formatDate(res.data.data.user.birthday,4)
  58. this.setData({
  59. wareCards: res.data.data,
  60. isFans: res.data.data.like
  61. });
  62. console.log(this.data.wareCards)
  63. // wx.hideToast();
  64. }).fail(err => {
  65. console.log(err);
  66. });
  67. APIClient.userWorks(uid, pageNo, pageSize).success(res => {
  68. this.setData({
  69. worksList: this.data.worksList.concat(res.data.data.list),
  70. totalNo: res.data.data.totalNo
  71. });
  72. // wx.hideToast();
  73. }).fail(err => {
  74. console.log(err);
  75. });
  76. },
  77. /**
  78. * 生命周期函数--监听页面加载
  79. */
  80. onLoad: function (options) {
  81. if(options.uid === wx.getStorageSync('uid')){
  82. this.setData({
  83. isMyself: true
  84. })
  85. }
  86. this.setData({
  87. uid: options.uid
  88. },() => {
  89. console.log(options.uid);
  90. });
  91. // wx.showToast({
  92. // title: '加载中...',
  93. // icon: 'loading'
  94. // });
  95. this.getResults();
  96. },
  97. /**
  98. * 生命周期函数--监听页面初次渲染完成
  99. */
  100. onReady: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面显示
  104. */
  105. onShow: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面隐藏
  109. */
  110. onHide: function () {
  111. },
  112. /**
  113. * 生命周期函数--监听页面卸载
  114. */
  115. onUnload: function () {
  116. },
  117. /**
  118. * 页面相关事件处理函数--监听用户下拉动作
  119. */
  120. onPullDownRefresh: function () {
  121. },
  122. /**
  123. * 页面上拉触底事件的处理函数
  124. */
  125. onReachBottom: function () {
  126. this.setData({
  127. pageNo: this.data.pageNo + 1
  128. })
  129. if (this.data.pageNo <= this.data.totalNo) {
  130. this.getResults();
  131. }
  132. },
  133. /**
  134. * 用户点击右上角分享
  135. */
  136. onShareAppMessage: function () {
  137. }
  138. })