index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import {
  2. getFansList,
  3. getMyInfo,
  4. setFans
  5. } from '~/api/user'
  6. import event from '~/mixins/event'
  7. import reachBottom from '~/mixins/reachBottom'
  8. Page({
  9. behaviors: [reachBottom,event],
  10. data: {
  11. // 1我的关注;2我的粉丝
  12. currentType: 1,
  13. c1: 0,
  14. c2: 0,
  15. userInfo: {},
  16. localUid: wx.getStorageSync('uid')
  17. },
  18. async onShow() {
  19. this.resetData()
  20. let c1 = await getFansList({
  21. pageSize: 1,
  22. type: 1
  23. })
  24. let c2 = await getFansList({
  25. pageSize: 1,
  26. type: 2
  27. })
  28. let userInfo = await getMyInfo()
  29. this.setData({
  30. c1: c1.totalSize,
  31. c2: c2.totalSize,
  32. userInfo
  33. })
  34. },
  35. setType({
  36. currentTarget
  37. }) {
  38. this.setData({
  39. currentType: currentTarget.dataset.type
  40. })
  41. this.resetData()
  42. },
  43. // 获取分类的内容
  44. loadMore() {
  45. let type = this.data.currentType
  46. this.getData(getFansList, {
  47. pageSize: 20,
  48. type
  49. })
  50. },
  51. jumpUserInfo({
  52. currentTarget
  53. }) {
  54. let uid = currentTarget.dataset.uid
  55. wx.navigateTo({
  56. url: `/pages/personal/index?uid=${uid}`,
  57. })
  58. },
  59. async setFans({
  60. currentTarget
  61. }) {
  62. if (this.data.currentType == '1') {
  63. this.jumpUserInfo({
  64. currentTarget
  65. })
  66. } else {
  67. if (currentTarget.dataset.iseachother) {
  68. this.jumpUserInfo({
  69. currentTarget
  70. })
  71. } else {
  72. await setFans({
  73. uid: currentTarget.dataset.uid
  74. })
  75. let listCopy = JSON.parse(JSON.stringify(this.data.list))
  76. listCopy.forEach(item => {
  77. if (item.user.uid == currentTarget.dataset.uid) {
  78. item.isEachOther = true
  79. }
  80. })
  81. this.setData({
  82. list: listCopy
  83. })
  84. wx.showToast({
  85. title: '已关注',
  86. icon: 'none'
  87. })
  88. }
  89. }
  90. },
  91. searchFriend() {
  92. wx.navigateTo({
  93. url: '/pages/searchFriend/index',
  94. })
  95. },
  96. clipboar({
  97. currentTarget
  98. }) {
  99. wx.setClipboardData({
  100. data: currentTarget.dataset.eid,
  101. success: function (res) { //成功回调函数
  102. wx.showToast({
  103. title: '已复制',
  104. icon: "none"
  105. })
  106. }
  107. })
  108. },
  109. sendMsg({
  110. currentTarget
  111. }) {
  112. let user = currentTarget.dataset.user
  113. let {
  114. nickName,
  115. eid,
  116. uid
  117. } = user
  118. if (this.data.localUid == uid) {
  119. return wx.showToast({
  120. title: '不可以给自己发私信哦~',
  121. icon: 'none'
  122. })
  123. }
  124. wx.navigateTo({
  125. url: `/pages/chat/index?title=${nickName||eid}&uid=${uid}`,
  126. })
  127. },
  128. onReachBottom() {
  129. this.loadMore()
  130. },
  131. })