personal.js 2.8 KB

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