index.js 1.7 KB

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