index.js 2.8 KB

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