CouponModal.vue 6.2 KB

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