coupon.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. type:0,
  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. showCoupon:function(e){
  65. console.log(e)
  66. this.setData({
  67. type:parseInt(e.currentTarget.dataset.type),
  68. couponList:[],
  69. noResult:false,
  70. noMore:false,
  71. page:1
  72. })
  73. this.getCouponList()
  74. },
  75. // 券包数据 0 待使用 1 已使用 2 已过期
  76. getCouponList: async function() {
  77. let res = await WelfareMall.getUserCouponSnList({
  78. page: this.data.page,
  79. pageSize: this.data.pageSize,
  80. mobile: getMobileCache(),
  81. stateList:[this.data.type]
  82. }).then(res => {
  83. if (res.code == 200) {
  84. this.userCouponListView(res.data)
  85. }
  86. this.data.lock = false
  87. }).catch(_ => {
  88. console.log(_)
  89. this.data.lock = false
  90. })
  91. },
  92. userCouponListView: function(data) {
  93. if (!Array.isArray(data) || data.length == 0) {
  94. console.log("订单列表数据为空");
  95. if (this.data.page == 1) {
  96. this.setData({
  97. mobileTop:getMobileCache(),
  98. noResult: true
  99. })
  100. } else {
  101. this.setData({
  102. mobileTop:getMobileCache(),
  103. noMore: true
  104. })
  105. }
  106. return
  107. }
  108. data.forEach(v => {
  109. let beginTime = v.couponBeginTimestamp
  110. let endTime = v.couponEndTimestamp
  111. v.couponStartTime = beginTime * 1000
  112. v.couponEndTime = endTime * 1000
  113. v.title = v.couponTitle
  114. v.isSn = true
  115. })
  116. this.data.couponList = this.data.couponList.concat(...data)
  117. this.setData({
  118. mobileTop:getMobileCache(),
  119. couponList: this.data.couponList
  120. })
  121. }
  122. })