index.js 2.5 KB

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