index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {
  2. getUserInfo,
  3. setFans,
  4. getUserRead
  5. } from '~/api/user'
  6. import share from '~/mixins/share'
  7. import reachBottom from '~/mixins/reachBottom'
  8. Page({
  9. behaviors: [reachBottom, share],
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. uid: '',
  15. userInfo: {},
  16. // type为pk,顶部显示为pk时样式,user为默认样式
  17. type: 'user'
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad(options) {
  23. this.setData({
  24. type: options.type || 'user',
  25. uid: options.uid
  26. })
  27. },
  28. onShow() {
  29. this.getUserInfo()
  30. },
  31. async getUserInfo() {
  32. let res = await getUserInfo({
  33. uid: this.data.uid
  34. })
  35. this.setData({
  36. userInfo: res
  37. })
  38. this.resetData()
  39. },
  40. loadMore() {
  41. this.getData(getUserRead, {
  42. uid: this.data.userInfo.user.uid,
  43. pageSize: 20
  44. })
  45. },
  46. // 关注
  47. async setFans() {
  48. let newLike = !this.data.userInfo.like
  49. let res = await setFans({
  50. uid: this.data.userInfo.user.uid,
  51. // fanId:
  52. }, 'put')
  53. console.log(res);
  54. this.setData({
  55. ['userInfo.like']: newLike
  56. })
  57. wx.showToast({
  58. title: newLike ? '已关注' : '取消关注',
  59. icon: 'none'
  60. })
  61. },
  62. toPkPage({
  63. currentTarget
  64. }) {
  65. wx.navigateTo({
  66. url: `/pages/pkPage/index?videoId=${currentTarget.dataset.id}`
  67. })
  68. },
  69. })