personal.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.getUserBuyCouponNum({
  27. mobile: getMobileCache(),
  28. });
  29. let resAward = await WelfareMall.getUserAwardCouponNum({
  30. mobile: getMobileCache(),
  31. });
  32. let resDraw = await WelfareMall.getUserDrawCouponNum({
  33. mobile: getMobileCache(),
  34. });
  35. let nums = Number(resBuy.data.notUseNum)+Number(resAward.data.notUseNum)+Number(resDraw.data.notUseNum)
  36. return nums;
  37. },
  38. // 授权手机号
  39. getPhoneNumber(e) {
  40. getPhoneNumberSync(e, async () => {
  41. let nums = await this.getCountNum();
  42. this.setData({
  43. isLogin: true,
  44. mobileTop: getMobileCache(),
  45. countNum: nums,
  46. })
  47. })
  48. },
  49. // 授权手机号--跳转导航栏
  50. getPhoneNav(e) {
  51. getPhoneNumberSync(e, async () => {
  52. let nums = await this.getCountNum();
  53. this.setData({
  54. isLogin: true,
  55. mobileTop: getMobileCache(),
  56. countNum: nums,
  57. });
  58. this.goToCoupon(e);
  59. })
  60. },
  61. // 动态获取导航栏
  62. async getIndexList(){
  63. let res = await WelfareMall.getPersonalData();
  64. this.setData({
  65. navigationList:res.data.navigationList,
  66. })
  67. },
  68. // 导航栏地址链接跳转
  69. goToCoupon:function(e){
  70. var appId = e.currentTarget.dataset.appid;
  71. var path = e.currentTarget.dataset.path;
  72. if(appId && path){
  73. wx.navigateToMiniProgram({
  74. appId: appId,
  75. path: path,
  76. success(res) {
  77. // 打开成功
  78. }
  79. })
  80. }
  81. if(!appId && path){
  82. wx.navigateTo({
  83. url: path,
  84. })
  85. }
  86. },
  87. /**
  88. * 生命周期函数--监听页面初次渲染完成
  89. */
  90. onReady: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面显示
  94. */
  95. onShow: async function () {
  96. this.setData({
  97. grayTheme: app.globalData.grayTheme
  98. })
  99. this.getIndexList();
  100. let userMobile = await activity.getMobileCache();
  101. // console.log(userMobile)
  102. if (userMobile.length !== 0) {
  103. this.setData({
  104. isLogin: true,
  105. mobileTop: userMobile,
  106. })
  107. }
  108. if(this.data.isLogin){
  109. let nums = await this.getCountNum();
  110. this.setData({
  111. countNum: nums,
  112. })
  113. }
  114. },
  115. /**
  116. * 生命周期函数--监听页面隐藏
  117. */
  118. onHide: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面卸载
  122. */
  123. onUnload: function () {
  124. },
  125. /**
  126. * 页面相关事件处理函数--监听用户下拉动作
  127. */
  128. onPullDownRefresh: function () {
  129. },
  130. /**
  131. * 页面上拉触底事件的处理函数
  132. */
  133. onReachBottom: function () {
  134. },
  135. /**
  136. * 用户点击右上角分享
  137. */
  138. onShareAppMessage: function () {
  139. }
  140. })