homepage.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // pages/today/today.js
  2. const app = getApp()
  3. import * as echarts from '../../ec-canvas/echarts';
  4. const $api = require('../../utils/api.js').API;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. datas:{},
  11. user_id:'',
  12. matchlist:[],
  13. fans:0,
  14. followers:0,
  15. is_follow:0,
  16. age:0,
  17. is_auth_user:1,
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. this.setData({
  24. user_id: options.user_id,
  25. })
  26. wx.getStorage({
  27. key: 'userInfo',
  28. success: res => {
  29. this.setData({
  30. is_auth_user:res.data.id != this.data.user_id,
  31. })
  32. }
  33. })
  34. if(options.type){
  35. wx.setNavigationBarTitle({
  36. title: '我的主页',
  37. })
  38. }
  39. this.getUserData(options.user_id)
  40. this.getUserMatch(options.user_id)
  41. },
  42. getUserData(user_id){
  43. var data = {}
  44. data.user_id = user_id
  45. var year = new Date().getFullYear()
  46. $api.getUserInfo(data).then(res=>{
  47. this.setData({
  48. datas:res.data.data,
  49. age:year - res.data.data.join_time,
  50. is_follow:res.data.data.is_follow,
  51. })
  52. })
  53. },
  54. getUserMatch(user_id){
  55. var data = {}
  56. data.user_id = user_id
  57. $api.getUserMatch(data).then(res=>{
  58. this.setData({
  59. matchlist:res.data.data.list,
  60. })
  61. })
  62. },
  63. followPlayer(e){
  64. let action = e.target.dataset.action;
  65. $api.follow({ follow_id: this.data.user_id, action:action}).then(res=>{
  66. wx.showToast({
  67. title: action?'取消成功':'已关注',
  68. })
  69. this.setData({
  70. is_follow: !this.data.is_follow
  71. })
  72. app.globalData.follow=1
  73. })
  74. },
  75. /**
  76. * 生命周期函数--监听页面初次渲染完成
  77. */
  78. onReady: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面显示
  82. */
  83. onShow: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面隐藏
  87. */
  88. onHide: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面卸载
  92. */
  93. onUnload: function () {
  94. },
  95. /**
  96. * 页面相关事件处理函数--监听用户下拉动作
  97. */
  98. onPullDownRefresh: function () {
  99. },
  100. /**
  101. * 页面上拉触底事件的处理函数
  102. */
  103. onReachBottom: function () {
  104. },
  105. /**
  106. * 用户点击右上角分享
  107. */
  108. onShareAppMessage: function () {
  109. }
  110. })