personal.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: async function (options) {
  20. let userMobile = await activity.getMobileCache();
  21. console.log(userMobile)
  22. if (userMobile.length !== 0) {
  23. this.setData({
  24. isLogin: true,
  25. mobileTop: userMobile,
  26. })
  27. }
  28. // this.setData({
  29. // isLogin: getMobileCache() != '',
  30. // mobileTop: getMobileCache(),
  31. // })
  32. if(this.data.isLogin){
  33. let nums = await this.getCountNum();
  34. this.setData({
  35. countNum: nums,
  36. })
  37. }
  38. },
  39. getCountNum: async function(){
  40. /**
  41. * 福利社
  42. */
  43. let resBuy = await WelfareMall.getUserBuyCouponNum({
  44. mobile: getMobileCache(),
  45. });
  46. let resAward = await WelfareMall.getUserAwardCouponNum({
  47. mobile: getMobileCache(),
  48. });
  49. let resDraw = await WelfareMall.getUserDrawCouponNum({
  50. mobile: getMobileCache(),
  51. });
  52. let nums = Number(resBuy.data.notUseNum)+Number(resAward.data.notUseNum)+Number(resDraw.data.notUseNum)
  53. return nums;
  54. },
  55. // 授权手机号
  56. getPhoneNumber(e) {
  57. getPhoneNumberSync(e, async () => {
  58. let nums = await this.getCountNum();
  59. this.setData({
  60. isLogin: true,
  61. mobileTop: getMobileCache(),
  62. countNum: nums,
  63. })
  64. })
  65. },
  66. toHistorical(e) {
  67. const url = "../historical/historical?id=" + e.currentTarget.dataset.id
  68. wx.navigateTo({
  69. url
  70. })
  71. },
  72. toFeedback(e) {
  73. const url = "../feedback/feedback?id=" + e.currentTarget.dataset.id
  74. wx.navigateTo({
  75. url: url,
  76. })
  77. },
  78. /**
  79. * 生命周期函数--监听页面初次渲染完成
  80. */
  81. onReady: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow: function () {
  87. this.setData({
  88. grayTheme: app.globalData.grayTheme
  89. })
  90. },
  91. /**
  92. * 生命周期函数--监听页面隐藏
  93. */
  94. onHide: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面卸载
  98. */
  99. onUnload: function () {
  100. },
  101. /**
  102. * 页面相关事件处理函数--监听用户下拉动作
  103. */
  104. onPullDownRefresh: function () {
  105. },
  106. /**
  107. * 页面上拉触底事件的处理函数
  108. */
  109. onReachBottom: function () {
  110. },
  111. /**
  112. * 用户点击右上角分享
  113. */
  114. onShareAppMessage: function () {
  115. }
  116. })