index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. userInfo:{},
  18. host_product:[],
  19. isClose:false,
  20. recharge_switch:0,
  21. },
  22. /**
  23. * 登录回调
  24. */
  25. onLoadFun:function(){
  26. this.getUserInfo();
  27. this.get_host_product();
  28. this.get_activity();
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {
  34. },
  35. openSubscribe:function(e){
  36. let page = e.currentTarget.dataset.url;
  37. wx.showLoading({
  38. title: '正在加载',
  39. })
  40. openRechargeSubscribe().then(res => {
  41. wx.hideLoading();
  42. wx.navigateTo({
  43. url: page,
  44. });
  45. }).catch(() => {
  46. wx.hideLoading();
  47. });
  48. },
  49. /**
  50. * 获取用户详情
  51. */
  52. getUserInfo:function(){
  53. let that = this;
  54. getUserInfo().then(res=>{
  55. that.setData({
  56. userInfo: res.data,
  57. recharge_switch: res.data.recharge_switch
  58. });
  59. });
  60. },
  61. /**
  62. * 获取活动可参与否
  63. */
  64. get_activity:function(){
  65. var that=this;
  66. userActivity().then(res=>{
  67. that.setData({ activity: res.data });
  68. })
  69. },
  70. /**
  71. * 获取我的推荐
  72. */
  73. get_host_product:function(){
  74. var that=this;
  75. getProductHot().then(res=>{
  76. that.setData({ host_product: res.data });
  77. })
  78. },
  79. /**
  80. * 生命周期函数--监听页面显示
  81. */
  82. onShow: function () {
  83. if (app.globalData.isLog && this.data.isClose) {
  84. this.getUserInfo();
  85. this.get_host_product();
  86. this.get_activity();
  87. }
  88. },
  89. /**
  90. * 生命周期函数--监听页面隐藏
  91. */
  92. onHide: function () {
  93. this.setData({ isClose: true });
  94. },
  95. })