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

322 lines
7.7 KiB

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