user.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. const app = getApp();
  2. import {
  3. getMenuList,
  4. getUserInfo
  5. } from '../../api/user.js';
  6. import wxh from '../../utils/wxh.js';
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. parameter: {
  13. 'navbar': '1',
  14. 'return': '0',
  15. 'title': '个人中心',
  16. 'color': true,
  17. 'class': '0'
  18. },
  19. userInfo: {},
  20. MyMenus: [],
  21. isGoIndex: false,
  22. iShidden: true,
  23. isAuto: false,
  24. switchActive: false,
  25. loginType: app.globalData.loginType,
  26. orderStatusNum: {},
  27. promoter_price: 0,
  28. generalActive: false,
  29. generalContent: {
  30. promoterNum: '',
  31. title: '您未获得推广权限'
  32. }
  33. },
  34. close: function () {
  35. this.setData({
  36. switchActive: false
  37. });
  38. },
  39. /**
  40. * 授权回调
  41. */
  42. onLoadFun: function (e) {
  43. this.getUserInfo();
  44. this.getMyMenus();
  45. },
  46. Setting: function () {
  47. wx.openSetting({
  48. success: function (res) {
  49. console.log(res.authSetting)
  50. // wxh.selfLocation();
  51. }
  52. });
  53. },
  54. /**
  55. * 获取个人中心图标
  56. */
  57. getMyMenus: function () {
  58. var that = this;
  59. if (this.data.MyMenus.length) return;
  60. getMenuList().then(res => {
  61. that.setData({
  62. MyMenus: res.data.routine_my_menus
  63. });
  64. });
  65. },
  66. /**
  67. * 获取个人用户信息
  68. */
  69. getUserInfo: function () {
  70. var that = this;
  71. getUserInfo().then(res => {
  72. const generalContent = "generalContent.promoterNum";
  73. that.setData({
  74. userInfo: res.data,
  75. loginType: res.data.login_type,
  76. orderStatusNum: res.data.orderStatusNum,
  77. [generalContent]: `您在商城累计消费金额仅差 ${res.data.promoter_price || 0}元即可开通推广权限`
  78. });
  79. // app.globalData.unread = res.data.notice
  80. app.setUnread(res.data.notice)
  81. });
  82. },
  83. generalWindow: function () {
  84. this.setData({
  85. generalActive: false
  86. })
  87. },
  88. /**
  89. * 页面跳转
  90. */
  91. goPages: function (e) {
  92. if (app.globalData.isLog) {
  93. if (e.currentTarget.dataset.url == '/pages/user_spread_user/index') {
  94. if (!this.data.userInfo.is_promoter && this.data.userInfo.statu == 1)
  95. return app.Tips({
  96. title: '您还没有推广权限!!'
  97. });
  98. if (!this.data.userInfo.is_promoter && this.data.userInfo.statu == 2) {
  99. return this.setData({
  100. generalActive: true
  101. });
  102. }
  103. }
  104. if (e.currentTarget.dataset.url == '/pages/logon/index') return this.setData({
  105. switchActive: true
  106. });
  107. wx.navigateTo({
  108. url: e.currentTarget.dataset.url
  109. })
  110. } else {
  111. this.setData({
  112. iShidden: false
  113. });
  114. }
  115. },
  116. /**
  117. * 生命周期函数--监听页面加载
  118. */
  119. onLoad: function (options) {
  120. this.setData({
  121. MyMenus: app.globalData.MyMenus
  122. });
  123. },
  124. /**
  125. * 生命周期函数--监听页面隐藏
  126. */
  127. onHide: function () {
  128. this.setData({
  129. switchActive: false
  130. });
  131. },
  132. /**
  133. * 生命周期函数--监听页面卸载
  134. */
  135. onUnload: function () {
  136. },
  137. onShow: function () {
  138. let that = this;
  139. if (app.globalData.isLog) {
  140. this.getUserInfo();
  141. this.getMyMenus();
  142. }
  143. },
  144. /**
  145. * 生命周期函数--监听页面卸载
  146. */
  147. onUnload: function () {
  148. },
  149. })