index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. },
  14. async onShow() {
  15. this.resetData()
  16. let c1 = await getFansList({
  17. pageSize: 1,
  18. type: 1
  19. })
  20. let c2 = await getFansList({
  21. pageSize: 1,
  22. type: 2
  23. })
  24. this.setData({
  25. c1: c1.totalSize,
  26. c2: c2.totalSize
  27. })
  28. },
  29. setType({
  30. currentTarget
  31. }) {
  32. this.setData({
  33. currentType: currentTarget.dataset.type
  34. })
  35. this.resetData()
  36. },
  37. // 获取分类的内容
  38. loadMore() {
  39. let type = this.data.currentType
  40. this.getData(getFansList, {
  41. pageSize: 20,
  42. type
  43. })
  44. },
  45. jumpUserInfo({
  46. currentTarget
  47. }) {
  48. let uid = currentTarget.dataset.uid
  49. wx.navigateTo({
  50. url: `/pages/personal/index?uid=${uid}`,
  51. })
  52. },
  53. async setFans({
  54. currentTarget
  55. }) {
  56. if (this.data.currentType == '1') {
  57. this.jumpUserInfo({
  58. currentTarget
  59. })
  60. } else {
  61. if (currentTarget.dataset.iseachother) {
  62. this.jumpUserInfo({
  63. currentTarget
  64. })
  65. } else {
  66. await setFans({
  67. uid: currentTarget.dataset.uid
  68. })
  69. let listCopy = JSON.parse(JSON.stringify(this.data.list))
  70. listCopy.forEach(item => {
  71. if (item.user.uid == currentTarget.dataset.uid) {
  72. item.isEachOther = true
  73. }
  74. })
  75. this.setData({
  76. list: listCopy
  77. })
  78. wx.showToast({
  79. title: '已关注',
  80. icon: 'none'
  81. })
  82. }
  83. }
  84. },
  85. searchFriend() {
  86. wx.navigateTo({
  87. url: '/pages/searchFriend/index',
  88. })
  89. },
  90. clipboar({
  91. currentTarget
  92. }) {
  93. wx.setClipboardData({
  94. data: currentTarget.dataset.eid,
  95. success: function (res) { //成功回调函数
  96. wx.showToast({
  97. title: '已复制',
  98. icon: "none"
  99. })
  100. }
  101. })
  102. },
  103. onReachBottom() {
  104. this.loadMore()
  105. },
  106. })