user.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. const app = getApp();
  2. import { getMenuList, getUserInfo} from '../../api/user.js';
  3. import { switchH5Login } from '../../api/api.js';
  4. import authLogin from '../../utils/autuLogin.js';
  5. import util from '../../utils/util.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({ switchActive:false});
  36. },
  37. /**
  38. * 授权回调
  39. */
  40. onLoadFun:function(e){
  41. this.getUserInfo();
  42. this.getMyMenus();
  43. },
  44. Setting: function () {
  45. wx.openSetting({
  46. success: function (res) {
  47. console.log(res.authSetting)
  48. wxh.selfLocation();
  49. }
  50. });
  51. },
  52. /**
  53. *
  54. * 获取个人中心图标
  55. */
  56. getMyMenus: function () {
  57. var that = this;
  58. if (this.data.MyMenus.length) return;
  59. getMenuList().then(res=>{
  60. that.setData({ MyMenus: res.data.routine_my_menus });
  61. });
  62. },
  63. /**
  64. * 获取个人用户信息
  65. */
  66. getUserInfo:function(){
  67. var that=this;
  68. getUserInfo().then(res=>{
  69. const generalContent="generalContent.promoterNum";
  70. that.setData({
  71. userInfo: res.data,
  72. loginType: res.data.login_type,
  73. orderStatusNum: res.data.orderStatusNum,
  74. [generalContent]:`您在商城累计消费金额仅差 ${res.data.promoter_price || 0}元即可开通推广权限`
  75. });
  76. });
  77. },
  78. generalWindow:function(){
  79. this.setData({
  80. generalActive: false
  81. })
  82. },
  83. /**
  84. * 页面跳转
  85. */
  86. goPages:function(e){
  87. if(app.globalData.isLog){
  88. if (e.currentTarget.dataset.url == '/pages/user_spread_user/index') {
  89. if (!this.data.userInfo.is_promoter && this.data.userInfo.statu == 1)
  90. return app.Tips({ title: '您还没有推广权限!!' });
  91. if (!this.data.userInfo.is_promoter && this.data.userInfo.statu == 2){
  92. return this.setData({ generalActive:true});
  93. }
  94. }
  95. if (e.currentTarget.dataset.url == '/pages/logon/index') return this.setData({ switchActive:true});
  96. wx.navigateTo({
  97. url: e.currentTarget.dataset.url
  98. })
  99. }else{
  100. this.setData({ iShidden:false});
  101. }
  102. },
  103. /**
  104. * 生命周期函数--监听页面加载
  105. */
  106. onLoad: function (options) {
  107. this.setData({ MyMenus:app.globalData.MyMenus});
  108. },
  109. /**
  110. * 生命周期函数--监听页面隐藏
  111. */
  112. onHide: function () {
  113. this.setData({ switchActive: false });
  114. },
  115. /**
  116. * 生命周期函数--监听页面卸载
  117. */
  118. onUnload: function () {
  119. },
  120. onShow:function(){
  121. let that = this;
  122. if (app.globalData.isLog){
  123. this.getUserInfo();
  124. this.getMyMenus();
  125. }
  126. },
  127. /**
  128. * 生命周期函数--监听页面卸载
  129. */
  130. onUnload: function () {
  131. },
  132. })