敢为人鲜小程序前端代码仓库
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.

136 lines
3.2 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. <template>
  2. <view class="page">
  3. <!-- 导航栏 -->
  4. <navbar title="优惠券" leftClick @leftClick="$utils.navigateBack" bgColor="#019245" color="#fff" />
  5. <!-- 标签页 -->
  6. <uv-sticky bgColor="#fff">
  7. <uv-tabs :list="tabs" @change="changeTab" :scrollable="false" lineColor="#019245"
  8. :activeStyle="{color: '#019245' }" lineWidth="80" lineHeight="6" :inactiveStyle="{color: '#333'}"
  9. :itemStyle="{height: '90rpx'}" />
  10. </uv-sticky>
  11. <!-- 优惠券列表 -->
  12. <view class="coupon-list">
  13. <template v-if="currentTab === 0">
  14. <coupon-item v-for="coupon in unusedCoupons" :key="coupon.id" :coupon="coupon" @use="useCoupon" />
  15. <uv-empty v-if="unusedCoupons.length == 0" text="暂无优惠卷" textSize="30rpx" iconSize="200rpx"
  16. style="padding-top: 200rpx;" icon="list" />
  17. </template>
  18. <template v-if="currentTab === 1">
  19. <coupon-item v-for="coupon in usedCoupons" :key="coupon.id" :coupon="coupon" />
  20. <uv-empty v-if="usedCoupons.length == 0" text="暂无优惠卷" textSize="30rpx" iconSize="200rpx"
  21. style="padding-top: 200rpx;" icon="list" />
  22. </template>
  23. <template v-if="currentTab === 2">
  24. <coupon-item v-for="coupon in expiredCoupons" :key="coupon.id" :coupon="coupon" />
  25. <uv-empty v-if="expiredCoupons.length == 0" text="暂无优惠卷" textSize="30rpx" iconSize="200rpx"
  26. style="padding-top: 200rpx;" icon="list" />
  27. </template>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import navbar from '@/components/base/navbar.vue'
  33. import CouponItem from '@/components/coupon/CouponItem.vue'
  34. export default {
  35. components: {
  36. navbar,
  37. CouponItem
  38. },
  39. data() {
  40. return {
  41. tabs: [
  42. { name: '未使用' },
  43. { name: '已使用' },
  44. { name: '已过期' }
  45. ],
  46. currentTab: 0,
  47. allCoupons: []
  48. }
  49. },
  50. computed: {
  51. unusedCoupons() {
  52. return (this.allCoupons || []).filter(coupon => coupon.status === "0")
  53. },
  54. usedCoupons() {
  55. return (this.allCoupons || []).filter(coupon => coupon.status === "1")
  56. },
  57. expiredCoupons() {
  58. return (this.allCoupons || []).filter(coupon => coupon.status === "2")
  59. }
  60. },
  61. onLoad() {
  62. this.getCoupon()
  63. },
  64. methods: {
  65. // 切换标签页
  66. changeTab(item) {
  67. this.currentTab = item.index
  68. },
  69. // 使用优惠券
  70. useCoupon(coupon) {
  71. uni.showModal({
  72. title: '提示',
  73. content: `确定使用面值${coupon.discount}元的优惠券吗?`,
  74. success: (res) => {
  75. // 模拟使用优惠券
  76. uni.showLoading({
  77. title: '使用中...'
  78. })
  79. setTimeout(() => {
  80. uni.hideLoading()
  81. uni.showToast({
  82. title: '使用成功',
  83. icon: 'success'
  84. })
  85. setTimeout(() => {
  86. if (res.confirm) {
  87. this.$utils.navigateTo('/pages/order/index')
  88. }
  89. }, 1000)
  90. }, 1000)
  91. },
  92. fail: (err) => {
  93. console.log('err', err)
  94. }
  95. })
  96. },
  97. // 获取优惠卷
  98. getCoupon() {
  99. this.$api('queryCouponList', {
  100. pageNo: 1,
  101. pageSize: 10000
  102. }, res => {
  103. if (res.code === 200){
  104. this.allCoupons = res.result.records
  105. }
  106. })
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. .page {
  113. .tabs-container {
  114. .coupon-list {
  115. padding: 30rpx;
  116. }
  117. .empty-tip {
  118. text-align: center;
  119. color: $uni-color-third;
  120. padding: 100rpx 0;
  121. font-size: 28rpx;
  122. }
  123. }
  124. }
  125. </style>