personal.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // pages/welfareMall/personal/personal.js
  2. import WelfareMall from '../../../api/welfareMall'
  3. import activity from '../../../api/activity'
  4. import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user'
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. isLogin: false,
  12. mobileTop: 'TONY WU',
  13. countNum: 0,
  14. grayTheme:false,
  15. navigationList:[],
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. },
  22. getCountNum: async function(){
  23. /**
  24. * 福利社
  25. */
  26. let resBuy = await WelfareMall.getUserCouponSnNum({
  27. mobile: getMobileCache(),
  28. });
  29. return Number(resBuy.data.num)
  30. },
  31. // 授权手机号
  32. getPhoneNumber(e) {
  33. getPhoneNumberSync(e, async () => {
  34. let nums = await this.getCountNum();
  35. this.setData({
  36. isLogin: true,
  37. mobileTop: getMobileCache(),
  38. countNum: nums,
  39. })
  40. })
  41. },
  42. // 授权手机号--跳转导航栏
  43. getPhoneNav(e) {
  44. getPhoneNumberSync(e, async () => {
  45. let nums = await this.getCountNum();
  46. this.setData({
  47. isLogin: true,
  48. mobileTop: getMobileCache(),
  49. countNum: nums,
  50. });
  51. this.goToCoupon(e);
  52. })
  53. },
  54. // 动态获取导航栏
  55. async getIndexList(){
  56. let res = await WelfareMall.getPersonalData();
  57. this.setData({
  58. navigationList:res.data.navigationList,
  59. })
  60. },
  61. // 导航栏地址链接跳转
  62. goToCoupon:function(e){
  63. var appId = e.currentTarget.dataset.appid;
  64. var path = e.currentTarget.dataset.path;
  65. if(appId && path){
  66. wx.navigateToMiniProgram({
  67. appId: appId,
  68. path: path,
  69. success(res) {
  70. // 打开成功
  71. }
  72. })
  73. }
  74. if(!appId && path){
  75. wx.navigateTo({
  76. url: path,
  77. })
  78. }
  79. },
  80. /**
  81. * 生命周期函数--监听页面初次渲染完成
  82. */
  83. onReady: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面显示
  87. */
  88. onShow: async function () {
  89. this.setData({
  90. grayTheme: app.globalData.grayTheme
  91. })
  92. this.getIndexList();
  93. let userMobile = await activity.getMobileCache();
  94. // console.log(userMobile)
  95. if (userMobile.length !== 0) {
  96. this.setData({
  97. isLogin: true,
  98. mobileTop: userMobile,
  99. })
  100. }
  101. if(this.data.isLogin){
  102. let nums = await this.getCountNum();
  103. this.setData({
  104. countNum: nums,
  105. })
  106. }
  107. },
  108. /**
  109. * 生命周期函数--监听页面隐藏
  110. */
  111. onHide: function () {
  112. },
  113. /**
  114. * 生命周期函数--监听页面卸载
  115. */
  116. onUnload: function () {
  117. },
  118. /**
  119. * 页面相关事件处理函数--监听用户下拉动作
  120. */
  121. onPullDownRefresh: function () {
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom: function () {
  127. },
  128. /**
  129. * 用户点击右上角分享
  130. */
  131. onShareAppMessage: function () {
  132. }
  133. })