profile.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // pages/luckDraw/profile.js
  2. import LuckDraw from '../../api/luck-draw'
  3. import { parseTime } from '../../utils/util'
  4. import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../utils/user'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. page: 1,
  11. pageSize: 10,
  12. lock: false,
  13. noResult: false,
  14. noMore: false,
  15. isLogin: false,
  16. couponNum: 0,
  17. productNum: 0,
  18. goodsItemList: []
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. this.setData({
  25. isLogin: getMobileCache() != ''
  26. })
  27. this.getUserPrizeList();
  28. },
  29. /**
  30. * 生命周期函数--监听页面初次渲染完成
  31. */
  32. onReady: function () {
  33. },
  34. /**
  35. * 生命周期函数--监听页面显示
  36. */
  37. onShow: function () {
  38. },
  39. /**
  40. * 生命周期函数--监听页面隐藏
  41. */
  42. onHide: function () {
  43. },
  44. /**
  45. * 生命周期函数--监听页面卸载
  46. */
  47. onUnload: function () {
  48. },
  49. /**
  50. * 页面相关事件处理函数--监听用户下拉动作
  51. */
  52. onPullDownRefresh: function () {
  53. },
  54. /**
  55. * 用户点击右上角分享
  56. */
  57. onShareAppMessage: function () {
  58. },
  59. getUserPrizeList: function() {
  60. LuckDraw.getUserPrizeList({
  61. page: this.data.page,
  62. pageSize: this.data.pageSize,
  63. mobile: getMobileCache(),
  64. goodsType: 1
  65. }).then(res => {
  66. if (res.code == 200) {
  67. this.uaerPrizeListView(res.data)
  68. }
  69. this.data.lock = false
  70. }).catch(_ => {
  71. console.log(_)
  72. this.data.lock = false
  73. })
  74. },
  75. uaerPrizeListView: function(data) {
  76. if (!Array.isArray(data.goodsItemList) || data.goodsItemList.length == 0) {
  77. console.log("没有获取到数据");
  78. this.setData({
  79. noResult: true
  80. })
  81. return
  82. }
  83. data.goodsItemList.forEach(v => {
  84. let beginTime = v.couponBeginTimestamp
  85. let endTime = v.couponEndTimestamp
  86. v.couponBeginTimestamp = parseTime(beginTime, "{y}.{m}.{d}")
  87. v.couponEndTimestamp = parseTime(endTime, "{y}.{m}.{d}")
  88. })
  89. this.data.goodsItemList = this.data.goodsItemList.concat(...data.goodsItemList)
  90. this.setData({
  91. couponNum: data.couponNum,
  92. productNum: data.productNum,
  93. goodsItemList: this.data.goodsItemList
  94. })
  95. },
  96. /**
  97. * 页面上拉触底事件的处理函数
  98. onReachBottom: function () {
  99. if (this.data.lock || this.data.noMore) {
  100. return
  101. }
  102. this.data.lock = true
  103. this.data.page++
  104. this.getUserPrizeList()
  105. },
  106. */
  107. toPrize(e) {
  108. const url = "prize?id=" + e.currentTarget.dataset.id
  109. wx.redirectTo({
  110. url
  111. })
  112. },
  113. turnPrize: function() {
  114. console.log("开始查看")
  115. if (this.isLock || !this.data.isLogin) {
  116. return
  117. }
  118. },
  119. // 授权手机号
  120. getPhoneNumber(e) {
  121. getPhoneNumberSync(e, _ => {
  122. this.getUserPrizeList()
  123. })
  124. },
  125. })