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

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