user.js 3.2 KB

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