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

118 lines
2.9 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: 100rpx;" 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: 100rpx;" 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: 100rpx;" 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 { unusedCoupons, usedCoupons, expiredCoupons } from '@/static/js/mockCoupon.js'
  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. unusedCoupons: [],
  49. usedCoupons: [],
  50. expiredCoupons: []
  51. }
  52. },
  53. onLoad() {
  54. // 从mock数据获取优惠券列表
  55. this.unusedCoupons = unusedCoupons
  56. this.usedCoupons = usedCoupons
  57. // 暂时 没有已过期的优惠卷
  58. // this.expiredCoupons = expiredCoupons
  59. },
  60. methods: {
  61. // 切换标签页
  62. changeTab(item) {
  63. this.currentTab = item.index
  64. },
  65. // 使用优惠券
  66. useCoupon(coupon) {
  67. uni.showModal({
  68. title: '提示',
  69. content: `确定使用面值${coupon.amount}元的优惠券吗?`,
  70. success: (res) => {
  71. // 模拟使用优惠券
  72. uni.showLoading({
  73. title: '使用中...'
  74. })
  75. setTimeout(() => {
  76. uni.hideLoading()
  77. uni.showToast({
  78. title: '使用成功',
  79. icon: 'success'
  80. })
  81. setTimeout(() => {
  82. if (res.confirm) {
  83. this.$utils.navigateTo('/pages/order/index')
  84. }
  85. }, 1000)
  86. }, 1000)
  87. }
  88. })
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. .page {
  95. .tabs-container {
  96. .coupon-list {
  97. padding: 30rpx;
  98. }
  99. .empty-tip {
  100. text-align: center;
  101. color: $uni-color-third;
  102. padding: 100rpx 0;
  103. font-size: 28rpx;
  104. }
  105. }
  106. }
  107. </style>