personal.js 2.6 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. 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. this.setData({
  20. isLogin: getMobileCache() != '',
  21. mobileTop: getMobileCache(),
  22. })
  23. if(this.data.isLogin){
  24. let nums = await this.getCountNum();
  25. this.setData({
  26. countNum: nums,
  27. })
  28. }
  29. },
  30. /**
  31. * 获取用户信息
  32. */
  33. getUserPhone: async function(){
  34. await WelfareMall.getUser({
  35. openid: activity.getOpenId(),
  36. source:'FREE_MINI_APP',
  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. },
  88. /**
  89. * 生命周期函数--监听页面隐藏
  90. */
  91. onHide: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面卸载
  95. */
  96. onUnload: function () {
  97. },
  98. /**
  99. * 页面相关事件处理函数--监听用户下拉动作
  100. */
  101. onPullDownRefresh: function () {
  102. },
  103. /**
  104. * 页面上拉触底事件的处理函数
  105. */
  106. onReachBottom: function () {
  107. },
  108. /**
  109. * 用户点击右上角分享
  110. */
  111. onShareAppMessage: function () {
  112. }
  113. })