personal.js 2.6 KB

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