homepage.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. is_black:0,
  17. age:0,
  18. is_auth_user:1,
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. this.setData({
  25. user_id: options.user_id,
  26. })
  27. wx.getStorage({
  28. key: 'userInfo',
  29. success: res => {
  30. this.setData({
  31. is_auth_user:res.data.id != this.data.user_id,
  32. })
  33. }
  34. })
  35. if(options.type){
  36. wx.setNavigationBarTitle({
  37. title: '我的主页',
  38. })
  39. }
  40. this.getUserData(options.user_id)
  41. this.getUserMatch(options.user_id)
  42. },
  43. getUserData(user_id){
  44. var data = {}
  45. data.user_id = user_id
  46. var year = new Date().getFullYear()
  47. $api.getUserInfo(data).then(res=>{
  48. this.setData({
  49. datas:res.data.data,
  50. age:res.data.data.join_time?(year - res.data.data.join_time):0,
  51. is_follow:res.data.data.is_follow,
  52. is_black:res.data.data.is_black,
  53. })
  54. })
  55. },
  56. getUserMatch(user_id){
  57. var data = {}
  58. data.user_id = user_id
  59. $api.getUserMatch(data).then(res=>{
  60. this.setData({
  61. matchlist:res.data.data.list,
  62. })
  63. })
  64. },
  65. // 拉黑
  66. black(){
  67. $api.blackUser({ black_user_id: this.data.user_id}).then(res=>{
  68. wx.showToast({
  69. title: '已拉黑'
  70. })
  71. this.setData({
  72. is_black: 1
  73. })
  74. })
  75. },
  76. // 取消拉黑
  77. cancelBlack(){
  78. $api.cancelBlack({ black_user_id: this.data.user_id}).then(res=>{
  79. wx.showToast({
  80. title: '已取消'
  81. })
  82. this.setData({
  83. is_black: 0
  84. })
  85. })
  86. },
  87. // 关注 取消
  88. followPlayer(e){
  89. let action = e.target.dataset.action;
  90. $api.follow({ follow_id: this.data.user_id, action:action}).then(res=>{
  91. wx.showToast({
  92. title: action?'取消成功':'已关注',
  93. })
  94. this.setData({
  95. is_follow: !this.data.is_follow
  96. })
  97. app.globalData.follow=1
  98. })
  99. },
  100. /**
  101. * 生命周期函数--监听页面初次渲染完成
  102. */
  103. onReady: function () {
  104. },
  105. /**
  106. * 生命周期函数--监听页面显示
  107. */
  108. onShow: function () {
  109. this.getUserData(this.data.user_id)
  110. },
  111. /**
  112. * 生命周期函数--监听页面隐藏
  113. */
  114. onHide: function () {
  115. },
  116. /**
  117. * 生命周期函数--监听页面卸载
  118. */
  119. onUnload: function () {
  120. },
  121. /**
  122. * 页面相关事件处理函数--监听用户下拉动作
  123. */
  124. onPullDownRefresh: function () {
  125. },
  126. /**
  127. * 页面上拉触底事件的处理函数
  128. */
  129. onReachBottom: function () {
  130. },
  131. /**
  132. * 用户点击右上角分享
  133. */
  134. onShareAppMessage: function () {
  135. }
  136. })