优化
This commit is contained in:
@@ -1,37 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { FileUp } from '@lucide/vue'
|
||||
import { ElMessage, type UploadFile } from 'element-plus'
|
||||
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import { getApiErrorDetails, type ApiErrorDetails } from '@/shared/api/http'
|
||||
import AdminPage from '@/shared/components/AdminPage.vue'
|
||||
import OperationErrorToast from '@/shared/components/OperationErrorToast.vue'
|
||||
import AppDialog from '@/shared/components/AppDialog.vue'
|
||||
import LoadingListDetailDrawer from '../components/LoadingListDetailDrawer.vue'
|
||||
import {
|
||||
completeLoadingDeclaration,
|
||||
getConfirmedLoadingList,
|
||||
getLoadingDeclaration,
|
||||
uploadLoadingDeclaration,
|
||||
type ConfirmedSummary,
|
||||
type LoadingDetail,
|
||||
} from '../api/platformLoadingLists'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const access = useAccessPreviewStore()
|
||||
const loading = ref(false)
|
||||
const detail = ref<LoadingDetail<ConfirmedSummary> | null>(null)
|
||||
const error = ref<ApiErrorDetails | null>(null)
|
||||
const customsDialogOpen = ref(false)
|
||||
const customsFile = ref<File | null>(null)
|
||||
const customsSaving = ref(false)
|
||||
const customsError = ref<ApiErrorDetails | null>(null)
|
||||
let loadSequence = 0
|
||||
const planId = computed(() => String(route.params.planId || ''))
|
||||
const warehouseId = computed(() => typeof route.query.warehouseId === 'string' ? route.query.warehouseId : '')
|
||||
const canManageCustoms = computed(() => access.can('platform:firstleg:customs:manage'))
|
||||
|
||||
async function loadDetail() {
|
||||
const sequence = ++loadSequence
|
||||
@@ -44,20 +30,13 @@ async function loadDetail() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const [result, customsDocument] = await Promise.all([
|
||||
getConfirmedLoadingList(planId.value, warehouseId.value),
|
||||
getLoadingDeclaration(planId.value, warehouseId.value).catch((cause) => {
|
||||
const details = getApiErrorDetails(cause)
|
||||
if (details.code === 'A0404') return null
|
||||
throw cause
|
||||
}),
|
||||
])
|
||||
const result = await getConfirmedLoadingList(planId.value, warehouseId.value)
|
||||
if (sequence !== loadSequence) return
|
||||
if (result.summary.status !== 'COMPLETED') {
|
||||
error.value = { code: 'MODE_STATUS_MISMATCH', message: '该计划尚未形成正式装柜清单,请从预装清单入口查看。' }
|
||||
return
|
||||
}
|
||||
detail.value = { ...result, customsDocument }
|
||||
detail.value = result
|
||||
} catch (cause) {
|
||||
if (sequence !== loadSequence) return
|
||||
detail.value = null
|
||||
@@ -72,66 +51,6 @@ function goBack() {
|
||||
else void router.push({ name: 'loading-lists' })
|
||||
}
|
||||
|
||||
function openCustomsDocument() {
|
||||
customsFile.value = null
|
||||
customsError.value = null
|
||||
customsDialogOpen.value = true
|
||||
}
|
||||
|
||||
function selectCustomsFile(uploadFile: UploadFile) {
|
||||
customsFile.value = uploadFile.raw ?? null
|
||||
customsError.value = null
|
||||
}
|
||||
|
||||
function removeCustomsFile() {
|
||||
customsFile.value = null
|
||||
}
|
||||
|
||||
async function uploadCustomsDocument() {
|
||||
if (!detail.value || !customsFile.value) {
|
||||
customsError.value = { code: 'FILE_REQUIRED', message: '请选择报关资料文件' }
|
||||
return
|
||||
}
|
||||
customsSaving.value = true
|
||||
customsError.value = null
|
||||
try {
|
||||
detail.value.customsDocument = await uploadLoadingDeclaration(
|
||||
planId.value,
|
||||
warehouseId.value,
|
||||
customsFile.value,
|
||||
detail.value.customsDocument?.version || 0,
|
||||
'上传装柜清单报关资料',
|
||||
)
|
||||
customsFile.value = null
|
||||
customsDialogOpen.value = false
|
||||
ElMessage.success('报关资料已上传')
|
||||
} catch (cause) {
|
||||
customsError.value = getApiErrorDetails(cause, '报关资料上传失败')
|
||||
} finally {
|
||||
customsSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function completeCustomsDocument() {
|
||||
if (!detail.value?.customsDocument) return
|
||||
customsSaving.value = true
|
||||
customsError.value = null
|
||||
try {
|
||||
detail.value.customsDocument = await completeLoadingDeclaration(
|
||||
planId.value,
|
||||
warehouseId.value,
|
||||
detail.value.customsDocument.version,
|
||||
'确认装柜清单报关完成',
|
||||
)
|
||||
ElMessage.success('已完成报关')
|
||||
} catch (cause) {
|
||||
customsError.value = getApiErrorDetails(cause, '报关完成失败')
|
||||
ElMessage.error(customsError.value.message)
|
||||
} finally {
|
||||
customsSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => void loadDetail())
|
||||
watch([planId, warehouseId], () => void loadDetail())
|
||||
</script>
|
||||
@@ -139,40 +58,16 @@ watch([planId, warehouseId], () => void loadDetail())
|
||||
<template>
|
||||
<AdminPage>
|
||||
<div class="confirmed-loading-detail-page">
|
||||
<OperationErrorToast :details="customsError" />
|
||||
<LoadingListDetailDrawer
|
||||
mode="confirmed"
|
||||
:loading="loading"
|
||||
:detail="detail"
|
||||
:error="error"
|
||||
:can-edit="false"
|
||||
:can-manage-customs="canManageCustoms"
|
||||
:customs-saving="customsSaving"
|
||||
@back="goBack"
|
||||
@retry="loadDetail"
|
||||
@attach-customs="openCustomsDocument"
|
||||
@complete-customs="completeCustomsDocument"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<AppDialog
|
||||
v-model="customsDialogOpen"
|
||||
title="装柜清单报关资料"
|
||||
width="min(520px, calc(100vw - 28px))"
|
||||
confirm-text="上传资料"
|
||||
:confirm-loading="customsSaving"
|
||||
:confirm-disabled="!customsFile"
|
||||
@confirm="uploadCustomsDocument"
|
||||
>
|
||||
<el-form label-position="top">
|
||||
<el-form-item label="报关资料">
|
||||
<el-upload :auto-upload="false" :limit="1" :on-change="selectCustomsFile" :on-remove="removeCustomsFile">
|
||||
<el-button><FileUp :size="16" />选择文件</el-button>
|
||||
<template #tip><div class="el-upload__tip">{{ detail?.customsDocument ? '上传新文件将替换当前资料。' : '请选择需要提交的装柜清单报关资料。' }}</div></template>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</AppDialog>
|
||||
</AdminPage>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user