user.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. app.updateUnread(res.data.notice.toString());
  77. });
  78. },
  79. generalWindow:function(){
  80. this.setData({
  81. generalActive: false
  82. })
  83. },
  84. /**
  85. * 页面跳转
  86. */
  87. goPages:function(e){
  88. if(app.globalData.isLog){
  89. if (e.currentTarget.dataset.url == '/pages/user_spread_user/index') {
  90. if (!this.data.userInfo.is_promoter && this.data.userInfo.statu == 1)
  91. return app.Tips({ title: '您还没有推广权限!!' });
  92. if (!this.data.userInfo.is_promoter && this.data.userInfo.statu == 2){
  93. return this.setData({ generalActive:true});
  94. }
  95. }
  96. if (e.currentTarget.dataset.url == '/pages/logon/index') return this.setData({ switchActive:true});
  97. wx.navigateTo({
  98. url: e.currentTarget.dataset.url
  99. })
  100. }else{
  101. this.setData({ iShidden:false});
  102. }
  103. },
  104. /**
  105. * 生命周期函数--监听页面加载
  106. */
  107. onLoad: function (options) {
  108. this.setData({ MyMenus:app.globalData.MyMenus});
  109. },
  110. /**
  111. * 生命周期函数--监听页面隐藏
  112. */
  113. onHide: function () {
  114. this.setData({ switchActive: false });
  115. },
  116. /**
  117. * 生命周期函数--监听页面卸载
  118. */
  119. onUnload: function () {
  120. },
  121. onShow:function(){
  122. let that = this;
  123. if (app.globalData.isLog){
  124. this.getUserInfo();
  125. this.getMyMenus();
  126. }
  127. },
  128. /**
  129. * 生命周期函数--监听页面卸载
  130. */
  131. onUnload: function () {
  132. },
  133. })