index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // pages/my-account/index.js
  2. import { getProductHot } from '../../api/store.js';
  3. import { openRechargeSubscribe } from '../../utils/SubscribeMessage.js';
  4. import { getUserInfo, userActivity } from '../../api/user.js';
  5. const app=getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. parameter: {
  12. 'navbar': '1',
  13. 'return': '1',
  14. 'title': '我的账户',
  15. 'color': false,
  16. },
  17. iShidden: false,
  18. userInfo:{},
  19. host_product:[],
  20. isClose:false,
  21. recharge_switch:0,
  22. },
  23. /**
  24. * 登录回调
  25. */
  26. onLoadFun:function(){
  27. this.getUserInfo();
  28. this.get_host_product();
  29. this.get_activity();
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. if (app.globalData.token) this.setData({ iShidden:true});
  36. },
  37. openSubscribe:function(e){
  38. let page = e.currentTarget.dataset.url;
  39. wx.showLoading({
  40. title: '正在加载',
  41. })
  42. openRechargeSubscribe().then(res => {
  43. wx.hideLoading();
  44. wx.navigateTo({
  45. url: page,
  46. });
  47. }).catch(() => {
  48. wx.hideLoading();
  49. });
  50. },
  51. /**
  52. * 获取用户详情
  53. */
  54. getUserInfo:function(){
  55. let that = this;
  56. getUserInfo().then(res=>{
  57. that.setData({
  58. userInfo: res.data,
  59. recharge_switch: res.data.recharge_switch
  60. });
  61. });
  62. },
  63. /**
  64. * 获取活动可参与否
  65. */
  66. get_activity:function(){
  67. var that=this;
  68. userActivity().then(res=>{
  69. that.setData({ activity: res.data });
  70. })
  71. },
  72. /**
  73. * 获取我的推荐
  74. */
  75. get_host_product:function(){
  76. var that=this;
  77. getProductHot().then(res=>{
  78. that.setData({ host_product: res.data });
  79. })
  80. },
  81. /**
  82. * 生命周期函数--监听页面显示
  83. */
  84. onShow: function () {
  85. if (app.globalData.isLog && this.data.isClose) {
  86. this.getUserInfo();
  87. this.get_host_product();
  88. this.get_activity();
  89. this.setData({
  90. iShidden: true
  91. });
  92. }
  93. },
  94. /**
  95. * 生命周期函数--监听页面隐藏
  96. */
  97. onHide: function () {
  98. this.setData({ isClose: true });
  99. },
  100. })