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

148 lines
3.6 KiB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 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" v-if="!usein">
  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. import { mapState } from 'vuex'
  35. export default {
  36. components: {
  37. navbar,
  38. CouponItem
  39. },
  40. data() {
  41. return {
  42. tabs: [
  43. { name: '未使用' },
  44. { name: '已使用' },
  45. { name: '已过期' }
  46. ],
  47. currentTab: 0,
  48. allCoupons: [],
  49. usein: false // 是否是跳进来选择使用的情况
  50. }
  51. },
  52. computed: {
  53. ...mapState(['couponData']),
  54. unusedCoupons() {
  55. return (this.allCoupons || []).filter(coupon => coupon.status === "0")
  56. },
  57. usedCoupons() {
  58. return (this.allCoupons || []).filter(coupon => coupon.status === "1")
  59. },
  60. expiredCoupons() {
  61. return (this.allCoupons || []).filter(coupon => coupon.status === "2")
  62. }
  63. },
  64. onLoad(args) {
  65. this.getCoupon()
  66. if (args.usein === '1') {
  67. this.usein = true
  68. }
  69. },
  70. methods: {
  71. // 切换标签页
  72. changeTab(item) {
  73. this.currentTab = item.index
  74. this.getCoupon()
  75. },
  76. // 使用优惠券
  77. useCoupon(coupon) {
  78. if (this.usein) {
  79. uni.showModal({
  80. title: '提示',
  81. content: `确定使用面值${coupon.discount}元的优惠券吗?`,
  82. confirmColor: '#019245',
  83. success: (res) => {
  84. // 模拟使用优惠券
  85. uni.showLoading({
  86. title: '使用中...'
  87. })
  88. setTimeout(() => {
  89. uni.hideLoading()
  90. if (res.confirm) {
  91. uni.showToast({
  92. title: '使用成功',
  93. icon: 'success'
  94. })
  95. this.$store.commit('setCouponData', coupon)
  96. this.$utils.navigateBack()
  97. }
  98. }, 300)
  99. },
  100. fail: (err) => {
  101. console.log('err', err)
  102. }
  103. })
  104. }else {
  105. this.$utils.navigateTo('/pages/index/category')
  106. }
  107. },
  108. // 获取优惠卷
  109. getCoupon() {
  110. this.$api('queryCouponList', {
  111. pageNo: 1,
  112. pageSize: 10000,
  113. status: this.currentTab
  114. }, res => {
  115. if (res.code === 200){
  116. this.allCoupons = res.result.records
  117. }
  118. })
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .page {
  125. .tabs-container {
  126. .coupon-list {
  127. padding: 30rpx;
  128. }
  129. .empty-tip {
  130. text-align: center;
  131. color: $uni-color-third;
  132. padding: 100rpx 0;
  133. font-size: 28rpx;
  134. }
  135. }
  136. }
  137. </style>