personal.js 2.7 KB

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