index.js 1.3 KB

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