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

177 lines
3.9 KiB

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