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

159 lines
3.5 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 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" :class="[getDisabled(item) ? 'is-disabled' : '']" 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. maxLimit: {
  37. type: Number,
  38. default: null,
  39. }
  40. },
  41. data() {
  42. return {
  43. queryParams: {
  44. pageNo: 1,
  45. pageSize: 10
  46. },
  47. couponList: [],
  48. total: 0
  49. }
  50. },
  51. watch: {
  52. status: function() {
  53. this.getCouponList()
  54. }
  55. },
  56. // #ifndef H5
  57. mounted() {
  58. this.getCouponList()
  59. },
  60. // #endif
  61. methods: {
  62. getDisabled(item) {
  63. return this.maxLimit && (item.discountAmount > this.maxLimit)
  64. },
  65. select(item) {
  66. if (this.getDisabled(item)) {
  67. return
  68. }
  69. this.$emit('select', item)
  70. },
  71. //获取优惠券列表
  72. getCouponList() {
  73. let params = {
  74. ...this.queryParams,
  75. type: 0, // type:0-抵扣 1-代金券
  76. }
  77. // todo: check “已过期”
  78. // status: 0-未使用 1-已使用
  79. if (this.status === 'all') {
  80. delete params.status
  81. } else {
  82. params.status = this.status
  83. }
  84. this.$api('queryVouchersList', params, res => {
  85. if (res.code == 200) {
  86. this.couponList = res.result.records
  87. this.total = res.result.total
  88. }
  89. })
  90. },
  91. //格式化年月日
  92. formatDate(date) {
  93. if(!date){
  94. return ''
  95. }
  96. date = new Date(date.replace(/-/g,'/'));
  97. // const year = date.getFullYear();
  98. const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要加1,并且确保是两位数
  99. const day = String(date.getDate()).padStart(2, '0'); // 确保日期是两位数
  100. return `${month}-${day}`;
  101. },
  102. // 加载更多
  103. moreCoupon() {
  104. if (this.queryParams.pageSize > this.total) return
  105. this.queryParams.pageSize += 10
  106. this.getCouponList()
  107. },
  108. },
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. .list {
  113. padding: 32rpx 50rpx;
  114. &-item {
  115. width: 100%;
  116. height: 211rpx;
  117. position: relative;
  118. &.is-disabled {
  119. opacity: 0.5;
  120. }
  121. &-bg {
  122. width: 100%;
  123. height: 100%;
  124. }
  125. &-count {
  126. position: absolute;
  127. top: 40rpx;
  128. left: 48rpx;
  129. color: $uni-color-light;
  130. font-size: 78rpx;
  131. font-weight: 900;
  132. line-height: 110rpx;
  133. }
  134. &-deadline {
  135. position: absolute;
  136. bottom: 58rpx;
  137. left: 156rpx;
  138. color: $uni-color-light;
  139. font-size: 22rpx;
  140. }
  141. }
  142. }
  143. </style>