CouponModal.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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" class="coupon-card">
  14. <!-- 左侧金额信息:数字大号,“元/折”小号 -->
  15. <view class="coupon-card__left">
  16. <view class="amount-row">
  17. <text class="amount-num">{{ amountNum(coupon) }}</text>
  18. <text class="amount-unit">{{ amountUnit(coupon) }}</text>
  19. </view>
  20. <text class="condition-text">{{ (coupon.minAmount && Number(coupon.minAmount) > 0) ? ('满' + coupon.minAmount + '可用') : '无门槛' }}</text>
  21. </view>
  22. <!-- 中间信息 -->
  23. <view class="coupon-card__center">
  24. <text class="name-text">{{ coupon.name }}</text>
  25. <text class="expire-text">{{ formatExpireDate(coupon.expireDate) }}到期</text>
  26. </view>
  27. </view>
  28. </scroll-view>
  29. <!-- 无数据时显示 -->
  30. <view class="no-coupon-tip" v-if="couponList.length === 0">
  31. <image :src="getFileUrl('img/icon/noCoupon.png')" mode="widthFix" class="no-coupon-tip-img"></image>
  32. <view class="no-coupon-tip-text">暂无优惠券</view>
  33. </view>
  34. </view>
  35. </BasicModal>
  36. </template>
  37. <script setup>
  38. import { computed } from 'vue';
  39. import BasicModal from '@/components/Modal/BasicModal.vue';
  40. import { getFileUrl } from '@/utils/file.js';
  41. const props = defineProps({
  42. open: {
  43. type: Boolean,
  44. default: false
  45. },
  46. couponList: {
  47. type: Array,
  48. default: () => []
  49. }
  50. });
  51. const emit = defineEmits(['update:open', 'close']);
  52. const getOpen = computed({
  53. get: () => props.open,
  54. set: (val) => emit('update:open', val)
  55. });
  56. // 格式化到期日期
  57. const formatExpireDate = (date) => {
  58. if (!date) return '';
  59. // 如果是字符串格式的日期,转换为 YYYY/MM/DD 格式
  60. if (typeof date === 'string') {
  61. const d = new Date(date);
  62. if (!isNaN(d.getTime())) {
  63. const year = d.getFullYear();
  64. const month = String(d.getMonth() + 1).padStart(2, '0');
  65. const day = String(d.getDate()).padStart(2, '0');
  66. return `${year}/${month}/${day}`;
  67. }
  68. // 如果已经是 YYYY/MM/DD 格式,直接返回
  69. if (date.includes('/')) {
  70. return date;
  71. }
  72. }
  73. return date;
  74. };
  75. // 金额数字与单位分开展示,单位用小字号
  76. const amountNum = (coupon) => {
  77. const str = coupon.amountDisplay || (coupon.amount + '元');
  78. return str.length > 0 ? str.slice(0, -1) : '';
  79. };
  80. const amountUnit = (coupon) => {
  81. const str = coupon.amountDisplay || (coupon.amount + '元');
  82. return str.length > 0 ? str.slice(-1) : '元';
  83. };
  84. // 处理关闭
  85. const handleClose = () => {
  86. getOpen.value = false;
  87. emit('close');
  88. };
  89. const copyUrl = () => {
  90. uni.setClipboardData({
  91. data: 'http:https://modao.cc/proto/KQv3fh5Kt7fy7tfvLMTCx/sharing?view_mode=read_only',
  92. success: () => {
  93. uni.showToast({
  94. title: '复制成功',
  95. icon: 'none'
  96. });
  97. }
  98. });
  99. };
  100. </script>
  101. <style scoped lang="scss">
  102. .coupon-modal {
  103. width: 100%;
  104. background: #F2F4F8;
  105. border-radius: 24rpx 24rpx 0 0;
  106. padding: 0;
  107. box-sizing: border-box;
  108. max-height: 80vh;
  109. display: flex;
  110. flex-direction: column;
  111. overflow: hidden;
  112. &__header {
  113. position: relative;
  114. display: flex;
  115. align-items: center;
  116. justify-content: center;
  117. height: 88rpx;
  118. background: #F2F4F8;
  119. .header-title {
  120. font-size: 32rpx;
  121. font-weight: bold;
  122. color: #151515;
  123. }
  124. .header-close {
  125. position: absolute;
  126. right: 30rpx;
  127. top: 50%;
  128. transform: translateY(-50%);
  129. width: 60rpx;
  130. height: 60rpx;
  131. display: flex;
  132. align-items: center;
  133. justify-content: center;
  134. .close-icon {
  135. width: 26rpx;
  136. height: 26rpx;
  137. }
  138. }
  139. }
  140. &__list {
  141. flex: 1;
  142. padding: 24rpx 30rpx;
  143. padding-bottom: calc(140rpx + env(safe-area-inset-bottom));
  144. box-sizing: border-box;
  145. overflow-y: auto;
  146. min-height: 0;
  147. }
  148. }
  149. .coupon-card {
  150. height: 191rpx;
  151. background: #FFFFFF;
  152. border: 1rpx solid #FFFFFF;
  153. display: flex;
  154. align-items: center;
  155. border-radius: 24rpx;
  156. padding: 28rpx 24rpx;
  157. margin-bottom: 22rpx;
  158. box-sizing: border-box;
  159. position: relative;
  160. &:last-child {
  161. margin-bottom: 0;
  162. }
  163. &__left {
  164. display: flex;
  165. flex-direction: column;
  166. align-items: center;
  167. margin-right: 24rpx;
  168. min-width: 120rpx;
  169. text-align: center;
  170. .amount-row {
  171. display: flex;
  172. align-items: baseline;
  173. justify-content: center;
  174. margin-bottom: 8rpx;
  175. }
  176. .amount-num {
  177. font-size: 50rpx;
  178. font-weight: 600;
  179. color: #F47D1F;
  180. line-height: 1.2;
  181. }
  182. .amount-unit {
  183. font-size: 28rpx;
  184. font-weight: 500;
  185. color: #F47D1F;
  186. margin-left: 2rpx;
  187. }
  188. .condition-text {
  189. font-size: 24rpx;
  190. color: #F47D1F;
  191. line-height: 1.2;
  192. }
  193. }
  194. &__center {
  195. flex: 1;
  196. display: flex;
  197. flex-direction: column;
  198. align-items: flex-start;
  199. margin-right: 20rpx;
  200. .name-text {
  201. font-size: 28rpx;
  202. color: #151515;
  203. font-weight: bold;
  204. line-height: 1.4;
  205. margin-bottom: 8rpx;
  206. }
  207. .expire-text {
  208. font-size: 22rpx;
  209. color: #666666;
  210. line-height: 1.4;
  211. margin-top: 20rpx;
  212. }
  213. }
  214. }
  215. .no-coupon-tip {
  216. height: 700rpx;
  217. text-align: center;
  218. padding-top: 40rpx;
  219. background: transparent;
  220. .no-coupon-tip-img {
  221. width: 343rpx;
  222. height: 322rpx;
  223. }
  224. .no-coupon-tip-text {
  225. font-size: 27rpx;
  226. color: #AAAAAA;
  227. margin-top: -100rpx;
  228. }
  229. .no-coupon-tip-url {
  230. width: 100%;
  231. padding: 0 80rpx;
  232. font-size: 27rpx;
  233. color: #AAAAAA;
  234. margin-top: 20rpx;
  235. text-align: left;
  236. .no-coupon-tip-url-text {
  237. color: #6C8FF8;
  238. }
  239. }
  240. }
  241. </style>