detail.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. <script setup lang="ts">
  2. import dayjs from 'dayjs'
  3. import CancelSvg from '~/assets/icons/order/cancelled.svg'
  4. import ProcessingSvg from '~/assets/icons/order/processing.svg'
  5. import CompletedSvg from '~/assets/icons/order/completed.svg'
  6. import AcceptedSvg from '~/assets/icons/order/accepted.svg'
  7. import { useI18n } from 'vue-i18n'
  8. import { showToast } from 'vant'
  9. import { useApi } from '~/composables/useApi'
  10. import { skillApi } from '~/api/skill'
  11. import type { SkillOrderInfoDetailVo } from '~/types/api'
  12. import type { FileAttachment } from '~/types/api/skill'
  13. import { mapApiStatus, statusKeyMap, type OrderStatus } from '~/types/order'
  14. import StarRating from '~/components/common/StarRating.vue'
  15. import ConfirmDialog from '~/components/common/ConfirmDialog.vue'
  16. definePageMeta({
  17. auth: true,
  18. })
  19. interface OrderDetail {
  20. id: string
  21. status: OrderStatus
  22. avatar: string
  23. name: string
  24. productType: string
  25. unitPrice: number
  26. unit: string
  27. quantity: number
  28. orderNo: string
  29. time: string
  30. total: number
  31. star?: number
  32. refundApply: boolean
  33. refundReason: string
  34. refundAttachments: FileAttachment[]
  35. customerRemark: string
  36. }
  37. const route = useRoute()
  38. const router = useRouter()
  39. const { t } = useI18n()
  40. const img = useImage()
  41. const { request } = useApi()
  42. const firstOrderDiscountStore = useFirstOrderDiscountStore()
  43. const detail = ref<OrderDetail | null>(null)
  44. const showRatingPopup = ref(false)
  45. const ratingScore = ref(0)
  46. const isRated = computed<boolean>(() => !!detail.value?.star && detail.value.star > 0)
  47. const refundAttachments = computed<FileAttachment[]>(() => {
  48. return (detail.value?.refundAttachments || []).filter(a => !!a?.attachmentUrl)
  49. })
  50. type OrderDetailActionType = 'complete' | 'refund' | 'delete' | 'cancel' | null
  51. const confirmDialogVisible = ref(false)
  52. const pendingAction = ref<OrderDetailActionType>(null)
  53. const confirmTexts = computed(() => {
  54. const type = pendingAction.value
  55. if (!type) {
  56. return {
  57. title: '',
  58. confirm: '',
  59. cancel: '',
  60. }
  61. }
  62. return {
  63. title: t(`order.confirm.${type}.title`),
  64. confirm: t(`order.confirm.${type}.confirm`),
  65. cancel: t(`order.confirm.${type}.cancel`),
  66. }
  67. })
  68. const formatOrderTime = (timestamp: number) => {
  69. return dayjs(timestamp).tz().format('YYYY/MM/DD HH:mm:ss')
  70. }
  71. const hasDiscount = computed(() => {
  72. const d = detail.value
  73. if (!d)
  74. return false
  75. return d.total < d.unitPrice * d.quantity
  76. })
  77. const orderDiscountText = computed(() => {
  78. const d = detail.value
  79. if (!d)
  80. return '-'
  81. const originalTotal = d.unitPrice * d.quantity
  82. if (d.total < originalTotal) {
  83. const discount = originalTotal - d.total
  84. return `-${discount.toLocaleString()}`
  85. }
  86. return '-'
  87. })
  88. const loadOrderDetail = async () => {
  89. const id = route.query.id as string | undefined
  90. if (!id)
  91. return
  92. const res = await request<SkillOrderInfoDetailVo>(() => skillApi.orderDetail({ id }))
  93. if (!res)
  94. return
  95. const order = res.orderInfo
  96. if (!order)
  97. return
  98. detail.value = {
  99. id: order.orderId,
  100. status: mapApiStatus(order.status),
  101. avatar: order.avatar,
  102. name: order.nickname,
  103. productType: order.bizCategoryName,
  104. unitPrice: order.price,
  105. unit: order.unit || '',
  106. quantity: order.purchaseQty,
  107. orderNo: order.orderId,
  108. time: formatOrderTime(order.createTime),
  109. total: order.totalAmount,
  110. star: order.star,
  111. refundApply: order.refundApply,
  112. refundReason: res.reason || '',
  113. refundAttachments: res.attachments || [],
  114. customerRemark: order.customerRemark ?? '',
  115. }
  116. }
  117. const openConfirmDialog = (action: Exclude<OrderDetailActionType, null>) => {
  118. if (!detail.value)
  119. return
  120. resetConfirmState()
  121. pendingAction.value = action
  122. confirmDialogVisible.value = true
  123. }
  124. const handleCompleteOrder = () => {
  125. openConfirmDialog('complete')
  126. }
  127. const handleRefundOrder = () => {
  128. if (!detail.value)
  129. return
  130. router.push(`/order/refund?id=${detail.value.id}`)
  131. }
  132. const handleCancelOrder = () => {
  133. openConfirmDialog('cancel')
  134. }
  135. // const handleDeleteOrder = () => {
  136. // openConfirmDialog('delete')
  137. // }
  138. const handleOpenRating = () => {
  139. showRatingPopup.value = true
  140. }
  141. const handleSubmitRating = async (score: number) => {
  142. const current = detail.value
  143. if (!current || !score)
  144. return
  145. const payload = {
  146. orderId: current.id,
  147. star: score,
  148. }
  149. const res = await request(() => skillApi.orderStar(payload))
  150. if (res !== null) {
  151. ratingScore.value = score
  152. showRatingPopup.value = false
  153. showToast(t('profile.toast.thanksForRating'))
  154. await loadOrderDetail()
  155. }
  156. }
  157. const resetConfirmState = () => {
  158. confirmDialogVisible.value = false
  159. pendingAction.value = null
  160. }
  161. const handleConfirmAction = async () => {
  162. const current = detail.value
  163. const action = pendingAction.value
  164. if (!current || !action)
  165. return
  166. if (action === 'complete') {
  167. const res = await request(() => skillApi.orderFinish({ id: current.id }))
  168. if (res !== null) {
  169. await loadOrderDetail()
  170. await firstOrderDiscountStore.fetchChance()
  171. }
  172. }
  173. else if (action === 'cancel') {
  174. const res = await request(() => skillApi.orderCancel({ id: current.id }))
  175. if (res !== null) {
  176. showToast(t('order.toast.cancelSuccess'))
  177. await loadOrderDetail()
  178. await firstOrderDiscountStore.fetchChance()
  179. }
  180. }
  181. else if (action === 'delete') {
  182. const res = await request(() => skillApi.orderDelete({ id: current.id }))
  183. if (res !== null) {
  184. await firstOrderDiscountStore.fetchChance()
  185. router.back()
  186. }
  187. }
  188. confirmDialogVisible.value = false
  189. }
  190. const handleCancelAction = () => {
  191. confirmDialogVisible.value = false
  192. }
  193. onMounted(() => {
  194. loadOrderDetail()
  195. })
  196. </script>
  197. <template>
  198. <div class="order-detail-page bg-bg-primary">
  199. <CommonHeader :title="t('order.common.myOrders')" />
  200. <main class="order-detail-main">
  201. <section
  202. v-if="detail"
  203. class="order-detail-hero"
  204. :class="[`order-detail-hero--${detail.status}`, { 'order-detail-hero--refunding': detail.refundApply }]"
  205. >
  206. <div class="order-detail-hero__bg" />
  207. <div class="order-detail-hero__status-container">
  208. <StarRating
  209. v-if="detail.status === 'completed' && isRated"
  210. v-model="detail.star"
  211. mode="display"
  212. variant="bordered"
  213. :size="30"
  214. :gap="14"
  215. />
  216. <div
  217. v-if="!detail.refundApply"
  218. class="order-detail-hero__status"
  219. >
  220. <CancelSvg v-if="detail.status === 'cancelled' || detail.status === 'refused'" />
  221. <ProcessingSvg v-if="detail.status === 'processing' || detail.status === 'processed' || detail.status === 'pending'" />
  222. <CompletedSvg v-if="detail.status === 'completed' || detail.status === 'refunded'" />
  223. <AcceptedSvg v-if="detail.status === 'accepted'" />
  224. <span class="order-detail-hero__text">
  225. {{ t(statusKeyMap[detail.status]) }}
  226. </span>
  227. </div>
  228. <div
  229. v-else
  230. class="order-detail-hero__status"
  231. >
  232. <ProcessingSvg />
  233. <span class="order-detail-hero__text">
  234. {{ t('order.refund.refunding') }}
  235. </span>
  236. </div>
  237. </div>
  238. <article class="order-detail-card">
  239. <header class="order-detail-card__header">
  240. <div class="order-detail-card__avatar">
  241. <NuxtImg
  242. :src="detail.avatar"
  243. :alt="detail.name"
  244. loading="lazy"
  245. :placeholder="img('/avatar.png')"
  246. />
  247. </div>
  248. <div class="order-detail-card__info">
  249. <p class="order-detail-card__name">
  250. {{ detail.name }}
  251. </p>
  252. </div>
  253. </header>
  254. <div class="order-detail-card__divider" />
  255. <dl class="order-detail-card__rows">
  256. <div class="order-detail-card__row">
  257. <dt>{{ t('order.detail.productType') }}</dt>
  258. <dd>{{ detail.productType }}</dd>
  259. </div>
  260. <div class="order-detail-card__row">
  261. <dt>{{ t('order.detail.unitPrice') }}</dt>
  262. <dd>
  263. <span
  264. class="order-detail-card__coin-sm"
  265. aria-hidden="true"
  266. />
  267. {{ detail.unitPrice.toLocaleString() }}
  268. </dd>
  269. </div>
  270. <div class="order-detail-card__row">
  271. <dt>{{ t('order.detail.quantity') }}</dt>
  272. <dd>{{ detail.unit }} x{{ detail.quantity }}</dd>
  273. </div>
  274. <div
  275. v-if="hasDiscount"
  276. class="order-detail-card__row"
  277. >
  278. <dt>{{ t('order.detail.discount') }}</dt>
  279. <dd>
  280. <span
  281. class="order-detail-card__coin-sm"
  282. aria-hidden="true"
  283. />
  284. {{ orderDiscountText }}
  285. </dd>
  286. </div>
  287. <div
  288. v-if="detail.customerRemark"
  289. class="order-detail-card__row"
  290. >
  291. <dt>{{ t('order.detail.remark') }}</dt>
  292. <dd>{{ detail.customerRemark || t('order.detail.remarkEmpty') }}</dd>
  293. </div>
  294. <div class="order-detail-card__row">
  295. <dt>{{ t('order.detail.orderNo') }}</dt>
  296. <dd>{{ detail.orderNo }}</dd>
  297. </div>
  298. <div class="order-detail-card__row">
  299. <dt>{{ t('order.detail.purchaseTime') }}</dt>
  300. <dd>{{ detail.time }}</dd>
  301. </div>
  302. </dl>
  303. <div class="order-detail-card__divider" />
  304. <footer class="order-detail-card__footer">
  305. <div class="order-detail-card__total-label">
  306. <span>{{ t('order.detail.totalLabel') }}</span>
  307. <span
  308. class="order-detail-card__coin"
  309. aria-hidden="true"
  310. />
  311. </div>
  312. <p class="order-detail-card__total-value">
  313. {{ detail.total.toLocaleString() }}
  314. </p>
  315. </footer>
  316. <template v-if="detail.refundApply">
  317. <div class="order-detail-refund-card__section">
  318. <p class="order-detail-refund-card__title">
  319. {{ t('order.detail.refundReasonTitle') }}
  320. </p>
  321. <div class="order-detail-refund-card__box">
  322. <p class="order-detail-refund-card__text">
  323. {{ detail.refundReason?.trim() || t('order.detail.refundReasonEmpty') }}
  324. </p>
  325. </div>
  326. </div>
  327. <div class="order-detail-refund-card__section">
  328. <p class="order-detail-refund-card__title">
  329. {{ t('order.detail.refundProofTitle') }}
  330. </p>
  331. <div
  332. v-if="refundAttachments.length"
  333. v-viewer="{
  334. toolbar: false,
  335. navbar: false,
  336. title: false,
  337. movable: true,
  338. zoomable: true,
  339. rotatable: false,
  340. scalable: false,
  341. }"
  342. class="order-detail-refund-grid"
  343. >
  344. <div
  345. v-for="(att, idx) in refundAttachments"
  346. :key="`${att.attachmentUrl || idx}`"
  347. class="order-detail-refund-grid__item"
  348. >
  349. <NuxtImg
  350. :src="att.attachmentUrl || ''"
  351. :alt="att.fileName || `Proof ${idx + 1}`"
  352. loading="lazy"
  353. :placeholder="img('/placeholder.png')"
  354. />
  355. </div>
  356. </div>
  357. <p
  358. v-else
  359. class="order-detail-refund-empty"
  360. >
  361. {{ t('order.detail.refundProofEmpty') }}
  362. </p>
  363. </div>
  364. </template>
  365. </article>
  366. </section>
  367. <section
  368. v-if="detail"
  369. class="order-detail-actions"
  370. >
  371. <template v-if="detail.status === 'pending'">
  372. <button
  373. type="button"
  374. class="order-detail-btn order-detail-btn--secondary"
  375. @click="handleCancelOrder"
  376. >
  377. {{ t('order.detail.cancel') }}
  378. </button>
  379. </template>
  380. <template v-if="detail.status === 'accepted' || detail.status === 'processing' || detail.status === 'processed'">
  381. <button
  382. type="button"
  383. class="order-detail-btn order-detail-btn--secondary"
  384. :class="{ 'order-detail-btn--disabled': detail.refundApply }"
  385. :disabled="detail.refundApply"
  386. @click="handleRefundOrder"
  387. >
  388. {{ t('order.detail.refund') }}
  389. </button>
  390. </template>
  391. <template v-if="detail.status === 'processed'">
  392. <button
  393. type="button"
  394. class="order-detail-btn order-detail-btn--primary"
  395. @click="handleCompleteOrder"
  396. >
  397. {{ t('order.detail.completeOrder') }}
  398. </button>
  399. </template>
  400. <template v-if="detail.status === 'completed'">
  401. <button
  402. v-if="!isRated"
  403. type="button"
  404. class="order-detail-btn order-detail-btn--evaluate"
  405. :class="{ 'order-detail-btn--disabled': isRated }"
  406. @click="handleOpenRating"
  407. >
  408. {{ isRated ? t('order.rating.rated') : t('order.detail.review') }}
  409. </button>
  410. </template>
  411. <!-- <template v-else-if="detail.status === 'cancelled'">
  412. <button
  413. type="button"
  414. class="order-detail-btn order-detail-btn--secondary"
  415. @click="handleDeleteOrder"
  416. >
  417. {{ t('order.detail.delete') }}
  418. </button>
  419. </template> -->
  420. </section>
  421. <PopupOrderRating
  422. v-if="detail"
  423. v-model:show="showRatingPopup"
  424. v-model="ratingScore"
  425. :avatar="detail.avatar"
  426. @submit="handleSubmitRating"
  427. />
  428. <ConfirmDialog
  429. v-if="detail"
  430. v-model:show="confirmDialogVisible"
  431. :title="confirmTexts.title"
  432. :confirm-text="confirmTexts.confirm"
  433. :cancel-text="confirmTexts.cancel"
  434. @confirm="handleConfirmAction"
  435. @cancel="handleCancelAction"
  436. />
  437. </main>
  438. </div>
  439. </template>
  440. <style scoped lang="scss">
  441. .order-detail-page {
  442. min-height: 100vh;
  443. display: flex;
  444. flex-direction: column;
  445. }
  446. .order-detail-main {
  447. flex: 1;
  448. display: flex;
  449. flex-direction: column;
  450. padding-bottom: 80px;
  451. }
  452. .order-detail-refund-card__section {
  453. display: flex;
  454. flex-direction: column;
  455. gap: 8px;
  456. padding: 0 16px;
  457. &:not(:last-child) {
  458. margin-bottom: 16px;
  459. }
  460. }
  461. .order-detail-refund-card__title {
  462. font-size: 14px;
  463. font-weight: 600;
  464. color: #1d2129;
  465. }
  466. .order-detail-refund-card__box {
  467. background: #f9fafb;
  468. border-radius: 12px;
  469. padding: 8px 12px;
  470. }
  471. .order-detail-refund-card__text {
  472. font-size: 14px;
  473. line-height: 16px;
  474. color: #1d2129;
  475. white-space: pre-wrap;
  476. }
  477. .order-detail-refund-grid {
  478. display: grid;
  479. grid-template-columns: repeat(3, 100px);
  480. grid-auto-rows: 100px;
  481. gap: 4px;
  482. }
  483. .order-detail-refund-grid__item {
  484. width: 100px;
  485. height: 100px;
  486. border-radius: 10px;
  487. overflow: hidden;
  488. img {
  489. width: 100%;
  490. height: 100%;
  491. object-fit: cover;
  492. display: block;
  493. }
  494. }
  495. .order-detail-refund-empty {
  496. font-size: 12px;
  497. color: #86909c;
  498. }
  499. .order-detail-hero {
  500. flex: 1;
  501. position: relative;
  502. overflow: hidden;
  503. display: flex;
  504. flex-direction: column;
  505. align-items: center;
  506. padding: 0 16px;
  507. .order-detail-hero__bg {
  508. @include size(100%, 193px);
  509. @include bg('~/assets/images/order/bg-normal.png', 100% 193px);
  510. position: absolute;
  511. inset: 0;
  512. z-index: 0;
  513. }
  514. }
  515. .order-detail-hero--refused,
  516. .order-detail-hero--refunding,
  517. .order-detail-hero--refunded,
  518. .order-detail-hero--cancelled {
  519. .order-detail-hero__bg {
  520. @include bg('~/assets/images/order/bg-cancel.png', 100% 193px);
  521. }
  522. }
  523. .order-detail-hero__status-container {
  524. margin-top: 44px;
  525. z-index: 1;
  526. display: flex;
  527. flex-direction: column;
  528. align-items: center;
  529. gap: 5px;
  530. }
  531. .order-detail-hero__status {
  532. display: flex;
  533. align-items: center;
  534. gap: 8px;
  535. color: var(--color-text-primary);
  536. }
  537. .order-detail-hero__text {
  538. font-family: var(--font-title);
  539. font-size: 24px;
  540. font-weight: 600;
  541. }
  542. .order-detail-card {
  543. width: 100%;
  544. border-radius: 12px;
  545. background: #fff;
  546. box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.02);
  547. padding: 8px 0;
  548. margin-top: 34px;
  549. z-index: 1;
  550. }
  551. .order-detail-card__header {
  552. height: 48px;
  553. padding: 0 12px;
  554. display: flex;
  555. align-items: center;
  556. justify-content: flex-start;
  557. gap: 8px;
  558. }
  559. .order-detail-card__avatar {
  560. @include size(40px);
  561. border-radius: 50%;
  562. overflow: hidden;
  563. flex-shrink: 0;
  564. img {
  565. width: 100%;
  566. height: 100%;
  567. object-fit: cover;
  568. display: block;
  569. }
  570. }
  571. .order-detail-card__name {
  572. font-size: 14px;
  573. font-weight: 600;
  574. color: var(--color-text-primary);
  575. }
  576. .order-detail-card__divider {
  577. width: calc(100% - 24px);
  578. height: 1px;
  579. background: #F2F3F5;
  580. margin: 10px auto;
  581. }
  582. .order-detail-card__rows {
  583. padding: 0 12px;
  584. }
  585. .order-detail-card__row {
  586. display: flex;
  587. align-items: center;
  588. justify-content: space-between;
  589. height: 30px;
  590. font-size: 12px;
  591. color: #1d2129;
  592. }
  593. .order-detail-card__footer {
  594. padding: 0 12px;
  595. height: 38px;
  596. display: flex;
  597. align-items: center;
  598. justify-content: flex-end;
  599. gap: 4px;
  600. }
  601. .order-detail-card__total-label {
  602. display: flex;
  603. align-items: center;
  604. gap: 4px;
  605. font-size: 12px;
  606. color: #1d2129;
  607. }
  608. .order-detail-card__coin {
  609. @include size(18px);
  610. @include bg('~/assets/images/common/coin.png');
  611. }
  612. .order-detail-card__coin-sm {
  613. @include size(14px);
  614. @include bg('~/assets/images/common/coin.png');
  615. display: inline-block;
  616. }
  617. .order-detail-card__total-value {
  618. font-size: 16px;
  619. font-weight: 600;
  620. color: #1d2129;
  621. }
  622. .order-detail-actions {
  623. width: 100%;
  624. position: fixed;
  625. bottom: 18px;
  626. display: flex;
  627. justify-content: center;
  628. gap: 12px;
  629. padding: 0 16px;
  630. }
  631. .order-detail-btn {
  632. flex: 1;
  633. height: 48px;
  634. padding: 0 32px;
  635. border-radius: 100px;
  636. font-size: 16px;
  637. font-weight: 500;
  638. &--disabled {
  639. opacity: 0.5;
  640. cursor: not-allowed;
  641. }
  642. }
  643. .order-detail-btn--secondary {
  644. min-width: 100px;
  645. border: 1px solid #86909c;
  646. color: #4e5969;
  647. }
  648. .order-detail-btn--primary {
  649. flex: 3;
  650. border: none;
  651. background: linear-gradient(90deg, #2f95ff 28.365%, #50ffd8 100%);
  652. color: #fff;
  653. }
  654. .order-detail-btn--evaluate {
  655. flex: 1;
  656. width: 100%;
  657. border-radius: 100px;
  658. border: 1px solid #4ed2ff;
  659. background: rgba(255, 255, 255, 0.7);
  660. color: #3fbfbd;
  661. }
  662. dd {
  663. display: flex;
  664. align-items: center;
  665. gap: 2px;
  666. }
  667. </style>