RulesModal.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <BasicModal type="bottom" v-model:open="getOpen" :is-mack="true">
  3. <view class="rules-modal">
  4. <!-- 标题栏 -->
  5. <view class="rules-modal__header">
  6. <text class="header-title">使用规则</text>
  7. <view class="close-btn" @click="handleClose">
  8. <view class="close-icon" />
  9. </view>
  10. </view>
  11. <view class="rules-modal__body">
  12. <!-- 券摘要卡片:左金额区 + 右名称/到期 -->
  13. <view class="card card--summary">
  14. <view class="summary-left">
  15. <view class="amount-line">
  16. <text class="amount-num">{{ couponData?.amount ?? 0 }}</text>
  17. <text class="amount-unit">{{ couponData?.amountUnit || '元' }}</text>
  18. </view>
  19. <text class="summary-condition">{{ conditionLine }}</text>
  20. </view>
  21. <view class="summary-right">
  22. <text class="summary-name">{{ couponData?.name || '优惠券' }}</text>
  23. <text class="summary-expire">{{ expireLine }}</text>
  24. </view>
  25. </view>
  26. <!-- 使用须知 -->
  27. <view class="card card--notice">
  28. <text class="card-title">使用须知</text>
  29. <view class="notice-row">
  30. <text class="notice-label">有效期</text>
  31. <text class="notice-value">{{ validityText }}</text>
  32. </view>
  33. <view class="notice-row">
  34. <text class="notice-label">补充说明</text>
  35. <text class="notice-value">{{ supplementText }}</text>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </BasicModal>
  41. </template>
  42. <script setup>
  43. import { computed } from 'vue';
  44. import BasicModal from '@/components/Modal/BasicModal.vue';
  45. const props = defineProps({
  46. open: {
  47. type: Boolean,
  48. default: false
  49. },
  50. couponData: {
  51. type: Object,
  52. default: () => ({})
  53. }
  54. });
  55. const emit = defineEmits(['update:open']);
  56. const getOpen = computed({
  57. get: () => props.open,
  58. set: (val) => emit('update:open', val)
  59. });
  60. const conditionLine = computed(() => {
  61. const c = props.couponData;
  62. if (c?.conditionText) return c.conditionText;
  63. const m = Number(c?.minAmount) || 0;
  64. return m > 0 ? `满${m}可用` : '无门槛';
  65. });
  66. const expireLine = computed(() => {
  67. const c = props.couponData;
  68. if (Number(c?.longTermValid) === 1) return '长期有效';
  69. const d = c?.expirationTime ?? c?.expireDate;
  70. if (d == null || String(d).trim() === '') return '';
  71. return `${String(d).trim()}到期`;
  72. });
  73. /** 从 specifiedDay / validDays 解析天数,用于「领取后*天有效」 */
  74. function parseReceiveValidDays(c) {
  75. const s = c?.specifiedDay ?? c?.validDays;
  76. if (s == null || String(s).trim() === '') return null;
  77. const str = String(s).trim();
  78. const m1 = str.match(/领取后\s*(\d+)\s*天/);
  79. if (m1) {
  80. const n = Number(m1[1]);
  81. return !Number.isNaN(n) && n > 0 ? n : null;
  82. }
  83. const m2 = str.match(/(\d+)\s*天/);
  84. if (m2) {
  85. const n = Number(m2[1]);
  86. return !Number.isNaN(n) && n > 0 ? n : null;
  87. }
  88. const n = Number(str);
  89. if (!Number.isNaN(n) && n > 0) return n;
  90. return null;
  91. }
  92. const validityText = computed(() => {
  93. const c = props.couponData;
  94. if (Number(c?.longTermValid) === 1) return '长期有效';
  95. const days = parseReceiveValidDays(c);
  96. if (days != null) return `领取后${days}天有效`;
  97. return '—';
  98. });
  99. const supplementText = computed(() => {
  100. const t = props.couponData?.supplementaryInstruction;
  101. if (t != null && String(t).trim() !== '') return String(t).trim();
  102. return '暂无说明';
  103. });
  104. function handleClose() {
  105. getOpen.value = false;
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .rules-modal {
  110. width: 100%;
  111. background: #f5f5f5;
  112. border-radius: 24rpx 24rpx 0 0;
  113. padding: 28rpx 0 calc(28rpx + env(safe-area-inset-bottom));
  114. box-sizing: border-box;
  115. max-height: 85vh;
  116. }
  117. .rules-modal__header {
  118. display: flex;
  119. align-items: center;
  120. justify-content: center;
  121. margin-bottom: 24rpx;
  122. padding: 0 30rpx;
  123. position: relative;
  124. .header-title {
  125. font-size: 34rpx;
  126. font-weight: bold;
  127. color: #151515;
  128. }
  129. .close-btn {
  130. position: absolute;
  131. right: 24rpx;
  132. top: 50%;
  133. transform: translateY(-50%);
  134. width: 56rpx;
  135. height: 56rpx;
  136. display: flex;
  137. align-items: center;
  138. justify-content: center;
  139. }
  140. .close-icon {
  141. width: 28rpx;
  142. height: 28rpx;
  143. position: relative;
  144. &::before,
  145. &::after {
  146. content: '';
  147. position: absolute;
  148. width: 28rpx;
  149. height: 3rpx;
  150. background: #999999;
  151. top: 50%;
  152. left: 50%;
  153. transform-origin: center;
  154. }
  155. &::before {
  156. transform: translate(-50%, -50%) rotate(45deg);
  157. }
  158. &::after {
  159. transform: translate(-50%, -50%) rotate(-45deg);
  160. }
  161. }
  162. }
  163. .rules-modal__body {
  164. padding: 0 24rpx;
  165. box-sizing: border-box;
  166. }
  167. .card {
  168. background: #ffffff;
  169. border-radius: 16rpx;
  170. margin-bottom: 20rpx;
  171. overflow: hidden;
  172. box-sizing: border-box;
  173. &:last-child {
  174. margin-bottom: 0;
  175. }
  176. }
  177. .card-title {
  178. display: block;
  179. font-size: 30rpx;
  180. font-weight: bold;
  181. color: #151515;
  182. margin-bottom: 20rpx;
  183. }
  184. /* 券摘要 */
  185. .card--summary {
  186. display: flex;
  187. flex-direction: row;
  188. align-items: stretch;
  189. min-height: 168rpx;
  190. padding: 0;
  191. }
  192. .summary-left {
  193. width: 220rpx;
  194. flex-shrink: 0;
  195. background: #fff4e6;
  196. display: flex;
  197. flex-direction: column;
  198. align-items: center;
  199. justify-content: center;
  200. padding: 24rpx 16rpx;
  201. box-sizing: border-box;
  202. }
  203. .amount-line {
  204. display: flex;
  205. flex-direction: row;
  206. align-items: baseline;
  207. margin-bottom: 10rpx;
  208. }
  209. .amount-num {
  210. font-size: 56rpx;
  211. font-weight: bold;
  212. color: #f47d1f;
  213. line-height: 1;
  214. }
  215. .amount-unit {
  216. font-size: 28rpx;
  217. color: #f47d1f;
  218. margin-left: 4rpx;
  219. }
  220. .summary-condition {
  221. font-size: 22rpx;
  222. color: #f47d1f;
  223. }
  224. .summary-right {
  225. flex: 1;
  226. min-width: 0;
  227. padding: 28rpx 24rpx;
  228. display: flex;
  229. flex-direction: column;
  230. justify-content: center;
  231. background: #ffffff;
  232. }
  233. .summary-name {
  234. font-size: 28rpx;
  235. font-weight: bold;
  236. color: #151515;
  237. line-height: 1.4;
  238. margin-bottom: 12rpx;
  239. }
  240. .summary-expire {
  241. font-size: 24rpx;
  242. color: #999999;
  243. }
  244. /* 使用须知 */
  245. .card--notice {
  246. padding: 28rpx 24rpx 32rpx;
  247. }
  248. .notice-row {
  249. display: flex;
  250. flex-direction: row;
  251. align-items: flex-start;
  252. justify-content: space-between;
  253. margin-bottom: 20rpx;
  254. font-size: 28rpx;
  255. line-height: 1.5;
  256. &:last-child {
  257. margin-bottom: 0;
  258. }
  259. }
  260. .notice-label {
  261. color: #888888;
  262. flex-shrink: 0;
  263. margin-right: 24rpx;
  264. }
  265. .notice-value {
  266. flex: 1;
  267. text-align: right;
  268. color: #151515;
  269. word-break: break-all;
  270. }
  271. </style>