index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. uid: '',
  19. localUid: wx.getStorageSync('uid')
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad(options) {
  25. this.setData({
  26. type: options.type || 'user',
  27. uid: options.uid
  28. })
  29. },
  30. onShow() {
  31. this.getUserInfo()
  32. },
  33. async getUserInfo() {
  34. let res = await getUserInfo({
  35. uid: this.data.uid
  36. })
  37. this.setData({
  38. userInfo: res
  39. })
  40. this.resetData()
  41. },
  42. loadMore() {
  43. this.getData(getUserRead, {
  44. uid: this.data.userInfo.user.uid,
  45. pageSize: 20
  46. })
  47. },
  48. // 关注
  49. async setFans() {
  50. if (wx.getStorageSync('uid') == this.data.uid) {
  51. return wx.showToast({
  52. title: '不可以关注自己哦~',
  53. icon: 'none'
  54. })
  55. }
  56. let newLike = !this.data.userInfo.like
  57. let res = await setFans({
  58. uid: this.data.userInfo.user.uid,
  59. }, 'put')
  60. this.setData({
  61. ['userInfo.like']: newLike
  62. })
  63. wx.showToast({
  64. title: newLike ? '已关注' : '取消关注',
  65. icon: 'none'
  66. })
  67. },
  68. toPkPage({
  69. currentTarget
  70. }) {
  71. if (this.data.userInfo.user.profession == '官方' || wx.getStorageSync('uid') == this.data.uid) {
  72. wx.navigateTo({
  73. url: `/pages/reading/index?videoId=${currentTarget.dataset.id}`
  74. })
  75. } else {
  76. wx.navigateTo({
  77. url: `/pages/pkPage/index?videoId=${currentTarget.dataset.id}`
  78. })
  79. }
  80. },
  81. })