me.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. Page({
  4. mixins: [require('../../mixin/commonMixin.js')],
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. info: [],
  10. member_info: {
  11. username: '',
  12. member_id: 1,
  13. avatar: "../../images/head-bitmap.png"
  14. },
  15. info: {
  16. total_money: 0,
  17. share_name: '无'
  18. }
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. let commiss_diy_name = wx.getStorageSync('commiss_diy_name') || '分销';
  25. wx.setNavigationBarTitle({
  26. title: `${commiss_diy_name}中心`,
  27. })
  28. },
  29. /**
  30. * 生命周期函数--监听页面显示
  31. */
  32. onShow: function () {
  33. let that = this;
  34. util.check_login_new().then((res) => {
  35. if (res) {
  36. that.setData({
  37. needAuth: false
  38. })
  39. that.getUser();
  40. that.getData();
  41. } else {
  42. that.setData({
  43. needAuth: true
  44. })
  45. }
  46. })
  47. },
  48. /**
  49. * 授权成功回调
  50. */
  51. authSuccess: function () {
  52. let that = this;
  53. this.setData({
  54. needAuth: false
  55. }, () => {
  56. that.getUser();
  57. that.getData();
  58. })
  59. },
  60. getData: function () {
  61. wx.showLoading();
  62. var token = wx.getStorageSync('token');
  63. let that = this;
  64. app.util.request({
  65. url: 'entry/wxapp/user',
  66. data: {
  67. controller: 'distribution.get_commission_info',
  68. token: token
  69. },
  70. dataType: 'json',
  71. success: function (res) {
  72. wx.hideLoading();
  73. if (res.data.code == 0) {
  74. let parent_info = res.data.parent_info;
  75. that.setData({ info: res.data.data, parent_info })
  76. } else {
  77. wx.showModal({
  78. title: '提示',
  79. content: res.data.msg,
  80. showCancel: false,
  81. success(res) {
  82. if (res.confirm) {
  83. console.log('用户点击确定')
  84. wx.reLaunch({
  85. url: '/lionfish_comshop/pages/user/me',
  86. })
  87. }
  88. }
  89. })
  90. }
  91. }
  92. })
  93. },
  94. getUser: function(){
  95. var token = wx.getStorageSync('token');
  96. let that = this;
  97. app.util.request({
  98. url: 'entry/wxapp/user',
  99. data: {
  100. controller: 'user.get_user_info',
  101. token: token
  102. },
  103. dataType: 'json',
  104. success: function (res) {
  105. wx.hideLoading();
  106. if (res.data.code == 0) {
  107. // let commiss_diy_name = res.data.commiss_diy_name || '分销';
  108. // wx.setNavigationBarTitle({
  109. // title: `${commiss_diy_name}中心`,
  110. // })
  111. that.setData({ member_info: res.data.data })
  112. } else {
  113. //is_login
  114. that.setData({ needAuth: true })
  115. wx.setStorage({
  116. key: "member_id",
  117. data: null
  118. })
  119. }
  120. }
  121. })
  122. },
  123. goLink: function (event) {
  124. if (!this.authModal()) return;
  125. let link = event.currentTarget.dataset.link;
  126. var pages_all = getCurrentPages();
  127. if (pages_all.length > 3) {
  128. wx.redirectTo({
  129. url: link
  130. })
  131. } else {
  132. wx.navigateTo({
  133. url: link
  134. })
  135. }
  136. },
  137. })