推拿小程序前端代码仓库
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.

139 lines
3.1 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. methods: {
  53. select(item) {
  54. this.$emit('select', item)
  55. },
  56. //获取优惠券列表
  57. getCouponList() {
  58. let params = {
  59. ...this.queryParams,
  60. type: 0, // type:0-抵扣 1-代金券
  61. }
  62. // todo: check “已过期”
  63. // status: 0-未使用 1-已使用
  64. if (this.status === 'all') {
  65. delete params.status
  66. } else {
  67. params.status = this.status
  68. }
  69. this.$api('queryVouchersList', params, res => {
  70. if (res.code == 200) {
  71. this.couponList = res.result.records
  72. this.total = res.result.total
  73. }
  74. })
  75. },
  76. //格式化年月日
  77. formatDate(date) {
  78. if(!date){
  79. return ''
  80. }
  81. date = new Date(date.replace(/-/g,'/'));
  82. // const year = date.getFullYear();
  83. const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要加1,并且确保是两位数
  84. const day = String(date.getDate()).padStart(2, '0'); // 确保日期是两位数
  85. return `${month}-${day}`;
  86. },
  87. // 加载更多
  88. moreCoupon() {
  89. if (this.queryParams.pageSize > this.total) return
  90. this.queryParams.pageSize += 10
  91. this.getCouponList()
  92. },
  93. },
  94. }
  95. </script>
  96. <style lang="scss" scoped>
  97. .list {
  98. padding: 32rpx 50rpx;
  99. &-item {
  100. width: 100%;
  101. height: 211rpx;
  102. position: relative;
  103. &-bg {
  104. width: 100%;
  105. height: 100%;
  106. }
  107. &-count {
  108. position: absolute;
  109. top: 40rpx;
  110. left: 48rpx;
  111. color: $uni-color-light;
  112. font-size: 78rpx;
  113. font-weight: 900;
  114. line-height: 110rpx;
  115. }
  116. &-deadline {
  117. position: absolute;
  118. bottom: 58rpx;
  119. left: 156rpx;
  120. color: $uni-color-light;
  121. font-size: 22rpx;
  122. }
  123. }
  124. }
  125. </style>