index.js 2.5 KB

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