Order.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <script setup lang="ts">
  2. import { useI18n } from 'vue-i18n'
  3. import { useOrderPopup } from '~/composables/useOrderPopup'
  4. import OrderCheckSvg from '~/assets/icons/order/check.svg'
  5. import ConfirmDialog from '~/components/common/ConfirmDialog.vue'
  6. const { state, totalPrice, hasDiscount, discountAmount, discountRatePercent, close, confirm, setQuantity } = useOrderPopup()
  7. const { wallet } = useAuth()
  8. const { openRecharge } = useRecharge()
  9. const { t } = useI18n()
  10. const img = useImage()
  11. const walletCoins = computed(() => wallet.value?.goldCoin ?? 0)
  12. const isWalletBalanceEnough = computed(() => totalPrice.value <= walletCoins.value)
  13. const orderConfirmVisible = ref<boolean>(false)
  14. const handleUpdateShow = (value: boolean) => {
  15. if (!value) {
  16. close()
  17. }
  18. }
  19. const handleQuantityChange = (value: number) => {
  20. setQuantity(value)
  21. }
  22. const handleRecharge = () => {
  23. openRecharge()
  24. }
  25. const handleConfirmOpen = () => {
  26. orderConfirmVisible.value = true
  27. }
  28. const handleConfirm = () => {
  29. confirm()
  30. }
  31. const handleCancel = () => {
  32. orderConfirmVisible.value = false
  33. }
  34. </script>
  35. <template>
  36. <van-popup
  37. :show="state.visible"
  38. round
  39. position="bottom"
  40. class="order-popup"
  41. @update:show="handleUpdateShow"
  42. >
  43. <div class="order-popup__container">
  44. <!-- 头像卡片 + 单价、数量、总价 -->
  45. <section class="order-popup__card order-popup__card--profile">
  46. <div class="order-popup__tag truncate">
  47. {{ state.productType }}
  48. </div>
  49. <div class="order-popup__avatar-wrapper">
  50. <div class="order-popup__avatar">
  51. <NuxtImg
  52. :src="state.avatar"
  53. :alt="state.name"
  54. loading="lazy"
  55. :placeholder="img('/avatar.png')"
  56. />
  57. </div>
  58. </div>
  59. <p class="order-popup__name">
  60. {{ state.name }}
  61. </p>
  62. <div class="order-popup__divider" />
  63. <div class="order-popup__price-row">
  64. <div class="order-popup__price-left">
  65. <p class="order-popup__price-label">
  66. {{ t('order.detail.unitPrice') }}
  67. </p>
  68. <div class="order-popup__rate-info">
  69. <span
  70. class="order-popup__coin order-popup__coin--small"
  71. aria-hidden="true"
  72. />
  73. <span class="order-popup__rate-value">
  74. {{ state.rate.toLocaleString() }}
  75. </span>
  76. <span class="order-popup__rate-unit">
  77. / {{ state.unit }}
  78. </span>
  79. </div>
  80. </div>
  81. <template v-if="state.specificQuantity == null">
  82. <CommonStepper
  83. :model-value="state.quantity"
  84. @update:model-value="handleQuantityChange"
  85. />
  86. </template>
  87. <template v-else>
  88. <span class="order-popup__fixed-quantity">
  89. x{{ state.quantity }}
  90. </span>
  91. </template>
  92. </div>
  93. <div
  94. v-if="hasDiscount"
  95. class="order-popup__discount-row"
  96. >
  97. <div class="order-popup__discount-left">
  98. <span class="order-popup__discount-label">{{ t('order.detail.discount') }}</span>
  99. <span class="order-popup__discount-tag">
  100. <span>{{ t('order.detail.discountTagNewOnly') }}</span>
  101. <span class="order-popup__discount-tag-sep" />
  102. <span>{{ discountRatePercent }} {{ t('order.detail.discountTagOff') }}</span>
  103. </span>
  104. </div>
  105. <div class="order-popup__discount-amount">
  106. <span
  107. class="order-popup__coin order-popup__coin--discount"
  108. aria-hidden="true"
  109. />
  110. <span class="order-popup__discount-value">-{{ discountAmount.toLocaleString() }}</span>
  111. </div>
  112. </div>
  113. <div class="order-popup__total-row">
  114. <span class="order-popup__total-label">
  115. {{ t('order.detail.totalLabel') }}
  116. </span>
  117. <div class="order-popup__total">
  118. <span
  119. class="order-popup__coin order-popup__coin--large"
  120. aria-hidden="true"
  121. />
  122. <span class="order-popup__total-value">
  123. {{ totalPrice.toLocaleString() }}
  124. </span>
  125. </div>
  126. </div>
  127. </section>
  128. <!-- 支付方式:钱包 -->
  129. <section class="order-popup__card order-popup__card--wallet">
  130. <div class="order-popup__wallet-main">
  131. <span class="order-popup__wallet-icon" />
  132. <div class="order-popup__wallet-info">
  133. <p class="order-popup__wallet-title">
  134. {{ t('order.detail.wallet') }}
  135. <span
  136. v-if="!isWalletBalanceEnough"
  137. class="order-popup__wallet-status"
  138. >
  139. {{ t('order.detail.walletBalanceNotEnough') }}
  140. </span>
  141. </p>
  142. <p class="order-popup__wallet-balance">
  143. <span
  144. class="order-popup__coin order-popup__coin--small"
  145. aria-hidden="true"
  146. />
  147. <span class="order-popup__wallet-balance-value">
  148. {{ walletCoins.toLocaleString() }}
  149. </span>
  150. </p>
  151. </div>
  152. </div>
  153. <div class="order-popup__wallet-check">
  154. <OrderCheckSvg />
  155. </div>
  156. </section>
  157. <!-- 底部支付按钮 -->
  158. <button
  159. v-if="isWalletBalanceEnough"
  160. type="button"
  161. class="order-popup__pay-btn"
  162. @click="handleConfirmOpen"
  163. >
  164. {{ t('order.detail.payNow') }}
  165. </button>
  166. <button
  167. v-else
  168. type="button"
  169. class="order-popup__pay-btn"
  170. @click="handleRecharge"
  171. >
  172. {{ t('payment.topup.recharge') }}
  173. </button>
  174. </div>
  175. </van-popup>
  176. <ConfirmDialog
  177. v-model:show="orderConfirmVisible"
  178. :title="t('order.confirm.pay.title')"
  179. :confirm-text="t('order.confirm.pay.confirm')"
  180. :cancel-text="t('order.confirm.pay.cancel')"
  181. @confirm="handleConfirm"
  182. @cancel="handleCancel"
  183. />
  184. </template>
  185. <style scoped lang="scss">
  186. .order-popup {
  187. background-color: transparent;
  188. &__container {
  189. position: relative;
  190. padding: 20px 16px 24px;
  191. border-radius: 20px 20px 0 0;
  192. background-color: var(--color-bg-primary);
  193. display: flex;
  194. flex-direction: column;
  195. gap: 12px;
  196. }
  197. &__card {
  198. position: relative;
  199. background-color: #fff;
  200. border-radius: 12px;
  201. padding: 24px 12px 12px;
  202. &--profile {
  203. padding-top: 54px;
  204. }
  205. &--wallet {
  206. display: flex;
  207. align-items: center;
  208. justify-content: space-between;
  209. padding: 10px 12px;
  210. }
  211. }
  212. &__tag {
  213. max-width: px2vw(125);
  214. position: absolute;
  215. top: 0;
  216. left: 0;
  217. padding: 7px 14px;
  218. border-radius: 12px 0 12px 0;
  219. background-image: linear-gradient(90deg, #4ED2FF 0%, #B1EF5D 100%);
  220. font-size: 12px;
  221. font-weight: 600;
  222. color: #fff;
  223. line-height: 1;
  224. }
  225. &__avatar-wrapper {
  226. position: absolute;
  227. top: -8px;
  228. left: 50%;
  229. transform: translateX(-50%);
  230. }
  231. &__avatar {
  232. @include size(60px);
  233. border-radius: 50%;
  234. overflow: hidden;
  235. background: #fff;
  236. display: flex;
  237. align-items: center;
  238. justify-content: center;
  239. img {
  240. width: 96%;
  241. height: 96%;
  242. border-radius: 50%;
  243. object-fit: cover;
  244. display: block;
  245. }
  246. }
  247. &__name {
  248. text-align: center;
  249. font-family: var(--font-title);
  250. font-size: 14px;
  251. font-weight: 600;
  252. color: var(--color-text-primary);
  253. }
  254. &__divider {
  255. margin: 16px 0 12px;
  256. height: 1px;
  257. background-color: #f2f3f5;
  258. }
  259. &__price-row {
  260. display: flex;
  261. align-items: center;
  262. justify-content: space-between;
  263. }
  264. &__price-left {
  265. display: flex;
  266. align-items: center;
  267. gap: 8px;
  268. }
  269. &__price-label {
  270. font-size: 12px;
  271. font-weight: 600;
  272. color: #1d2129;
  273. }
  274. &__discount-row {
  275. display: flex;
  276. align-items: center;
  277. justify-content: space-between;
  278. padding: 6px 0 7px;
  279. margin-top: 12px;
  280. }
  281. &__discount-left {
  282. display: flex;
  283. align-items: center;
  284. gap: 8px;
  285. }
  286. &__discount-label {
  287. font-size: 12px;
  288. font-weight: 600;
  289. color: #1d2129;
  290. }
  291. &__discount-tag {
  292. display: inline-flex;
  293. align-items: center;
  294. gap: 4px;
  295. padding: 4px 6px;
  296. border-radius: 4px;
  297. background-color: #ff6f32;
  298. font-size: 11px;
  299. font-weight: 400;
  300. color: #fff;
  301. line-height: 14px;
  302. &-sep {
  303. width: 1px;
  304. height: 12px;
  305. background-color: rgba(255, 255, 255, 0.5);
  306. }
  307. }
  308. &__discount-amount {
  309. display: flex;
  310. align-items: center;
  311. gap: 4px;
  312. }
  313. &__coin--discount {
  314. @include size(20px);
  315. @include bg('~/assets/images/common/coin.png');
  316. filter: none;
  317. }
  318. &__discount-value {
  319. font-family: var(--font-title);
  320. font-size: 16px;
  321. font-weight: 600;
  322. color: #ff6f32;
  323. line-height: 17px;
  324. }
  325. &__rate-info {
  326. display: flex;
  327. align-items: center;
  328. gap: 3px;
  329. }
  330. &__rate-value {
  331. font-family: var(--font-title);
  332. font-size: 14px;
  333. font-weight: 600;
  334. color: #1d2129;
  335. transform: translateY(1px);
  336. }
  337. &__rate-unit {
  338. font-size: 14px;
  339. color: var(--color-text-secondary);
  340. }
  341. &__total-row {
  342. display: flex;
  343. align-items: center;
  344. justify-content: flex-end;
  345. margin-top: 12px;
  346. }
  347. &__total-label {
  348. margin-right: 8px;
  349. font-size: 14px;
  350. color: #1d2129;
  351. }
  352. &__total {
  353. display: flex;
  354. align-items: center;
  355. gap: 4px;
  356. }
  357. &__coin {
  358. @include bg('~/assets/images/common/coin.png');
  359. &--small {
  360. @include size(14px);
  361. }
  362. &--large {
  363. @include size(18px);
  364. }
  365. }
  366. &__total-value {
  367. font-family: var(--font-title);
  368. font-size: 24px;
  369. font-weight: 600;
  370. color: #1d2129;
  371. }
  372. &__fixed-quantity {
  373. font-size: 14px;
  374. font-weight: 400;
  375. color: #1f2024;
  376. }
  377. &__wallet-icon {
  378. @include size(38px);
  379. @include bg('~/assets/images/order/popup-wallet.png');
  380. }
  381. &__wallet-main {
  382. display: flex;
  383. align-items: center;
  384. gap: 8px;
  385. }
  386. &__wallet-info {
  387. display: flex;
  388. flex-direction: column;
  389. gap: 2px;
  390. }
  391. &__wallet-title {
  392. font-size: 12px;
  393. font-weight: 600;
  394. color: #1d2129;
  395. }
  396. &__wallet-status {
  397. margin-left: 4px;
  398. font-size: 12px;
  399. font-weight: 600;
  400. color: #1d2129;
  401. }
  402. &__wallet-balance {
  403. display: flex;
  404. align-items: center;
  405. gap: 4px;
  406. font-size: 14px;
  407. color: #86909c;
  408. }
  409. &__wallet-balance-value {
  410. font-size: 14px;
  411. }
  412. &__wallet-check {
  413. margin-left: auto;
  414. }
  415. &__pay-btn {
  416. margin-top: 4px;
  417. @include size(100%, 47px);
  418. border: none;
  419. border-radius: 999px;
  420. background-image: linear-gradient(90deg, #2f95ff 0%, #50ffd8 100%);
  421. color: #fff;
  422. font-family: var(--font-title);
  423. font-size: 16px;
  424. font-weight: 600;
  425. display: flex;
  426. align-items: center;
  427. justify-content: center;
  428. cursor: pointer;
  429. -webkit-tap-highlight-color: transparent;
  430. }
  431. }
  432. </style>
  433. <style lang="scss">
  434. .van-popup.order-popup {
  435. overflow-y: unset;
  436. }
  437. </style>