四零语境前端代码仓库
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.

299 lines
7.0 KiB

1 month ago
  1. <template>
  2. <view class="discount-container">
  3. <!-- 顶部tab切换 -->
  4. <uv-subsection
  5. :list="tabList"
  6. :current="currentTab"
  7. @change="onTabChange"
  8. :activeColor="tabStyle.activeColor"
  9. :inactiveColor="tabStyle.inactiveColor"
  10. :bgColor="tabStyle.bgColor"
  11. :fontSize="tabStyle.fontSize"
  12. :height="tabStyle.height"
  13. ></uv-subsection>
  14. <!-- 优惠券列表 -->
  15. <view class="coupon-list">
  16. <view
  17. v-for="(coupon, index) in currentCoupons"
  18. :key="index"
  19. class="coupon-item"
  20. :class="{
  21. 'used-coupon': coupon.status === 'used',
  22. 'expired-coupon': coupon.status === 'expired'
  23. }"
  24. >
  25. <!-- 左侧金额区域 -->
  26. <view class="coupon-left">
  27. <text class="coupon-symbol">¥</text>
  28. <text class="coupon-amount">{{ coupon.amount }}</text>
  29. <!-- 状态盖章 -->
  30. <image
  31. v-if="coupon.status !== 'available'"
  32. class="status-stamp"
  33. :src="coupon.status === 'used' ? '/static/已使用盖章.png' : '/static/已过期盖章.png'"
  34. mode="aspectFit"
  35. ></image>
  36. </view>
  37. <!-- 右侧信息区域 -->
  38. <view class="coupon-right">
  39. <view class="coupon-title">{{ coupon.title }}</view>
  40. <view class="coupon-expire">有效期至 {{ coupon.expireDate }}</view>
  41. <!-- 使用按钮或状态 -->
  42. <view class="coupon-action">
  43. <uv-button
  44. v-if="coupon.status === 'available'"
  45. :customStyle="buttonStyle"
  46. text="去使用"
  47. @click="useCoupon(coupon)"
  48. ></uv-button>
  49. <view
  50. v-else
  51. class="coupon-status"
  52. :class="{
  53. 'used-status': coupon.status === 'used',
  54. 'expired-status': coupon.status === 'expired'
  55. }"
  56. >
  57. {{ coupon.status === 'used' ? '已使用' : '已过期' }}
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 空状态 -->
  63. <uv-empty
  64. v-if="currentCoupons.length === 0"
  65. text="暂无优惠券"
  66. :textColor="emptyStyle.textColor"
  67. :textSize="emptyStyle.textSize"
  68. :marginTop="emptyStyle.marginTop"
  69. ></uv-empty>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. export default {
  75. data() {
  76. return {
  77. currentTab: 0,
  78. tabList: [
  79. { name: '待使用' },
  80. { name: '已使用' },
  81. { name: '已过期' }
  82. ],
  83. // tab样式配置
  84. tabStyle: {
  85. activeColor: '#06DADC',
  86. inactiveColor: '#999',
  87. bgColor: '#f8f8f8',
  88. fontSize: '28rpx',
  89. height: '80rpx'
  90. },
  91. // 按钮样式配置
  92. buttonStyle: {
  93. backgroundColor: '#06DADC',
  94. borderRadius: '99rpx',
  95. width: '140rpx',
  96. height: '60rpx',
  97. fontSize: '30rpx',
  98. color: '#fff'
  99. },
  100. // 空状态样式配置
  101. emptyStyle: {
  102. textColor: '#999',
  103. textSize: '28rpx',
  104. marginTop: '200rpx'
  105. },
  106. // 优惠券数据
  107. coupons: {
  108. available: [
  109. {
  110. id: 1,
  111. title: '专属福利】20元红包',
  112. amount: 20,
  113. expireDate: '2026-04-28',
  114. status: 'available'
  115. },
  116. {
  117. id: 2,
  118. title: '专属福利】400元红包',
  119. amount: 400,
  120. expireDate: '2026-04-28',
  121. status: 'available'
  122. },
  123. {
  124. id: 3,
  125. title: '专属福利】400元红包',
  126. amount: 400,
  127. expireDate: '2026-04-28',
  128. status: 'available'
  129. }
  130. ],
  131. used: [
  132. {
  133. id: 4,
  134. title: '专属福利】20元红包',
  135. amount: 20,
  136. expireDate: '2026-04-28',
  137. status: 'used'
  138. }
  139. ],
  140. expired: [
  141. {
  142. id: 5,
  143. title: '专属福利】20元红包',
  144. amount: 20,
  145. expireDate: '2026-04-28',
  146. status: 'expired'
  147. }
  148. ]
  149. }
  150. }
  151. },
  152. computed: {
  153. currentCoupons() {
  154. const statusMap = ['available', 'used', 'expired']
  155. return this.coupons[statusMap[this.currentTab]] || []
  156. }
  157. },
  158. methods: {
  159. onTabChange(index) {
  160. this.currentTab = index
  161. },
  162. useCoupon(coupon) {
  163. uni.showToast({
  164. title: '跳转到使用页面',
  165. icon: 'none'
  166. })
  167. }
  168. }
  169. }
  170. </script>
  171. <style lang="scss" scoped>
  172. .discount-container {
  173. min-height: 100vh;
  174. background-color: #f8f8f8;
  175. .coupon-list {
  176. padding: 40rpx 30rpx;
  177. .coupon-item {
  178. display: flex;
  179. background-color: #fff;
  180. border-radius: 24rpx;
  181. margin-bottom: 24rpx;
  182. overflow: hidden;
  183. position: relative;
  184. padding: 8rpx;
  185. // box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
  186. &.used-coupon,
  187. &.expired-coupon {
  188. .coupon-left {
  189. background-color: #E3E3E3;
  190. .coupon-symbol,
  191. .coupon-amount {
  192. color: #FBFBFB;
  193. }
  194. }
  195. }
  196. .coupon-left {
  197. width: 180rpx;
  198. background-color: #FFF2F2;
  199. display: flex;
  200. // flex-direction: column;
  201. align-items: center;
  202. justify-content: center;
  203. border-radius: 16rpx;
  204. position: relative;
  205. .coupon-symbol {
  206. font-size: 24rpx;
  207. color: #FF4800;
  208. font-weight: bold;
  209. margin-bottom: 10rpx;
  210. }
  211. .coupon-amount {
  212. font-size: 48rpx;
  213. color: #FF4800;
  214. font-weight: 500;
  215. line-height: 1.4;
  216. }
  217. .status-stamp {
  218. position: absolute;
  219. bottom: 0rpx;
  220. right: 0rpx;
  221. width: 100rpx;
  222. height: 100rpx;
  223. // opacity: 0.8;
  224. }
  225. }
  226. .coupon-right {
  227. flex: 1;
  228. margin-left: 20rpx;
  229. padding: 40rpx 30rpx 20rpx;
  230. position: relative;
  231. width: 0px;
  232. border-left: 2rpx dashed #DADADA;
  233. .coupon-title {
  234. font-size: 32rpx;
  235. color: #181818;
  236. font-weight: bold;
  237. margin-bottom: 16rpx;
  238. }
  239. .coupon-expire {
  240. font-size: 28rpx;
  241. color: #9B9B9B;
  242. margin-bottom: 16rpx;
  243. }
  244. .coupon-action {
  245. display: flex;
  246. justify-content: flex-start;
  247. .coupon-status {
  248. padding: 10rpx 30rpx;
  249. border-radius: 40rpx;
  250. font-size: 30rpx;
  251. text-align: center;
  252. &.used-status {
  253. background-color: #E3E3E3;
  254. color: #fff;
  255. }
  256. &.expired-status {
  257. background-color: #E3E3E3;
  258. color: #fff;
  259. }
  260. }
  261. }
  262. }
  263. }
  264. }
  265. }
  266. </style>