prize.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // pages/luckDraw/prize.js
  2. import LuckDraw from '../../api/luck-draw'
  3. import { parseTime } from '../../utils/util';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. page: 1,
  10. pageSize: 10,
  11. lock: false,
  12. noResult: false,
  13. noMore: false,
  14. couponNum: 0,
  15. productNum: 0,
  16. goodsItemList: []
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. },
  23. /**
  24. * 生命周期函数--监听页面初次渲染完成
  25. */
  26. onReady: function () {
  27. },
  28. /**
  29. * 生命周期函数--监听页面显示
  30. */
  31. onShow: function () {
  32. this.getUserPrizeList();
  33. },
  34. /**
  35. * 生命周期函数--监听页面隐藏
  36. */
  37. onHide: function () {
  38. },
  39. /**
  40. * 生命周期函数--监听页面卸载
  41. */
  42. onUnload: function () {
  43. },
  44. /**
  45. * 页面相关事件处理函数--监听用户下拉动作
  46. */
  47. onPullDownRefresh: function () {
  48. },
  49. /**
  50. * 页面上拉触底事件的处理函数
  51. */
  52. onReachBottom: 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:'16602120168',
  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. */
  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. toProfile(e) {
  107. const url = "profile?id=" + e.currentTarget.dataset.id
  108. wx.redirectTo({
  109. url
  110. })
  111. }
  112. })