推拿小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
3.2 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. <template>
  2. <scroll-view scroll-y="true" :style="{height: height}" @scrolltolower="moreCoupon()">
  3. <!-- 优惠券列表 -->
  4. <view class="list">
  5. <view class="list-item" v-for="item in couponList" @click="select(item)" :key="item.id">
  6. <!-- 已领取 -->
  7. <template v-if="item.status == 0">
  8. <image class="list-item-bg" src="@/pages_order/static/coupon/coupon-bg-useful.png" ></image>
  9. </template>
  10. <!-- 已使用 -->
  11. <template v-else-if="item.status == 1">
  12. <image class="list-item-bg" src="@/pages_order/static/coupon/coupon-bg-used.png" ></image>
  13. </template>
  14. <!-- 已过期 -->
  15. <template v-else-if="item.status == 2">
  16. <image class="list-item-bg" src="@/pages_order/static/coupon/coupon-bg-overtime.png" ></image>
  17. </template>
  18. <text class="list-item-count">{{ item.discountAmount }}</text>
  19. <text class="list-item-deadline">{{ `有效期至${item.validDate ? $dayjs(item.validDate).format('YYYY-MM-DD') : '-'}` }}</text>
  20. </view>
  21. </view>
  22. <uv-empty v-if="couponList.length == 0" text="空空如也" textSize="30rpx" iconSize="200rpx" icon="list"></uv-empty>
  23. </scroll-view>
  24. </template>
  25. <script>
  26. export default {
  27. name: 'CouponList',
  28. props: {
  29. status: {
  30. type: String | Number,
  31. default: 'all'
  32. },
  33. height: {
  34. default: 'calc(90vh - 180rpx)'
  35. }
  36. },
  37. data() {
  38. return {
  39. queryParams: {
  40. pageNo: 1,
  41. pageSize: 10
  42. },
  43. couponList: [],
  44. total: 0
  45. }
  46. },
  47. watch: {
  48. status: function() {
  49. this.getCouponList()
  50. }
  51. },
  52. // #ifndef H5
  53. mounted() {
  54. this.getCouponList()
  55. },
  56. // #endif
  57. methods: {
  58. select(item) {
  59. this.$emit('select', item)
  60. },
  61. //获取优惠券列表
  62. getCouponList() {
  63. let params = {
  64. ...this.queryParams,
  65. type: 0, // type:0-抵扣 1-代金券
  66. }
  67. // todo: check “已过期”
  68. // status: 0-未使用 1-已使用
  69. if (this.status === 'all') {
  70. delete params.status
  71. } else {
  72. params.status = this.status
  73. }
  74. this.$api('queryVouchersList', params, res => {
  75. if (res.code == 200) {
  76. this.couponList = res.result.records
  77. this.total = res.result.total
  78. }
  79. })
  80. },
  81. //格式化年月日
  82. formatDate(date) {
  83. if(!date){
  84. return ''
  85. }
  86. date = new Date(date.replace(/-/g,'/'));
  87. // const year = date.getFullYear();
  88. const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要加1,并且确保是两位数
  89. const day = String(date.getDate()).padStart(2, '0'); // 确保日期是两位数
  90. return `${month}-${day}`;
  91. },
  92. // 加载更多
  93. moreCoupon() {
  94. if (this.queryParams.pageSize > this.total) return
  95. this.queryParams.pageSize += 10
  96. this.getCouponList()
  97. },
  98. },
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. .list {
  103. padding: 32rpx 50rpx;
  104. &-item {
  105. width: 100%;
  106. height: 211rpx;
  107. position: relative;
  108. &-bg {
  109. width: 100%;
  110. height: 100%;
  111. }
  112. &-count {
  113. position: absolute;
  114. top: 40rpx;
  115. left: 48rpx;
  116. color: $uni-color-light;
  117. font-size: 78rpx;
  118. font-weight: 900;
  119. line-height: 110rpx;
  120. }
  121. &-deadline {
  122. position: absolute;
  123. bottom: 58rpx;
  124. left: 156rpx;
  125. color: $uni-color-light;
  126. font-size: 22rpx;
  127. }
  128. }
  129. }
  130. </style>