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

145 lines
3.5 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
  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. 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. },
  75. // 使用优惠券
  76. useCoupon(coupon) {
  77. if (this.usein) {
  78. uni.showModal({
  79. title: '提示',
  80. content: `确定使用面值${coupon.discount}元的优惠券吗?`,
  81. success: (res) => {
  82. // 模拟使用优惠券
  83. uni.showLoading({
  84. title: '使用中...'
  85. })
  86. setTimeout(() => {
  87. uni.hideLoading()
  88. if (res.confirm) {
  89. uni.showToast({
  90. title: '使用成功',
  91. icon: 'success'
  92. })
  93. this.$store.commit('setCouponData', coupon)
  94. this.$utils.navigateBack()
  95. }
  96. }, 300)
  97. },
  98. fail: (err) => {
  99. console.log('err', err)
  100. }
  101. })
  102. }else {
  103. this.$utils.navigateTo('/pages/index/category')
  104. }
  105. },
  106. // 获取优惠卷
  107. getCoupon() {
  108. this.$api('queryCouponList', {
  109. pageNo: 1,
  110. pageSize: 10000
  111. }, res => {
  112. if (res.code === 200){
  113. this.allCoupons = res.result.records
  114. }
  115. })
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. .page {
  122. .tabs-container {
  123. .coupon-list {
  124. padding: 30rpx;
  125. }
  126. .empty-tip {
  127. text-align: center;
  128. color: $uni-color-third;
  129. padding: 100rpx 0;
  130. font-size: 28rpx;
  131. }
  132. }
  133. }
  134. </style>