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: 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 (this.data.userInfo.user.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. console.log(res);
  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 == '官方' || this.data.userInfo.user.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. })