coupon.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // pages/welfareMall/coupon/coupon.js
  2. import WelfareMall from '../../../api/welfareMall'
  3. import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. page: 1,
  10. pageSize: 10,
  11. lock: false,
  12. noResult: false,
  13. noMore: false,
  14. mobileTop: 'TONY WU',
  15. couponList: []
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. this.getCouponList();
  22. },
  23. /**
  24. * 生命周期函数--监听页面初次渲染完成
  25. */
  26. onReady: function () {
  27. },
  28. /**
  29. * 生命周期函数--监听页面显示
  30. */
  31. onShow: function () {
  32. },
  33. /**
  34. * 生命周期函数--监听页面隐藏
  35. */
  36. onHide: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面卸载
  40. */
  41. onUnload: function () {
  42. },
  43. /**
  44. * 页面相关事件处理函数--监听用户下拉动作
  45. */
  46. onPullDownRefresh: function () {
  47. },
  48. /**
  49. * 页面上拉触底事件的处理函数
  50. */
  51. onReachBottom: function () {
  52. if (this.data.lock || this.data.noMore) {
  53. return
  54. }
  55. this.data.lock = true
  56. this.data.page++
  57. this.getCouponList();
  58. },
  59. /**
  60. * 用户点击右上角分享
  61. */
  62. onShareAppMessage: function () {
  63. },
  64. // 券包数据
  65. getCouponList: async function() {
  66. let res = await WelfareMall.getUserCouponSnList({
  67. page: this.data.page,
  68. pageSize: this.data.pageSize,
  69. mobile: getMobileCache(),
  70. }).then(res => {
  71. if (res.code == 200) {
  72. this.userCouponListView(res.data)
  73. }
  74. this.data.lock = false
  75. }).catch(_ => {
  76. console.log(_)
  77. this.data.lock = false
  78. })
  79. },
  80. userCouponListView: function(data) {
  81. if (!Array.isArray(data) || data.length == 0) {
  82. console.log("订单列表数据为空");
  83. if (this.data.page == 1) {
  84. this.setData({
  85. mobileTop:getMobileCache(),
  86. noResult: true
  87. })
  88. } else {
  89. this.setData({
  90. mobileTop:getMobileCache(),
  91. noMore: true
  92. })
  93. }
  94. return
  95. }
  96. data.forEach(v => {
  97. let beginTime = v.couponBeginTimestamp
  98. let endTime = v.couponEndTimestamp
  99. v.couponStartTime = beginTime * 1000
  100. v.couponEndTime = endTime * 1000
  101. v.title = v.couponTitle
  102. v.isSn = true
  103. })
  104. this.data.couponList = this.data.couponList.concat(...data)
  105. this.setData({
  106. mobileTop:getMobileCache(),
  107. couponList: this.data.couponList
  108. })
  109. }
  110. })