index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. })
  44. },
  45. // 关注
  46. async setFans() {
  47. let newLike = !this.data.userInfo.like
  48. await setFans({
  49. uid: this.data.userInfo.user.uid
  50. }, 'put')
  51. this.setData({
  52. ['userInfo.like']: newLike
  53. })
  54. wx.showToast({
  55. title: newLike ? '已关注' : '取消关注',
  56. icon: 'none'
  57. })
  58. },
  59. toPkPage({
  60. currentTarget
  61. }) {
  62. wx.navigateTo({
  63. url: `/pages/pkPage/index?videoId=${currentTarget.dataset.id}`
  64. })
  65. },
  66. })