prize.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // pages/luckDraw/prize.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: 2
  65. }).then(res => {
  66. if (res.code == 200) {
  67. this.uaerPrizeListView(res.data)
  68. }
  69. this.data.lock = false
  70. }).catch(_ => {
  71. this.data.lock = false
  72. })
  73. },
  74. uaerPrizeListView: function(data) {
  75. if (!Array.isArray(data.goodsItemList) || data.goodsItemList.length == 0) {
  76. console.log("没有获取到数据");
  77. this.setData({
  78. noResult: true
  79. })
  80. return
  81. }
  82. data.goodsItemList.forEach(v => {
  83. let beginTime = v.couponBeginTimestamp
  84. let endTime = v.couponEndTimestamp
  85. v.couponBeginTimestamp = parseTime(beginTime, "{y}.{m}.{d}")
  86. v.couponEndTimestamp = parseTime(endTime, "{y}.{m}.{d}")
  87. })
  88. this.data.goodsItemList = this.data.goodsItemList.concat(...data.goodsItemList)
  89. this.setData({
  90. couponNum: data.couponNum,
  91. productNum: data.productNum,
  92. goodsItemList: this.data.goodsItemList
  93. })
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. onReachBottom: function () {
  98. if (this.data.lock || this.data.noMore) {
  99. return
  100. }
  101. this.data.lock = true
  102. this.data.page++
  103. this.getUserPrizeList()
  104. },*/
  105. toProfile(e) {
  106. const url = "profile?id=" + e.currentTarget.dataset.id
  107. wx.redirectTo({
  108. url
  109. })
  110. },
  111. turnPrize: function() {
  112. console.log("开始查看")
  113. if (this.isLock || !this.data.isLogin) {
  114. return
  115. }
  116. },
  117. // 授权手机号
  118. getPhoneNumber(e) {
  119. getPhoneNumberSync(e, _ => {
  120. this.getUserPrizeList()
  121. })
  122. },
  123. })