328 lines
17 KiB
Vue
328 lines
17 KiB
Vue
/**
|
|
* features/chat/components/messages/ShippingParseReviewMessage.vue
|
|
* 用途:发货 Agent parse_review 阶段单头/订单行可编辑消息 UI。
|
|
* 依赖:chat.types、shipping.api.types、vue-i18n。
|
|
* 逻辑:ChatView 渲染 parse_review 消息时挂载;通过 ShippingParseReviewHandlers 提交字段更正。
|
|
*/
|
|
<script setup lang="ts">
|
|
import { computed, reactive, ref, watch } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import type { ChatMessage } from '../../types/chat.types';
|
|
import type { ShippingParseReviewPayload } from '../../types/shipping.types';
|
|
import type { ShippingNoticeHeader, ShippingNoticeLine } from '../../types/shipping.api.types';
|
|
|
|
export interface ShippingParseReviewHandlers {
|
|
getPayload: (msg: ChatMessage) => ShippingParseReviewPayload | null;
|
|
updateHeader: (msg: ChatMessage, fields: Partial<ShippingNoticeHeader>) => Promise<boolean>;
|
|
updateLine: (msg: ChatMessage, lineIndex: number, patch: Partial<ShippingNoticeLine>) => Promise<boolean>;
|
|
addLine: (msg: ChatMessage, line: Partial<ShippingNoticeLine>) => Promise<boolean>;
|
|
removeLine: (msg: ChatMessage, lineIndex: number) => Promise<boolean>;
|
|
}
|
|
|
|
const { message, handlers } = defineProps<{
|
|
message: ChatMessage;
|
|
handlers: ShippingParseReviewHandlers;
|
|
}>();
|
|
|
|
const { t } = useI18n();
|
|
const editingHeader = ref(false);
|
|
const editingLineIndex = ref<number | null>(null);
|
|
const headerForm = reactive<ShippingNoticeHeader>({
|
|
customer_name: '',
|
|
customer_code: '',
|
|
ship_to: '',
|
|
po_number: '',
|
|
required_date: '',
|
|
});
|
|
const lineForm = reactive<Partial<ShippingNoticeLine>>({
|
|
reservation_id: '',
|
|
sku: '',
|
|
qty: 0,
|
|
required_date: '',
|
|
uom: '',
|
|
});
|
|
const addingLine = ref(false);
|
|
|
|
const payload = computed(() => handlers.getPayload(message));
|
|
|
|
watch(payload, (value) => {
|
|
if (!value) return;
|
|
headerForm.customer_name = value.header.customer_name ?? '';
|
|
headerForm.customer_code = value.header.customer_code ?? '';
|
|
headerForm.ship_to = value.header.ship_to ?? '';
|
|
headerForm.po_number = value.header.po_number ?? '';
|
|
headerForm.required_date = value.header.required_date ?? '';
|
|
}, { immediate: true, deep: true });
|
|
|
|
watch(
|
|
() => editingLineIndex.value,
|
|
(value) => {
|
|
if (value == null || !payload.value) return;
|
|
const line = payload.value.lines[value];
|
|
if (!line) return;
|
|
lineForm.reservation_id = line.reservation_id ?? '';
|
|
lineForm.sku = line.sku;
|
|
lineForm.qty = line.qty;
|
|
lineForm.required_date = line.required_date ?? '';
|
|
lineForm.uom = line.uom ?? '';
|
|
},
|
|
{ immediate: true },
|
|
);
|
|
|
|
const saveHeader = async () => {
|
|
const ok = await handlers.updateHeader(message, {
|
|
customer_name: headerForm.customer_name,
|
|
customer_code: headerForm.customer_code,
|
|
ship_to: headerForm.ship_to,
|
|
po_number: headerForm.po_number,
|
|
required_date: headerForm.required_date,
|
|
});
|
|
if (ok) editingHeader.value = false;
|
|
};
|
|
|
|
const saveLine = async () => {
|
|
if (editingLineIndex.value == null) return;
|
|
const ok = await handlers.updateLine(message, editingLineIndex.value, {
|
|
reservation_id: lineForm.reservation_id,
|
|
sku: lineForm.sku,
|
|
qty: Number(lineForm.qty || 0),
|
|
required_date: lineForm.required_date,
|
|
uom: lineForm.uom,
|
|
});
|
|
if (ok) editingLineIndex.value = null;
|
|
};
|
|
|
|
const startAddLine = () => {
|
|
addingLine.value = true;
|
|
editingLineIndex.value = null;
|
|
lineForm.reservation_id = '';
|
|
lineForm.sku = '';
|
|
lineForm.qty = 0;
|
|
lineForm.required_date = '';
|
|
lineForm.uom = '';
|
|
};
|
|
|
|
const saveAddedLine = async () => {
|
|
const ok = await handlers.addLine(message, {
|
|
reservation_id: lineForm.reservation_id,
|
|
sku: lineForm.sku,
|
|
qty: Number(lineForm.qty || 0),
|
|
required_date: lineForm.required_date,
|
|
uom: lineForm.uom,
|
|
});
|
|
if (ok) addingLine.value = false;
|
|
};
|
|
|
|
const removeLine = async (lineIndex: number) => {
|
|
const ok = await handlers.removeLine(message, lineIndex);
|
|
if (ok && editingLineIndex.value === lineIndex) {
|
|
editingLineIndex.value = null;
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div v-if="payload" class="space-y-4">
|
|
<div class="whitespace-pre-wrap text-sm font-medium text-secondary">{{ message.content }}</div>
|
|
<div class="space-y-4 rounded-2xl border border-default bg-surface-soft/90 p-4">
|
|
<div class="flex items-start justify-between gap-4">
|
|
<div>
|
|
<div class="text-xs font-bold uppercase tracking-wider text-muted">{{ t('chat.shippingNoticeUi.parseReviewHeader') }}</div>
|
|
<div class="mt-1 text-xs text-muted">{{ t('chat.shippingNoticeUi.taskId', { taskId: payload.taskId }) }}</div>
|
|
</div>
|
|
<button
|
|
type="button"
|
|
class="rounded-xl border border-default px-3 py-1.5 text-xs font-medium text-secondary transition hover:bg-surface disabled:cursor-not-allowed disabled:opacity-60"
|
|
:disabled="payload.saving"
|
|
@click="editingHeader = !editingHeader"
|
|
>
|
|
{{ editingHeader ? t('chat.shippingNoticeUi.cancelEdit') : t('chat.shippingNoticeUi.editHeader') }}
|
|
</button>
|
|
</div>
|
|
|
|
<div v-if="editingHeader" class="grid gap-3 md:grid-cols-2">
|
|
<label class="space-y-1.5">
|
|
<span class="text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.customer') }}</span>
|
|
<input v-model="headerForm.customer_name" class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400" />
|
|
</label>
|
|
<label class="space-y-1.5">
|
|
<span class="text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.customerCode') }}</span>
|
|
<input v-model="headerForm.customer_code" class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400" />
|
|
</label>
|
|
<label class="space-y-1.5 md:col-span-2">
|
|
<span class="text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.shipTo') }}</span>
|
|
<input v-model="headerForm.ship_to" class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400" />
|
|
</label>
|
|
<label class="space-y-1.5">
|
|
<span class="text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.poNumber') }}</span>
|
|
<input v-model="headerForm.po_number" class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400" />
|
|
</label>
|
|
<label class="space-y-1.5">
|
|
<span class="text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.requiredDate') }}</span>
|
|
<input v-model="headerForm.required_date" class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400" />
|
|
</label>
|
|
<div class="md:col-span-2 flex justify-end gap-3">
|
|
<button
|
|
type="button"
|
|
class="rounded-xl bg-emerald-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-emerald-700 disabled:cursor-not-allowed disabled:opacity-60"
|
|
:disabled="payload.saving"
|
|
@click="saveHeader"
|
|
>
|
|
{{ payload.saving ? t('chat.shippingNoticeUi.saving') : t('chat.shippingNoticeUi.saveHeader') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<table v-else class="w-full border-collapse text-sm">
|
|
<tbody>
|
|
<tr>
|
|
<th class="border border-default bg-surface px-3 py-2 text-left text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.customer') }}</th>
|
|
<td class="border border-default px-3 py-2 text-secondary">{{ payload.header.customer_name || '-' }}</td>
|
|
<th class="border border-default bg-surface px-3 py-2 text-left text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.poNumber') }}</th>
|
|
<td class="border border-default px-3 py-2 text-secondary">{{ payload.header.po_number || '-' }}</td>
|
|
</tr>
|
|
<tr>
|
|
<th class="border border-default bg-surface px-3 py-2 text-left text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.shipTo') }}</th>
|
|
<td class="border border-default px-3 py-2 text-secondary">{{ payload.header.ship_to || '-' }}</td>
|
|
<th class="border border-default bg-surface px-3 py-2 text-left text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.requiredDate') }}</th>
|
|
<td class="border border-default px-3 py-2 text-secondary">{{ payload.header.required_date || '-' }}</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<div class="space-y-2">
|
|
<div class="flex items-center justify-between gap-3">
|
|
<div class="text-xs font-bold uppercase tracking-wider text-muted">{{ t('chat.shippingNoticeUi.orderLines') }}</div>
|
|
<button
|
|
type="button"
|
|
class="rounded-xl border border-default px-3 py-1.5 text-xs font-medium text-secondary transition hover:bg-surface disabled:cursor-not-allowed disabled:opacity-60"
|
|
:disabled="payload.saving || addingLine"
|
|
@click="startAddLine"
|
|
>
|
|
{{ t('chat.shippingNoticeUi.addLine') }}
|
|
</button>
|
|
</div>
|
|
<table class="w-full border-collapse text-sm">
|
|
<thead>
|
|
<tr>
|
|
<th class="border border-default bg-surface px-3 py-2 text-left text-xs font-semibold text-muted">#</th>
|
|
<th class="border border-default bg-surface px-3 py-2 text-left text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.reservationId') }}</th>
|
|
<th class="border border-default bg-surface px-3 py-2 text-left text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.sku') }}</th>
|
|
<th class="border border-default bg-surface px-3 py-2 text-left text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.qty') }}</th>
|
|
<th class="border border-default bg-surface px-3 py-2 text-left text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.requiredDate') }}</th>
|
|
<th class="border border-default bg-surface px-3 py-2 text-left text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.actions') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-for="(line, lineIndex) in payload.lines" :key="`${payload.taskId}-${line.line_no || lineIndex}`">
|
|
<td class="border border-default px-3 py-2 text-secondary">{{ lineIndex + 1 }}</td>
|
|
<td class="border border-default px-3 py-2 text-secondary">{{ line.reservation_id || '-' }}</td>
|
|
<td class="border border-default px-3 py-2 text-secondary">{{ line.sku }}</td>
|
|
<td class="border border-default px-3 py-2 text-secondary">{{ line.qty }}</td>
|
|
<td class="border border-default px-3 py-2 text-secondary">{{ line.required_date || '-' }}</td>
|
|
<td class="border border-default px-3 py-2">
|
|
<button
|
|
type="button"
|
|
class="rounded-xl border border-default px-3 py-1.5 text-xs font-medium text-secondary transition hover:bg-surface disabled:cursor-not-allowed disabled:opacity-60"
|
|
:disabled="payload.saving"
|
|
@click="editingLineIndex = lineIndex"
|
|
>
|
|
{{ t('chat.shippingNoticeUi.editLine') }}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="ml-2 rounded-xl border border-rose-200 px-3 py-1.5 text-xs font-medium text-rose-700 transition hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-60"
|
|
:disabled="payload.saving || payload.lines.length <= 1"
|
|
@click="removeLine(lineIndex)"
|
|
>
|
|
{{ t('chat.shippingNoticeUi.deleteLine') }}
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div v-if="addingLine" class="space-y-3 rounded-xl border border-emerald-200 bg-emerald-50/70 p-4">
|
|
<div class="text-sm font-semibold text-emerald-700">{{ t('chat.shippingNoticeUi.addOrderLine') }}</div>
|
|
<div class="grid gap-3 md:grid-cols-2">
|
|
<label class="space-y-1.5">
|
|
<span class="text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.reservationId') }}</span>
|
|
<input v-model="lineForm.reservation_id" class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400" />
|
|
</label>
|
|
<label class="space-y-1.5">
|
|
<span class="text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.sku') }}</span>
|
|
<input v-model="lineForm.sku" class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400" />
|
|
</label>
|
|
<label class="space-y-1.5">
|
|
<span class="text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.qty') }}</span>
|
|
<input v-model.number="lineForm.qty" type="number" min="1" class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400" />
|
|
</label>
|
|
<label class="space-y-1.5">
|
|
<span class="text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.requiredDate') }}</span>
|
|
<input v-model="lineForm.required_date" class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400" />
|
|
</label>
|
|
</div>
|
|
<div class="flex justify-end gap-3">
|
|
<button
|
|
type="button"
|
|
class="rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition hover:bg-surface disabled:cursor-not-allowed disabled:opacity-60"
|
|
:disabled="payload.saving"
|
|
@click="addingLine = false"
|
|
>
|
|
{{ t('chat.shippingNoticeUi.cancelEdit') }}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="rounded-xl bg-emerald-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-emerald-700 disabled:cursor-not-allowed disabled:opacity-60"
|
|
:disabled="payload.saving"
|
|
@click="saveAddedLine"
|
|
>
|
|
{{ payload.saving ? t('chat.shippingNoticeUi.saving') : t('chat.shippingNoticeUi.saveAddedLine') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-if="editingLineIndex !== null" class="space-y-3 rounded-xl border border-brand-200 bg-brand-50/70 p-4">
|
|
<div class="text-sm font-semibold text-brand-700">{{ t('chat.shippingNoticeUi.editLineTitle', { index: editingLineIndex + 1 }) }}</div>
|
|
<div class="grid gap-3 md:grid-cols-2">
|
|
<label class="space-y-1.5">
|
|
<span class="text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.reservationId') }}</span>
|
|
<input v-model="lineForm.reservation_id" class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400" />
|
|
</label>
|
|
<label class="space-y-1.5">
|
|
<span class="text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.sku') }}</span>
|
|
<input v-model="lineForm.sku" class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400" />
|
|
</label>
|
|
<label class="space-y-1.5">
|
|
<span class="text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.qty') }}</span>
|
|
<input v-model.number="lineForm.qty" type="number" min="1" class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400" />
|
|
</label>
|
|
<label class="space-y-1.5">
|
|
<span class="text-xs font-semibold text-muted">{{ t('chat.shippingNoticeUi.requiredDate') }}</span>
|
|
<input v-model="lineForm.required_date" class="w-full rounded-xl border border-default px-3 py-2 text-sm text-secondary outline-none transition focus:border-blue-400" />
|
|
</label>
|
|
</div>
|
|
<div class="flex justify-end gap-3">
|
|
<button
|
|
type="button"
|
|
class="rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition hover:bg-surface disabled:cursor-not-allowed disabled:opacity-60"
|
|
:disabled="payload.saving"
|
|
@click="editingLineIndex = null"
|
|
>
|
|
{{ t('chat.shippingNoticeUi.cancelEdit') }}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="rounded-xl bg-emerald-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-emerald-700 disabled:cursor-not-allowed disabled:opacity-60"
|
|
:disabled="payload.saving"
|
|
@click="saveLine"
|
|
>
|
|
{{ payload.saving ? t('chat.shippingNoticeUi.saving') : t('chat.shippingNoticeUi.saveLineItem') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|