202 lines
7.5 KiB
Vue
202 lines
7.5 KiB
Vue
/**
|
|
* features/chat/components/ShippingNoticeDuplicateDialog.vue
|
|
* 用途:发货通知阻断型重复处理弹窗(打开已有 / 修订 / 强制新建)。
|
|
* 依赖:shipping.types Duplicate 类型、vue-i18n。
|
|
* 逻辑:ChatViewOverlays 展示;确认后回写 resolveDuplicateAttachment,再允许确认建单。
|
|
*/
|
|
<script setup lang="ts">
|
|
import { computed, ref, watch } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import type {
|
|
ShippingDuplicateAction,
|
|
ShippingNoticePendingAttachment,
|
|
} from '../types/shipping.types';
|
|
|
|
const props = defineProps<{
|
|
open: boolean;
|
|
attachment: ShippingNoticePendingAttachment | null;
|
|
canForceCreate: boolean;
|
|
}>();
|
|
|
|
const emit = defineEmits<{
|
|
'update:open': [value: boolean];
|
|
resolve: [payload: { action: ShippingDuplicateAction; targetTaskNo?: string; reason?: string }];
|
|
remove: [];
|
|
cancel: [];
|
|
}>();
|
|
|
|
const { t } = useI18n();
|
|
const reason = ref('');
|
|
const selectedAction = ref<ShippingDuplicateAction>('open_existing');
|
|
const submitting = ref(false);
|
|
const localError = ref('');
|
|
|
|
const match = computed(() => props.attachment?.duplicate?.matches?.[0] || null);
|
|
const allowed = computed(() => new Set(props.attachment?.duplicate?.allowedActions || []));
|
|
|
|
watch(
|
|
() => props.open,
|
|
(open) => {
|
|
if (!open) return;
|
|
reason.value = '';
|
|
localError.value = '';
|
|
submitting.value = false;
|
|
const actions = props.attachment?.duplicate?.allowedActions || [];
|
|
selectedAction.value = (actions[0] as ShippingDuplicateAction) || 'open_existing';
|
|
},
|
|
);
|
|
|
|
/**
|
|
* 关闭弹窗。
|
|
*/
|
|
function close() {
|
|
emit('update:open', false);
|
|
emit('cancel');
|
|
}
|
|
|
|
/**
|
|
* 提交所选重复处理动作。
|
|
*/
|
|
async function confirm() {
|
|
if (!props.attachment?.duplicate || !match.value) return;
|
|
const action = selectedAction.value;
|
|
if (!allowed.value.has(action)) {
|
|
localError.value = t('chat.shippingNoticeDuplicateActionUnavailable');
|
|
return;
|
|
}
|
|
if (action === 'force_create') {
|
|
if (!props.canForceCreate) {
|
|
localError.value = t('chat.shippingNoticeDuplicateForceForbidden');
|
|
return;
|
|
}
|
|
if (!reason.value.trim()) {
|
|
localError.value = t('chat.shippingNoticeDuplicateReasonRequired');
|
|
return;
|
|
}
|
|
}
|
|
submitting.value = true;
|
|
localError.value = '';
|
|
try {
|
|
emit('resolve', {
|
|
action,
|
|
targetTaskNo: match.value.taskNo,
|
|
reason: action === 'force_create' ? reason.value.trim() : undefined,
|
|
});
|
|
emit('update:open', false);
|
|
} finally {
|
|
submitting.value = false;
|
|
}
|
|
}
|
|
|
|
const statusLabel = computed(() => {
|
|
const status = props.attachment?.duplicate?.status;
|
|
if (status === 'exact_file') return t('chat.shippingNoticeDuplicateExactFile');
|
|
if (status === 'same_active_task') return t('chat.shippingNoticeDuplicateSameActive');
|
|
if (status === 'same_completed_task') return t('chat.shippingNoticeDuplicateSameCompleted');
|
|
if (status === 'possible_duplicate') return t('chat.shippingNoticeDuplicatePossible');
|
|
return t('chat.shippingNoticeDuplicateNeedsResolution');
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
v-if="open && attachment"
|
|
class="fixed inset-0 z-[160] flex items-center justify-center bg-black/40 px-4"
|
|
role="dialog"
|
|
aria-modal="true"
|
|
>
|
|
<div class="w-full max-w-lg rounded-xl border border-default bg-surface p-5 shadow-xl">
|
|
<h3 class="text-base font-semibold text-primary">
|
|
{{ t('chat.shippingNoticeDuplicateTitle') }}
|
|
</h3>
|
|
<p class="mt-2 text-sm text-secondary">{{ statusLabel }}</p>
|
|
<p class="mt-1 text-xs text-muted">
|
|
{{ attachment.originalFilename }}
|
|
</p>
|
|
|
|
<div
|
|
v-if="match"
|
|
class="mt-4 rounded-lg border border-default bg-surface-soft px-3 py-2 text-sm text-secondary"
|
|
>
|
|
<div>{{ t('chat.shippingNoticeDuplicateMatchTask', { taskNo: match.taskNo }) }}</div>
|
|
<div class="mt-1 text-xs text-muted">
|
|
{{ t('chat.shippingNoticeDuplicateMatchStatus', { status: match.processStatus }) }}
|
|
· v{{ match.documentVersion }}
|
|
</div>
|
|
<div v-if="match.matchedFields?.length" class="mt-1 text-xs text-muted">
|
|
{{ t('chat.shippingNoticeDuplicateMatchFields', { fields: match.matchedFields.join(', ') }) }}
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mt-4 space-y-2">
|
|
<label
|
|
v-if="allowed.has('open_existing')"
|
|
class="flex cursor-pointer items-start gap-2 rounded-lg border border-default px-3 py-2 text-sm"
|
|
:class="selectedAction === 'open_existing' ? 'border-brand-500 bg-brand-50/40' : ''"
|
|
>
|
|
<input v-model="selectedAction" type="radio" value="open_existing" class="mt-1" />
|
|
<span>
|
|
<span class="font-medium text-primary">{{ t('chat.shippingNoticeDuplicateOpenExisting') }}</span>
|
|
<span class="mt-0.5 block text-xs text-muted">{{ t('chat.shippingNoticeDuplicateOpenExistingHint') }}</span>
|
|
</span>
|
|
</label>
|
|
<label
|
|
v-if="allowed.has('create_revision')"
|
|
class="flex cursor-pointer items-start gap-2 rounded-lg border border-default px-3 py-2 text-sm"
|
|
:class="selectedAction === 'create_revision' ? 'border-brand-500 bg-brand-50/40' : ''"
|
|
>
|
|
<input v-model="selectedAction" type="radio" value="create_revision" class="mt-1" />
|
|
<span>
|
|
<span class="font-medium text-primary">{{ t('chat.shippingNoticeDuplicateCreateRevision') }}</span>
|
|
<span class="mt-0.5 block text-xs text-muted">{{ t('chat.shippingNoticeDuplicateCreateRevisionHint') }}</span>
|
|
</span>
|
|
</label>
|
|
<label
|
|
v-if="allowed.has('force_create') && canForceCreate"
|
|
class="flex cursor-pointer items-start gap-2 rounded-lg border border-default px-3 py-2 text-sm"
|
|
:class="selectedAction === 'force_create' ? 'border-amber-500 bg-amber-50/50' : ''"
|
|
>
|
|
<input v-model="selectedAction" type="radio" value="force_create" class="mt-1" />
|
|
<span>
|
|
<span class="font-medium text-primary">{{ t('chat.shippingNoticeDuplicateForceCreate') }}</span>
|
|
<span class="mt-0.5 block text-xs text-muted">{{ t('chat.shippingNoticeDuplicateForceCreateHint') }}</span>
|
|
</span>
|
|
</label>
|
|
</div>
|
|
|
|
<div v-if="selectedAction === 'force_create'" class="mt-3">
|
|
<label class="text-xs font-medium text-secondary">{{ t('chat.shippingNoticeDuplicateReasonLabel') }}</label>
|
|
<textarea
|
|
v-model="reason"
|
|
rows="2"
|
|
class="mt-1 w-full rounded-lg border border-default bg-surface px-3 py-2 text-sm"
|
|
:placeholder="t('chat.shippingNoticeDuplicateReasonPlaceholder')"
|
|
/>
|
|
</div>
|
|
|
|
<p v-if="localError" class="mt-2 text-xs text-red-600">{{ localError }}</p>
|
|
|
|
<div class="mt-5 flex flex-wrap justify-end gap-2">
|
|
<button type="button" class="rounded-lg px-3 py-1.5 text-sm text-muted hover:text-primary" @click="close">
|
|
{{ t('common.cancel') }}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="rounded-lg px-3 py-1.5 text-sm text-red-600 hover:bg-red-50"
|
|
@click="emit('remove'); emit('update:open', false)"
|
|
>
|
|
{{ t('chat.shippingNoticeDuplicateRemoveFile') }}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="rounded-lg bg-brand-600 px-3 py-1.5 text-sm font-medium text-white disabled:opacity-50"
|
|
:disabled="submitting || !match"
|
|
@click="confirm"
|
|
>
|
|
{{ t('chat.shippingNoticeDuplicateConfirm') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|