index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <template>
  2. <!-- 优惠券页面 -->
  3. <view class="page">
  4. <!-- 标签页 -->
  5. <view class="tabs">
  6. <view v-for="(tab, index) in tabs" :key="index"
  7. :class="['tab-item', { 'tab-item--active': currentTab === index }]" @click="handleTabChange(index)">
  8. {{ tab }}
  9. </view>
  10. </view>
  11. <!-- 优惠券列表 -->
  12. <scroll-view class="content" scroll-y>
  13. <view class="coupon-list" v-if="filteredCoupons.length > 0">
  14. <view v-for="(coupon, index) in filteredCoupons" :key="coupon.id || index"
  15. :class="['coupon-card', getCouponCardClass(coupon)]">
  16. <image :src="getFileUrl('img/personal/coupon.png')" mode="widthFix" class="coupon-card-bg"></image>
  17. <image :src="getFileUrl('img/personal/couponLeft.png')" mode="heightFix" class="coupon-card-bgLeft"></image>
  18. <view class="coupon-card-content">
  19. <!-- 左侧金额区域 -->
  20. <view class="coupon-card__left">
  21. <view class="amount-wrapper">
  22. <text class="amount-number">{{ coupon.amount }}</text>
  23. <text class="amount-unit">元</text>
  24. </view>
  25. <text class="condition-text">满{{ coupon.minAmount }}可用</text>
  26. </view>
  27. <!-- 右侧信息区域 -->
  28. <view class="coupon-card__right">
  29. <view class="coupon-info">
  30. <text class="coupon-name">{{ coupon.name }}</text>
  31. <view class="coupon-rules" @click="handleShowRules(coupon)">
  32. 使用规则
  33. <text class="arrow">›</text>
  34. </view>
  35. <text class="coupon-expire">{{ coupon.expireDate }}到期</text>
  36. </view>
  37. <!-- 操作按钮 -->
  38. <view class="coupon-action">
  39. <view v-if="coupon.status === 0" class="action-btn action-btn--use" hover-class="hover-active"
  40. @click="handleUseCoupon(coupon)">
  41. 去使用
  42. </view>
  43. <view v-else-if="coupon.status === 1" class="action-btn action-btn--use" hover-class="hover-active"
  44. @click="handleUseCoupon(coupon)">
  45. 去使用
  46. </view>
  47. <view v-else-if="coupon.status === 2" class="status-text status-text--used">
  48. 已使用
  49. </view>
  50. <view v-else class="status-text status-text--expired">
  51. 已过期
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. <!-- 空状态 -->
  59. <view class="empty-state" v-else>
  60. <image :src="getFileUrl('img/icon/noCoupon.png')" mode="widthFix" class="empty-icon"></image>
  61. <text class="empty-text">暂无优惠券</text>
  62. </view>
  63. </scroll-view>
  64. <!-- 使用规则弹窗 -->
  65. <RulesModal v-model:open="showRulesModal" :couponData="selectedCoupon" @use="handleUseCoupon" />
  66. </view>
  67. </template>
  68. <script setup>
  69. import { onLoad } from "@dcloudio/uni-app";
  70. import { ref, computed } from "vue";
  71. import { go } from "@/utils/utils.js";
  72. import { getFileUrl } from "@/utils/file.js";
  73. import RulesModal from "./components/RulesModal.vue";
  74. // 标签页数据
  75. const tabs = ['未使用', '即将过期', '已使用', '已过期'];
  76. const currentTab = ref(0);
  77. // 弹窗控制
  78. const showRulesModal = ref(false);
  79. const selectedCoupon = ref({
  80. amount: 0,
  81. minAmount: 0,
  82. name: '',
  83. expireDate: '',
  84. validDays: 90,
  85. description: '周一、周五不可用'
  86. });
  87. // 优惠券数据(模拟数据)
  88. const couponList = ref([
  89. {
  90. id: 1,
  91. amount: 1000,
  92. minAmount: 2000,
  93. name: '美食必吃套餐专享券',
  94. expireDate: '2024/07/28',
  95. status: 0 // 0: 未使用, 1: 即将过期, 2: 已使用, 3: 已过期
  96. },
  97. {
  98. id: 2,
  99. amount: 38,
  100. minAmount: 158,
  101. name: '美食必吃套餐专享券',
  102. expireDate: '2024/07/28',
  103. status: 0
  104. },
  105. {
  106. id: 3,
  107. amount: 999,
  108. minAmount: 2000,
  109. name: '美食必吃套餐专享券',
  110. expireDate: '2024/07/28',
  111. status: 0
  112. },
  113. {
  114. id: 4,
  115. amount: 5,
  116. minAmount: 158,
  117. name: '美食必吃套餐专享券',
  118. expireDate: '2024/07/28',
  119. status: 0
  120. }
  121. ]);
  122. // 根据当前标签页过滤优惠券
  123. const filteredCoupons = computed(() => {
  124. return couponList.value.filter(coupon => {
  125. if (currentTab.value === 0) return coupon.status === 0;
  126. if (currentTab.value === 1) return coupon.status === 1;
  127. if (currentTab.value === 2) return coupon.status === 2;
  128. if (currentTab.value === 3) return coupon.status === 3;
  129. return true;
  130. });
  131. });
  132. // 切换标签页
  133. const handleTabChange = (index) => {
  134. currentTab.value = index;
  135. };
  136. // 获取优惠券卡片样式类
  137. const getCouponCardClass = (coupon) => {
  138. if (coupon.status === 2) return 'coupon-card--used';
  139. if (coupon.status === 3) return 'coupon-card--expired';
  140. return '';
  141. };
  142. // 使用优惠券
  143. const handleUseCoupon = (coupon) => {
  144. console.log('使用优惠券:', coupon);
  145. // 跳转到点餐页面
  146. go('/pages/orderFood/index');
  147. };
  148. // 查看使用规则
  149. const handleShowRules = (coupon) => {
  150. selectedCoupon.value = {
  151. ...coupon,
  152. validDays: 90,
  153. description: '周一、周五不可用'
  154. };
  155. showRulesModal.value = true;
  156. };
  157. onLoad(() => {
  158. // 页面加载时获取优惠券列表
  159. // TODO: 调用API获取真实数据
  160. });
  161. </script>
  162. <style lang="scss" scoped>
  163. .page {
  164. min-height: 100vh;
  165. background: #F5F5F5;
  166. display: flex;
  167. flex-direction: column;
  168. }
  169. .header {
  170. background: #FFFFFF;
  171. padding: 20rpx 30rpx;
  172. padding-top: calc(20rpx + env(safe-area-inset-top));
  173. .header-title {
  174. font-size: 36rpx;
  175. font-weight: bold;
  176. color: #151515;
  177. text-align: center;
  178. }
  179. }
  180. .tabs {
  181. background: #FFFFFF;
  182. display: flex;
  183. align-items: center;
  184. padding: 0 30rpx;
  185. .tab-item {
  186. flex: 1;
  187. text-align: center;
  188. font-size: 28rpx;
  189. color: #666666;
  190. padding: 28rpx 0;
  191. position: relative;
  192. transition: all 0.3s;
  193. &--active {
  194. color: #151515;
  195. font-weight: bold;
  196. &::after {
  197. content: '';
  198. position: absolute;
  199. bottom: 20rpx;
  200. left: 50%;
  201. transform: translateX(-50%);
  202. width: 40rpx;
  203. height: 6rpx;
  204. background: linear-gradient(90deg, #FF8A57 0%, #F47D1F 100%);
  205. border-radius: 3rpx;
  206. }
  207. }
  208. }
  209. }
  210. .content {
  211. flex: 1;
  212. padding: 24rpx 30rpx;
  213. padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
  214. box-sizing: border-box;
  215. }
  216. .coupon-list {
  217. position: relative;
  218. .coupon-card-bg {
  219. position: absolute;
  220. top: 0;
  221. left: 0;
  222. width: 100%;
  223. height: 100%;
  224. z-index: 1;
  225. }
  226. .coupon-card-bgLeft {
  227. position: absolute;
  228. top: 0;
  229. left: 0;
  230. width: auto;
  231. height: 190rpx;
  232. z-index: 1;
  233. }
  234. .coupon-card-content {
  235. position: relative;
  236. z-index: 3;
  237. display: flex;
  238. align-items: center;
  239. }
  240. .coupon-card {
  241. display: flex;
  242. align-items: center;
  243. margin-bottom: 24rpx;
  244. overflow: hidden;
  245. position: relative;
  246. box-sizing: border-box;
  247. position: relative;
  248. z-index: 3;
  249. &:last-child {
  250. margin-bottom: 0;
  251. }
  252. &__left {
  253. width: 200rpx;
  254. padding: 32rpx 0;
  255. display: flex;
  256. flex-direction: column;
  257. align-items: center;
  258. justify-content: center;
  259. .amount-wrapper {
  260. display: flex;
  261. align-items: baseline;
  262. margin-bottom: 8rpx;
  263. .amount-number {
  264. font-size: 64rpx;
  265. font-weight: bold;
  266. color: #F47D1F;
  267. line-height: 1;
  268. }
  269. .amount-unit {
  270. font-size: 28rpx;
  271. color: #F47D1F;
  272. margin-left: 4rpx;
  273. }
  274. }
  275. .condition-text {
  276. font-size: 22rpx;
  277. color: #F47D1F;
  278. }
  279. }
  280. &__divider {
  281. width: 2rpx;
  282. height: 100%;
  283. position: relative;
  284. .dash-line {
  285. width: 2rpx;
  286. height: 100%;
  287. // background-image: linear-gradient(to bottom, #FFD9C2 0%, #FFD9C2 50%, transparent 50%, transparent 100%);
  288. background-size: 2rpx 12rpx;
  289. background-repeat: repeat-y;
  290. }
  291. }
  292. &__right {
  293. flex: 1;
  294. display: flex;
  295. align-items: center;
  296. justify-content: space-between;
  297. padding: 32rpx 24rpx;
  298. .coupon-info {
  299. flex: 1;
  300. display: flex;
  301. flex-direction: column;
  302. .coupon-name {
  303. font-size: 28rpx;
  304. font-weight: bold;
  305. color: #151515;
  306. margin-bottom: 12rpx;
  307. }
  308. .coupon-rules {
  309. font-size: 22rpx;
  310. color: #999999;
  311. margin-bottom: 12rpx;
  312. display: flex;
  313. align-items: center;
  314. .arrow {
  315. font-size: 28rpx;
  316. margin-left: 4rpx;
  317. }
  318. }
  319. .coupon-expire {
  320. font-size: 22rpx;
  321. color: #999999;
  322. }
  323. }
  324. .coupon-action {
  325. margin-left: 20rpx;
  326. .action-btn {
  327. width: 120rpx;
  328. height: 56rpx;
  329. border-radius: 28rpx;
  330. display: flex;
  331. align-items: center;
  332. justify-content: center;
  333. font-size: 26rpx;
  334. font-weight: 500;
  335. &--use {
  336. // background: linear-gradient(135deg, #FF8A57 0%, #F47D1F 100%);
  337. background: #F47D1F;
  338. color: #FFFFFF;
  339. // box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(255, 107, 53, 0.3);
  340. }
  341. }
  342. .status-text {
  343. font-size: 24rpx;
  344. padding: 8rpx 16rpx;
  345. &--used {
  346. color: #999999;
  347. }
  348. &--expired {
  349. color: #CCCCCC;
  350. }
  351. }
  352. }
  353. }
  354. // 已使用状态
  355. &--used {
  356. background: #F8F8F8;
  357. .coupon-card__left {
  358. .amount-number,
  359. .amount-unit,
  360. .condition-text {
  361. color: #CCCCCC;
  362. }
  363. }
  364. .coupon-card__right {
  365. .coupon-info {
  366. .coupon-name,
  367. .coupon-rules,
  368. .coupon-expire {
  369. color: #CCCCCC;
  370. }
  371. }
  372. }
  373. }
  374. // 已过期状态
  375. &--expired {
  376. background: #F8F8F8;
  377. .coupon-card__left {
  378. .amount-number,
  379. .amount-unit,
  380. .condition-text {
  381. color: #CCCCCC;
  382. }
  383. }
  384. .coupon-card__right {
  385. .coupon-info {
  386. .coupon-name,
  387. .coupon-rules,
  388. .coupon-expire {
  389. color: #CCCCCC;
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. .hover-active {
  397. opacity: 0.8;
  398. transform: scale(0.98);
  399. }
  400. .empty-state {
  401. display: flex;
  402. flex-direction: column;
  403. align-items: center;
  404. justify-content: center;
  405. padding-top: 200rpx;
  406. .empty-icon {
  407. width: 300rpx;
  408. height: 280rpx;
  409. margin-bottom: 40rpx;
  410. }
  411. .empty-text {
  412. font-size: 28rpx;
  413. color: #AAAAAA;
  414. }
  415. }
  416. </style>