profile.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // pages/luckDraw/profile.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. this.getUserPrizeList();
  23. },
  24. /**
  25. * 生命周期函数--监听页面初次渲染完成
  26. */
  27. onReady: function () {
  28. },
  29. /**
  30. * 生命周期函数--监听页面显示
  31. */
  32. onShow: function () {
  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. onShareAppMessage: function () {
  53. },
  54. getUserPrizeList: function() {
  55. LuckDraw.getUserPrizeList({
  56. page: this.data.page,
  57. pageSize: this.data.pageSize,
  58. mobile:'16602120168',
  59. goodsType: 1
  60. }).then(res => {
  61. if (res.code == 200) {
  62. this.uaerPrizeListView(res.data)
  63. }
  64. this.data.lock = false
  65. }).catch(_ => {
  66. this.data.lock = false
  67. })
  68. },
  69. uaerPrizeListView: function(data) {
  70. if (!Array.isArray(data.goodsItemList) || data.goodsItemList.length == 0) {
  71. console.log("没有获取到数据");
  72. if (this.data.couponNum == 1) {
  73. this.setData({
  74. noResult: true
  75. })
  76. } else {
  77. this.setData({
  78. noMore: true
  79. })
  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. */
  99. onReachBottom: function () {
  100. if (this.data.lock || this.data.noMore) {
  101. return
  102. }
  103. this.data.lock = true
  104. this.data.page++
  105. this.getUserPrizeList()
  106. },
  107. toPrize(e) {
  108. const url = "prize?id=" + e.currentTarget.dataset.id
  109. wx.redirectTo({
  110. url
  111. })
  112. }
  113. })