CouponModal.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <BasicModal type="bottom" v-model:open="getOpen" :isMack="true">
  3. <view class="coupon-modal">
  4. <!-- 顶部标题栏 -->
  5. <view class="coupon-modal__header">
  6. <text class="header-title">优惠券</text>
  7. <view class="header-close" @click="handleClose">
  8. <image :src="getFileUrl('img/icon/close.png')" mode="aspectFill" class="close-icon"></image>
  9. </view>
  10. </view>
  11. <!-- 优惠券列表 -->
  12. <scroll-view class="coupon-modal__list" scroll-y v-if="couponList.length > 0">
  13. <view v-for="(coupon, index) in couponList" :key="coupon.id || index"
  14. :class="['coupon-card', { 'coupon-card--received': coupon.isReceived }]">
  15. <!-- 左侧金额信息 -->
  16. <view class="coupon-card__left">
  17. <text class="amount-text">{{ coupon.amount }}元</text>
  18. <text class="condition-text">满{{ coupon.minAmount }}可用</text>
  19. </view>
  20. <!-- 中间信息 -->
  21. <view class="coupon-card__center">
  22. <text class="name-text">{{ coupon.name }}</text>
  23. <text class="expire-text">{{ formatExpireDate(coupon.expireDate) }}到期</text>
  24. </view>
  25. <!-- 右侧操作区域 -->
  26. <view class="coupon-card__right">
  27. <!-- 未领取:显示领取按钮 -->
  28. <view v-if="!coupon.isReceived" class="receive-btn" @click="handleReceive(coupon, index)"
  29. hover-class="hover-active">
  30. 领取
  31. </view>
  32. <!-- 已领取:显示已领取标记 -->
  33. <image :src="getFileUrl('img/icon/ylq.png')" mode="widthFix" v-else class="received-mark-img"></image>
  34. </view>
  35. </view>
  36. </scroll-view>
  37. <!-- 没有优惠券 -->
  38. <view class="no-coupon-tip" v-if="couponList.length === 0">
  39. <image :src="getFileUrl('img/icon/noCoupon.png')" mode="widthFix" class="no-coupon-tip-img"></image>
  40. <view class="no-coupon-tip-text">暂无优惠券</view>
  41. <view class="no-coupon-tip-url">您可以去
  42. <text
  43. class="no-coupon-tip-url-text" @click='copyUrl'>http:https://modao.cc/proto/KQv3fh5Kt7fy7tfvLMTCx/sharing?view_mode=read_only</text>
  44. 进行下载领取优惠券
  45. </view>
  46. </view>
  47. </view>
  48. </BasicModal>
  49. </template>
  50. <script setup>
  51. import { computed } from 'vue';
  52. import BasicModal from '@/components/Modal/BasicModal.vue';
  53. import { getFileUrl } from '@/utils/file.js';
  54. const props = defineProps({
  55. open: {
  56. type: Boolean,
  57. default: false
  58. },
  59. couponList: {
  60. type: Array,
  61. default: () => []
  62. }
  63. });
  64. const emit = defineEmits(['update:open', 'receive', 'close']);
  65. const getOpen = computed({
  66. get: () => props.open,
  67. set: (val) => emit('update:open', val)
  68. });
  69. // 格式化到期日期
  70. const formatExpireDate = (date) => {
  71. if (!date) return '';
  72. // 如果是字符串格式的日期,转换为 YYYY/MM/DD 格式
  73. if (typeof date === 'string') {
  74. const d = new Date(date);
  75. if (!isNaN(d.getTime())) {
  76. const year = d.getFullYear();
  77. const month = String(d.getMonth() + 1).padStart(2, '0');
  78. const day = String(d.getDate()).padStart(2, '0');
  79. return `${year}/${month}/${day}`;
  80. }
  81. // 如果已经是 YYYY/MM/DD 格式,直接返回
  82. if (date.includes('/')) {
  83. return date;
  84. }
  85. }
  86. return date;
  87. };
  88. // 处理关闭
  89. const handleClose = () => {
  90. getOpen.value = false;
  91. emit('close');
  92. };
  93. // 处理领取
  94. const handleReceive = (coupon, index) => {
  95. emit('receive', { coupon, index });
  96. };
  97. const copyUrl = () => {
  98. uni.setClipboardData({
  99. data: 'http:https://modao.cc/proto/KQv3fh5Kt7fy7tfvLMTCx/sharing?view_mode=read_only',
  100. success: () => {
  101. uni.showToast({
  102. title: '复制成功',
  103. icon: 'none'
  104. });
  105. }
  106. });
  107. };
  108. </script>
  109. <style scoped lang="scss">
  110. .coupon-modal {
  111. width: 100%;
  112. background: #F2F4F8;
  113. border-radius: 24rpx 24rpx 0 0;
  114. padding: 0;
  115. box-sizing: border-box;
  116. max-height: 80vh;
  117. display: flex;
  118. flex-direction: column;
  119. overflow: hidden;
  120. &__header {
  121. position: relative;
  122. display: flex;
  123. align-items: center;
  124. justify-content: center;
  125. height: 88rpx;
  126. background: #F2F4F8;
  127. .header-title {
  128. font-size: 32rpx;
  129. font-weight: bold;
  130. color: #151515;
  131. }
  132. .header-close {
  133. position: absolute;
  134. right: 30rpx;
  135. top: 50%;
  136. transform: translateY(-50%);
  137. width: 60rpx;
  138. height: 60rpx;
  139. display: flex;
  140. align-items: center;
  141. justify-content: center;
  142. .close-icon {
  143. width: 26rpx;
  144. height: 26rpx;
  145. }
  146. }
  147. }
  148. &__list {
  149. flex: 1;
  150. padding: 24rpx 30rpx;
  151. padding-bottom: calc(140rpx + env(safe-area-inset-bottom));
  152. box-sizing: border-box;
  153. overflow-y: auto;
  154. min-height: 0;
  155. }
  156. }
  157. .coupon-card {
  158. height: 191rpx;
  159. background: #FEF2F2;
  160. border: 1rpx solid #FFFFFF;
  161. display: flex;
  162. align-items: center;
  163. border-radius: 24rpx;
  164. padding: 28rpx 24rpx;
  165. margin-bottom: 22rpx;
  166. box-sizing: border-box;
  167. position: relative;
  168. &:last-child {
  169. margin-bottom: 0;
  170. }
  171. &__left {
  172. display: flex;
  173. flex-direction: column;
  174. // align-items: flex-start;
  175. margin-right: 24rpx;
  176. min-width: 120rpx;
  177. text-align: center;
  178. .amount-text {
  179. font-size: 50rpx;
  180. font-weight: 600;
  181. color: #F47D1F;
  182. line-height: 1.2;
  183. margin-bottom: 8rpx;
  184. }
  185. .condition-text {
  186. font-size: 24rpx;
  187. color: #F47D1F;
  188. line-height: 1.2;
  189. }
  190. }
  191. &__center {
  192. flex: 1;
  193. display: flex;
  194. flex-direction: column;
  195. align-items: flex-start;
  196. margin-right: 20rpx;
  197. .name-text {
  198. font-size: 28rpx;
  199. color: #151515;
  200. font-weight: bold;
  201. line-height: 1.4;
  202. margin-bottom: 8rpx;
  203. }
  204. .expire-text {
  205. font-size: 22rpx;
  206. color: #666666;
  207. line-height: 1.4;
  208. margin-top: 20rpx;
  209. }
  210. }
  211. &__right {
  212. display: flex;
  213. align-items: center;
  214. justify-content: center;
  215. min-width: 100rpx;
  216. .receive-btn {
  217. width: 100rpx;
  218. height: 56rpx;
  219. background: #FF6B35;
  220. border-radius: 28rpx;
  221. display: flex;
  222. align-items: center;
  223. justify-content: center;
  224. font-size: 28rpx;
  225. color: #FFFFFF;
  226. font-weight: 500;
  227. transition: all 0.3s;
  228. &:active {
  229. opacity: 0.8;
  230. transform: scale(0.95);
  231. }
  232. }
  233. .received-mark {
  234. width: 100rpx;
  235. height: 100rpx;
  236. border: 2rpx dashed #CCCCCC;
  237. border-radius: 50%;
  238. display: flex;
  239. align-items: center;
  240. justify-content: center;
  241. background: rgba(255, 255, 255, 0.6);
  242. position: relative;
  243. opacity: 0.7;
  244. .received-text {
  245. font-size: 22rpx;
  246. color: #999999;
  247. transform: rotate(-15deg);
  248. font-weight: 400;
  249. }
  250. }
  251. }
  252. .received-mark-img {
  253. width: 114rpx;
  254. height: 114rpx;
  255. }
  256. &--received {
  257. background: #FFFFFF;
  258. }
  259. }
  260. .no-coupon-tip {
  261. height: 700rpx;
  262. text-align: center;
  263. padding-top: 40rpx;
  264. .no-coupon-tip-img {
  265. width: 343rpx;
  266. height: 322rpx;
  267. }
  268. .no-coupon-tip-text {
  269. font-size: 27rpx;
  270. color: #AAAAAA;
  271. margin-top: -100rpx;
  272. }
  273. .no-coupon-tip-url {
  274. width: 100%;
  275. padding: 0 80rpx;
  276. font-size: 27rpx;
  277. color: #AAAAAA;
  278. margin-top: 20rpx;
  279. text-align: left;
  280. .no-coupon-tip-url-text {
  281. color: #6C8FF8;
  282. }
  283. }
  284. }
  285. </style>