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. },
  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. if (this.data.userInfo.user.uid == wx.getStorageSync('uid')) {
  49. return wx.showToast({
  50. title: '不可以关注自己哦~',
  51. icon: 'none'
  52. })
  53. }
  54. let newLike = !this.data.userInfo.like
  55. let res = await setFans({
  56. uid: this.data.userInfo.user.uid,
  57. }, 'put')
  58. console.log(res);
  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 == '官方') {
  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. })