index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. },
  12. onShow() {
  13. this.resetData()
  14. },
  15. setType({
  16. currentTarget
  17. }) {
  18. this.setData({
  19. currentType: currentTarget.dataset.type
  20. })
  21. this.resetData()
  22. },
  23. // 获取分类的内容
  24. loadMore() {
  25. let type = this.data.currentType
  26. this.getData(getFansList, {
  27. pageSize: 20,
  28. type
  29. })
  30. },
  31. jumpUserInfo({
  32. currentTarget
  33. }) {
  34. let uid = currentTarget.dataset.uid
  35. wx.navigateTo({
  36. url: `/pages/personal/index?uid=${uid}`,
  37. })
  38. },
  39. async setFans({
  40. currentTarget
  41. }) {
  42. if (this.data.currentType == '1') {
  43. this.jumpUserInfo({
  44. currentTarget
  45. })
  46. } else {
  47. if (currentTarget.dataset.iseachother) {
  48. this.jumpUserInfo({
  49. currentTarget
  50. })
  51. } else {
  52. await setFans({
  53. uid: currentTarget.dataset.uid
  54. })
  55. let listCopy = JSON.parse(JSON.stringify(this.data.list))
  56. listCopy.forEach(item => {
  57. if (item.user.uid == currentTarget.dataset.uid) {
  58. item.isEachOther = true
  59. }
  60. })
  61. this.setData({
  62. list: listCopy
  63. })
  64. wx.showToast({
  65. title: '已回关',
  66. icon: 'none'
  67. })
  68. }
  69. }
  70. }
  71. })