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

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