CouponModal.vue 7.0 KB

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