feat(shipping-notice): 添加识别定义和规则集管理功能,支持客户和站点的可配置识别规则
This commit is contained in:
1 parent
88408490d7
commit
34d489a2d1
167 files changed
+10365
-7978
No files matched your search
@@ -8,7 +8,6 @@
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { BusinessError, requestJson, resolveLocalizedErrorMessage } from '@/shared/api/client';
|
||||
import type {
|
||||
ShippingCustomerIdentifier,
|
||||
ShippingCustomerImportBatch,
|
||||
ShippingCustomerLifecycleImpact,
|
||||
ShippingCustomerLifecycleTimeline,
|
||||
@@ -21,7 +20,9 @@ import type {
|
||||
ShippingCustomerRow,
|
||||
ShippingCustomerShadowItem,
|
||||
ShippingCustomerShadowReport,
|
||||
ShippingIdentifierFormState,
|
||||
ShippingIdentityEvidence,
|
||||
ShippingIdentityEvidenceFormState,
|
||||
ShippingPublishedEvidenceDefinitions,
|
||||
} from '../types/customer-master.types';
|
||||
|
||||
const auth = () => ({ headers: getAuthHeaders() });
|
||||
@@ -89,13 +90,33 @@ export const deactivateShippingCustomer = (id: number, reason: string) =>
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify({ reason }),
|
||||
});
|
||||
|
||||
export const createShippingCustomerIdentifier = (customerId: number, payload: ShippingIdentifierFormState) =>
|
||||
requestJson<ShippingCustomerIdentifier>(`/api/admin/shipping-customers/${customerId}/identifiers`, {
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
/** 读取当前已发布规则集中可由客户主数据维护的兼容证据定义。 */
|
||||
export const getShippingPublishedEvidenceDefinitions = (targetType: 'customer' | 'site') =>
|
||||
requestJson<ShippingPublishedEvidenceDefinitions>(
|
||||
`/api/admin/shipping-identity-rules/published-evidence-definitions?target_type=${targetType}`,
|
||||
auth(),
|
||||
);
|
||||
|
||||
export const updateShippingCustomerIdentifier = (identifierId: number, payload: Record<string, unknown>) =>
|
||||
requestJson<ShippingCustomerIdentifier>(`/api/admin/shipping-customer-identifiers/${identifierId}`, {
|
||||
/** 为客户主体或送货站点新建配置化识别证据。 */
|
||||
export const createShippingIdentityEvidence = (form: ShippingIdentityEvidenceFormState) => {
|
||||
const targetId = form.target_id;
|
||||
const path = form.target_type === 'customer'
|
||||
? `/api/admin/shipping-customers/${targetId}/identity-evidences`
|
||||
: `/api/admin/shipping-customer-sites/${targetId}/identity-evidences`;
|
||||
return requestJson<ShippingIdentityEvidence>(path, {
|
||||
method: 'POST', ...jsonAuth(), body: JSON.stringify({
|
||||
definition_id: form.definition_id,
|
||||
raw_value: form.raw_value,
|
||||
status: form.status,
|
||||
auto_match_allowed: form.auto_match_allowed,
|
||||
remark: form.remark,
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
/** 审核、停用或调整配置化证据授权;服务端要求高风险变更理由。 */
|
||||
export const updateShippingIdentityEvidence = (evidenceId: number, payload: Record<string, unknown>) =>
|
||||
requestJson<ShippingIdentityEvidence>(`/api/admin/shipping-identity-evidences/${evidenceId}`, {
|
||||
method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ onMounted(() => { void Promise.all([admin.loadCustomers(), admin.loadShadowRepor
|
||||
<th class="px-5 py-4 text-left">{{ t('admin.shippingCustomers.headers.name') }}</th>
|
||||
<th class="px-5 py-4 text-left">{{ t('admin.shippingCustomers.headers.shortCode') }}</th>
|
||||
<th class="px-5 py-4 text-left">{{ t('admin.shippingCustomers.headers.status') }}</th>
|
||||
<th class="px-5 py-4 text-left">{{ t('admin.shippingCustomers.headers.identifiers') }}</th>
|
||||
<th class="px-5 py-4 text-left">{{ t('admin.shippingCustomers.headers.identityEvidences') }}</th>
|
||||
<th class="px-5 py-4 text-left">{{ t('admin.shippingCustomers.headers.cases') }}</th>
|
||||
<th class="px-5 py-4 text-right">{{ t('admin.shippingCustomers.headers.actions') }}</th>
|
||||
</tr></thead>
|
||||
@@ -67,7 +67,7 @@ onMounted(() => { void Promise.all([admin.loadCustomers(), admin.loadShadowRepor
|
||||
<td class="px-5 py-4"><div class="font-medium text-primary">{{ customer.standard_name }}</div><div v-if="customer.remark" class="text-xs text-muted truncate max-w-sm">{{ customer.remark }}</div></td>
|
||||
<td class="px-5 py-4 font-mono text-sm">{{ customer.short_code }}</td>
|
||||
<td class="px-5 py-4"><span class="text-sm" :class="customer.status === 'active' ? 'text-emerald-600' : 'text-muted'">{{ t(`admin.shippingCustomers.status.${customer.status}`) }}</span></td>
|
||||
<td class="px-5 py-4 text-sm">{{ customer.identifier_count }}</td>
|
||||
<td class="px-5 py-4 text-sm">{{ customer.identity_evidence_count || 0 }}</td>
|
||||
<td class="px-5 py-4 text-sm">{{ customer.case_count }}</td>
|
||||
<td class="px-5 py-4"><div class="flex justify-end gap-1">
|
||||
<button type="button" class="p-2 text-indigo-600 hover:bg-indigo-50 rounded-lg" :title="t('admin.shippingCustomers.identifiers.title')" @click="admin.openIdentifiers(customer)"><Fingerprint class="w-4 h-4" /></button>
|
||||
@@ -87,7 +87,7 @@ onMounted(() => { void Promise.all([admin.loadCustomers(), admin.loadShadowRepor
|
||||
<CustomerShadowQualityPanel :report="admin.shadowReport.value" :customers="admin.importTargetCustomers.value.length ? admin.importTargetCustomers.value : admin.customers.value" :loading="admin.isShadowLoading.value" @refresh="admin.loadShadowReport" @label="admin.labelShadowResolution" />
|
||||
|
||||
<CustomerFormModal :visible="admin.showCustomerModal.value" :form="admin.customerForm.value" :is-saving="admin.isSaving.value" @close="admin.closeCustomerModal" @save="admin.saveCustomer" />
|
||||
<CustomerIdentifiersPanel :visible="admin.showIdentifiersPanel.value" :customer="admin.selectedCustomer.value" :is-saving="admin.isSaving.value" @close="admin.showIdentifiersPanel.value = false" @add="admin.addIdentifier" @update="admin.updateIdentifier" @add-external-ref="admin.addExternalRef" @add-site="admin.addSite" />
|
||||
<CustomerIdentifiersPanel :visible="admin.showIdentifiersPanel.value" :customer="admin.selectedCustomer.value" :published-definitions="admin.publishedEvidenceDefinitions.value" :is-saving="admin.isSaving.value" @close="admin.showIdentifiersPanel.value = false" @add-evidence="admin.addIdentityEvidence" @update-evidence="admin.updateIdentityEvidence" @add-external-ref="admin.addExternalRef" @add-site="admin.addSite" />
|
||||
<CustomerImportDialog :visible="admin.showImportDialog.value" :batch="admin.importBatch.value" :customers="admin.importTargetCustomers.value" :is-importing="admin.isImporting.value" @close="admin.showImportDialog.value = false" @upload="admin.uploadImport" @decide="admin.decideImportRow" @publish="admin.publishImport" @template="admin.downloadTemplate" @reconciliation="admin.downloadReconciliation" />
|
||||
<CustomerDeleteDialog :visible="admin.showDeleteDialog.value" :customer="admin.deleteCustomer.value" :impact="admin.deleteImpact.value" :is-saving="admin.isSaving.value" @close="admin.closeDeleteCustomer" @confirm="admin.confirmDeleteCustomer" />
|
||||
<CustomerLifecyclePanel :visible="admin.showLifecyclePanel.value" :customer="admin.lifecycleCustomer.value" :timeline="admin.lifecycleTimeline.value" @close="admin.closeLifecycleTimeline" />
|
||||
|
||||
+69
-77
@@ -1,51 +1,82 @@
|
||||
<!--
|
||||
features/shipping-notice/customers/components/CustomerIdentifiersPanel.vue
|
||||
用途:展示、新增、审核和停用客户识别证据。
|
||||
用途:维护客户主体和送货站点的全配置识别证据。
|
||||
依赖:customer-master.types、vue-i18n。
|
||||
逻辑:所有修改通过事件上送 composable;本组件不直接访问 API。
|
||||
逻辑:定义目录由服务端按已发布规则集提供;组件不维护类型枚举,也不直接调用 API。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type {
|
||||
ShippingCustomerRow,
|
||||
ShippingIdentifierFormState,
|
||||
ShippingIdentityEvidenceFormState,
|
||||
ShippingPublishedEvidenceDefinitions,
|
||||
} from '@/features/shipping-notice/types/customer-master.types';
|
||||
import { createEmptyShippingIdentifierForm } from '@/features/shipping-notice/types/customer-master.types';
|
||||
import { createEmptyShippingIdentityEvidenceForm } from '@/features/shipping-notice/types/customer-master.types';
|
||||
|
||||
const props = defineProps<{ visible: boolean; customer: ShippingCustomerRow | null; isSaving: boolean }>();
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
customer: ShippingCustomerRow | null;
|
||||
publishedDefinitions: ShippingPublishedEvidenceDefinitions | null;
|
||||
isSaving: boolean;
|
||||
}>();
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
add: [form: ShippingIdentifierFormState];
|
||||
update: [id: number, payload: Record<string, unknown>];
|
||||
addEvidence: [form: ShippingIdentityEvidenceFormState];
|
||||
updateEvidence: [id: number, payload: Record<string, unknown>];
|
||||
addExternalRef: [payload: { source_system: string; customer_code: string }];
|
||||
addSite: [payload: { site_name: string; site_code: string; address?: string; city?: string; country?: string; remark?: string }];
|
||||
}>();
|
||||
const { t } = useI18n();
|
||||
const form = ref(createEmptyShippingIdentifierForm());
|
||||
const form = ref(createEmptyShippingIdentityEvidenceForm());
|
||||
const externalRefForm = ref({ source_system: '', customer_code: '' });
|
||||
const siteForm = ref({ site_name: '', site_code: '', address: '', city: '', country: '', remark: '' });
|
||||
|
||||
/** 切换客户或关闭面板时清空未提交证据。 */
|
||||
const currentDefinitions = computed(() => (props.publishedDefinitions?.definitions || []).filter(
|
||||
(item) => item.target_type === form.value.target_type,
|
||||
));
|
||||
const selectedDefinition = computed(() => currentDefinitions.value.find(
|
||||
(item) => item.id === form.value.definition_id,
|
||||
));
|
||||
const selectedSite = computed(() => (props.customer?.sites || []).find((item) => item.id === form.value.target_id));
|
||||
const targetReady = computed(() => form.value.target_type === 'customer'
|
||||
? Boolean(props.customer?.id)
|
||||
: Boolean(selectedSite.value));
|
||||
|
||||
/** 切换客户、可见性或目标对象时清空未提交的证据草稿。 */
|
||||
watch(() => [props.visible, props.customer?.id], () => {
|
||||
form.value = createEmptyShippingIdentifierForm();
|
||||
form.value = { ...createEmptyShippingIdentityEvidenceForm(), target_id: props.customer?.id };
|
||||
externalRefForm.value = { source_system: '', customer_code: '' };
|
||||
siteForm.value = { site_name: '', site_code: '', address: '', city: '', country: '', remark: '' };
|
||||
});
|
||||
|
||||
/** 提交证据后重置表单,实际保存由父级处理。 */
|
||||
const submit = (): void => {
|
||||
emit('add', { ...form.value });
|
||||
form.value = createEmptyShippingIdentifierForm();
|
||||
/** 目标切换时限定定义目录,避免将客户定义提交给站点或反向提交。 */
|
||||
watch(() => form.value.target_type, (targetType) => {
|
||||
form.value.definition_id = '';
|
||||
form.value.target_id = targetType === 'customer' ? props.customer?.id : undefined;
|
||||
form.value.auto_match_allowed = false;
|
||||
});
|
||||
|
||||
/** 所选定义不允许自动化时立即清除授权,后端仍会二次校验。 */
|
||||
watch(selectedDefinition, (definition) => {
|
||||
if (definition?.max_automation !== 'conditional') form.value.auto_match_allowed = false;
|
||||
});
|
||||
|
||||
/** 提交配置化证据;目标 ID 与定义均由当前表单明确携带。 */
|
||||
const submitEvidence = (): void => {
|
||||
emit('addEvidence', { ...form.value, raw_value: form.value.raw_value.trim(), remark: form.value.remark.trim() });
|
||||
form.value.raw_value = '';
|
||||
form.value.remark = '';
|
||||
form.value.auto_match_allowed = false;
|
||||
};
|
||||
|
||||
/** 提交来源系统客户编码;客户简称仍由客户基本信息统一维护。 */
|
||||
/** 提交来源系统客户编码;该语义有独立主数据模型,不能伪装成普通证据值。 */
|
||||
const submitExternalRef = (): void => {
|
||||
emit('addExternalRef', { ...externalRefForm.value });
|
||||
externalRefForm.value = { source_system: '', customer_code: '' };
|
||||
};
|
||||
|
||||
/** 提交送货站点;站点用于 Ship-to 匹配,不创建新的账款客户。 */
|
||||
/** 提交送货站点;站点证据需在站点创建完成后选择对应站点维护。 */
|
||||
const submitSite = (): void => {
|
||||
emit('addSite', { ...siteForm.value });
|
||||
siteForm.value = { site_name: '', site_code: '', address: '', city: '', country: '', remark: '' };
|
||||
@@ -56,10 +87,7 @@ const submitSite = (): void => {
|
||||
<div v-if="visible && customer" class="admin-modal-overlay animate-fade-in items-center">
|
||||
<div class="admin-modal-panel max-w-5xl max-h-[92vh] scale-100">
|
||||
<div class="px-6 py-5 border-b border-subtle flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="section-title">{{ t('admin.shippingCustomers.identifiers.title') }}</h3>
|
||||
<p class="section-desc mt-1">{{ customer.standard_name }} · {{ customer.short_code }}</p>
|
||||
</div>
|
||||
<div><h3 class="section-title">{{ t('admin.shippingCustomers.identifiers.title') }}</h3><p class="section-desc mt-1">{{ customer.standard_name }} · {{ customer.short_code }}</p></div>
|
||||
<button type="button" class="btn-ghost" @click="emit('close')">{{ t('admin.close') }}</button>
|
||||
</div>
|
||||
<div class="px-6 py-5 overflow-y-auto space-y-6">
|
||||
@@ -67,71 +95,35 @@ const submitSite = (): void => {
|
||||
<div><h4 class="font-semibold text-primary">{{ t('admin.shippingCustomers.externalRefs.title') }}</h4><p class="text-xs text-muted mt-1">{{ t('admin.shippingCustomers.externalRefs.hint') }}</p></div>
|
||||
<div v-if="customer.external_refs?.length" class="flex flex-wrap gap-2"><span v-for="item in customer.external_refs" :key="item.id" class="badge">{{ item.source_system }} · {{ item.customer_code }}</span></div>
|
||||
<p v-else class="text-sm text-muted">{{ t('admin.shippingCustomers.externalRefs.empty') }}</p>
|
||||
<div class="grid grid-cols-1 md:grid-cols-[1fr_1fr_auto] gap-3">
|
||||
<input v-model="externalRefForm.source_system" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.externalRefs.sourceSystem')" />
|
||||
<input v-model="externalRefForm.customer_code" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.externalRefs.customerCode')" />
|
||||
<button type="button" class="btn-primary" :disabled="isSaving || !externalRefForm.source_system.trim() || !externalRefForm.customer_code.trim()" @click="submitExternalRef">{{ t('admin.add') }}</button>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-[1fr_1fr_auto] gap-3"><input v-model="externalRefForm.source_system" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.externalRefs.sourceSystem')"><input v-model="externalRefForm.customer_code" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.externalRefs.customerCode')"><button type="button" class="btn-primary" :disabled="isSaving || !externalRefForm.source_system.trim() || !externalRefForm.customer_code.trim()" @click="submitExternalRef">{{ t('admin.add') }}</button></div>
|
||||
</section>
|
||||
|
||||
<section class="rounded-xl border border-default p-4 space-y-4">
|
||||
<div><h4 class="font-semibold text-primary">{{ t('admin.shippingCustomers.sites.title') }}</h4><p class="text-xs text-muted mt-1">{{ t('admin.shippingCustomers.sites.hint') }}</p></div>
|
||||
<div v-if="customer.sites?.length" class="grid gap-2"><div v-for="site in customer.sites" :key="site.id" class="rounded-lg bg-surface-soft p-3"><div class="font-medium text-primary">{{ site.site_name }} · {{ site.site_code }}</div><div class="text-xs text-muted mt-1">{{ [site.address, site.city, site.country].filter(Boolean).join(' · ') || '-' }}</div></div></div>
|
||||
<div v-if="customer.sites?.length" class="grid gap-2"><div v-for="site in customer.sites" :key="site.id" class="rounded-lg bg-surface-soft p-3"><div class="font-medium text-primary">{{ site.site_name }} · {{ site.site_code }}</div><div class="text-xs text-muted mt-1">{{ [site.address, site.city, site.country].filter(Boolean).join(' · ') || '-' }}</div><div v-if="site.identity_evidences?.length" class="mt-2 space-y-1 text-xs text-muted"><div>{{ t('admin.shippingCustomers.identifiers.siteEvidenceCount', { count: site.identity_evidences.length }) }}</div><div v-for="evidence in site.identity_evidences" :key="evidence.id" class="flex items-center justify-between gap-2"><span>{{ evidence.definition?.display_name || evidence.definition?.definition_code || evidence.definition_id }} · {{ evidence.raw_value }}</span><span class="flex gap-2"><button v-if="evidence.status !== 'approved'" type="button" class="btn-ghost text-xs" @click="emit('updateEvidence', evidence.id, { status: 'approved' })">{{ t('admin.shippingCustomers.identifiers.approve') }}</button><button v-if="evidence.status === 'approved' && !evidence.auto_match_allowed && evidence.definition?.max_automation === 'conditional'" type="button" class="btn-ghost text-xs" @click="emit('updateEvidence', evidence.id, { auto_match_allowed: true })">{{ t('admin.shippingCustomers.identifiers.enableAuto') }}</button><button v-if="evidence.status !== 'disabled'" type="button" class="btn-ghost text-xs text-red-600" @click="emit('updateEvidence', evidence.id, { status: 'disabled' })">{{ t('admin.shippingCustomers.identifiers.disable') }}</button></span></div></div></div></div>
|
||||
<p v-else class="text-sm text-muted">{{ t('admin.shippingCustomers.sites.empty') }}</p>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
<input v-model="siteForm.site_name" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.sites.siteName')" />
|
||||
<input v-model="siteForm.site_code" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.sites.siteCode')" />
|
||||
<input v-model="siteForm.address" class="input-field text-sm md:col-span-2" :placeholder="t('admin.shippingCustomers.sites.address')" />
|
||||
<input v-model="siteForm.city" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.sites.city')" />
|
||||
<input v-model="siteForm.country" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.sites.country')" />
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3"><input v-model="siteForm.site_name" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.sites.siteName')"><input v-model="siteForm.site_code" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.sites.siteCode')"><input v-model="siteForm.address" class="input-field text-sm md:col-span-2" :placeholder="t('admin.shippingCustomers.sites.address')"><input v-model="siteForm.city" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.sites.city')"><input v-model="siteForm.country" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.sites.country')"></div>
|
||||
<div class="flex justify-end"><button type="button" class="btn-primary" :disabled="isSaving || !siteForm.site_name.trim() || !siteForm.site_code.trim()" @click="submitSite">{{ t('admin.add') }}</button></div>
|
||||
</section>
|
||||
|
||||
<div class="rounded-xl border border-default overflow-x-auto">
|
||||
<table class="admin-table min-w-[780px]">
|
||||
<thead><tr>
|
||||
<th class="px-4 py-3 text-left">{{ t('admin.shippingCustomers.identifiers.type') }}</th>
|
||||
<th class="px-4 py-3 text-left">{{ t('admin.shippingCustomers.identifiers.value') }}</th>
|
||||
<th class="px-4 py-3 text-left">{{ t('admin.shippingCustomers.identifiers.status') }}</th>
|
||||
<th class="px-4 py-3 text-left">{{ t('admin.shippingCustomers.identifiers.autoMatch') }}</th>
|
||||
<th class="px-4 py-3 text-right">{{ t('admin.shippingCustomers.headers.actions') }}</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr v-if="!customer.identifiers?.length">
|
||||
<td colspan="5" class="admin-table-empty px-4">{{ t('admin.shippingCustomers.identifiers.empty') }}</td>
|
||||
</tr>
|
||||
<tr v-for="item in customer.identifiers" :key="item.id">
|
||||
<td class="px-4 py-3 text-sm">{{ t(`admin.shippingCustomers.identifierTypes.${item.identifier_type}`) }}</td>
|
||||
<td class="px-4 py-3 text-sm"><div>{{ item.raw_value }}</div><div class="text-xs text-muted">{{ item.normalized_value }}</div></td>
|
||||
<td class="px-4 py-3 text-sm">{{ t(`admin.shippingCustomers.identifierStatus.${item.status}`) }}</td>
|
||||
<td class="px-4 py-3 text-sm">{{ item.auto_match_allowed ? t('admin.shippingCustomers.yes') : t('admin.shippingCustomers.no') }}</td>
|
||||
<td class="px-4 py-3"><div class="flex justify-end gap-2">
|
||||
<button v-if="item.status !== 'approved'" type="button" class="btn-ghost text-xs" @click="emit('update', item.id, { status: 'approved' })">{{ t('admin.shippingCustomers.identifiers.approve') }}</button>
|
||||
<button v-if="item.status === 'approved' && !item.auto_match_allowed" type="button" class="btn-ghost text-xs" @click="emit('update', item.id, { auto_match_allowed: true })">{{ t('admin.shippingCustomers.identifiers.enableAuto') }}</button>
|
||||
<button v-if="item.status !== 'disabled'" type="button" class="btn-ghost text-xs text-red-600" @click="emit('update', item.id, { status: 'disabled' })">{{ t('admin.shippingCustomers.identifiers.disable') }}</button>
|
||||
</div></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="rounded-xl border border-default p-4 space-y-4">
|
||||
<h4 class="font-semibold text-primary">{{ t('admin.shippingCustomers.identifiers.add') }}</h4>
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-3">
|
||||
<select v-model="form.identifier_type" class="input-field text-sm">
|
||||
<option v-for="kind in ['name_alias','email','domain','template_fingerprint','address','contact']" :key="kind" :value="kind">{{ t(`admin.shippingCustomers.identifierTypes.${kind}`) }}</option>
|
||||
</select>
|
||||
<input v-model="form.identifier_value" class="input-field text-sm md:col-span-2" :placeholder="t('admin.shippingCustomers.identifiers.valuePlaceholder')" />
|
||||
<select v-model="form.status" class="input-field text-sm">
|
||||
<option value="pending">{{ t('admin.shippingCustomers.identifierStatus.pending') }}</option>
|
||||
<option value="approved">{{ t('admin.shippingCustomers.identifierStatus.approved') }}</option>
|
||||
</select>
|
||||
<label class="flex items-center gap-2 text-sm text-secondary"><input v-model="form.auto_match_allowed" type="checkbox" :disabled="form.status !== 'approved'" />{{ t('admin.shippingCustomers.identifiers.allowAuto') }}</label>
|
||||
<input v-model="form.remark" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.fields.remark')" />
|
||||
<section class="rounded-xl border border-default p-4 space-y-4">
|
||||
<div><h4 class="font-semibold text-primary">{{ t('admin.shippingCustomers.identifiers.add') }}</h4><p class="text-xs text-muted mt-1">{{ t('admin.shippingCustomers.identifiers.definitionHint') }}</p></div>
|
||||
<p v-if="publishedDefinitions?.disabled_reason" class="text-sm text-amber-700">{{ t('admin.shippingCustomers.identifiers.publishedRuleRequired') }}</p>
|
||||
<div v-else class="grid grid-cols-1 md:grid-cols-3 gap-3">
|
||||
<select v-model="form.target_type" class="input-field text-sm"><option value="customer">{{ t('admin.shippingCustomers.identifiers.targets.customer') }}</option><option value="site">{{ t('admin.shippingCustomers.identifiers.targets.site') }}</option></select>
|
||||
<select v-if="form.target_type === 'site'" v-model.number="form.target_id" class="input-field text-sm"><option :value="undefined">{{ t('admin.shippingCustomers.identifiers.selectSite') }}</option><option v-for="site in customer.sites || []" :key="site.id" :value="site.id">{{ site.site_name }} · {{ site.site_code }}</option></select><div v-else class="input-field text-sm bg-surface-soft">{{ customer.standard_name }}</div>
|
||||
<select v-model="form.definition_id" class="input-field text-sm"><option value="">{{ t('admin.shippingCustomers.identifiers.selectDefinition') }}</option><option v-for="definition in currentDefinitions" :key="definition.id" :value="definition.id">{{ definition.display_name }}</option></select>
|
||||
<input v-model="form.raw_value" class="input-field text-sm md:col-span-2" :placeholder="t('admin.shippingCustomers.identifiers.valuePlaceholder')">
|
||||
<select v-model="form.status" class="input-field text-sm"><option value="pending">{{ t('admin.shippingCustomers.identifierStatus.pending') }}</option><option value="approved">{{ t('admin.shippingCustomers.identifierStatus.approved') }}</option></select>
|
||||
<label class="flex items-center gap-2 text-sm text-secondary"><input v-model="form.auto_match_allowed" type="checkbox" :disabled="form.status !== 'approved' || selectedDefinition?.max_automation !== 'conditional'">{{ t('admin.shippingCustomers.identifiers.allowAuto') }}</label>
|
||||
<input v-model="form.remark" class="input-field text-sm" :placeholder="t('admin.shippingCustomers.fields.remark')">
|
||||
</div>
|
||||
<div class="flex justify-end"><button type="button" class="btn-primary" :disabled="isSaving" @click="submit">{{ t('admin.add') }}</button></div>
|
||||
</div>
|
||||
<p v-if="selectedDefinition && selectedDefinition.max_automation === 'none'" class="text-xs text-muted">{{ t('admin.shippingCustomers.identifiers.manualOnly') }}</p>
|
||||
<div class="flex justify-end"><button type="button" class="btn-primary" :disabled="isSaving || Boolean(publishedDefinitions?.disabled_reason) || !targetReady || !form.definition_id || !form.raw_value.trim()" @click="submitEvidence">{{ t('admin.add') }}</button></div>
|
||||
</section>
|
||||
|
||||
<section class="rounded-xl border border-default overflow-x-auto"><table class="admin-table min-w-[780px]"><thead><tr><th class="px-4 py-3 text-left">{{ t('admin.shippingCustomers.identifiers.definition') }}</th><th class="px-4 py-3 text-left">{{ t('admin.shippingCustomers.identifiers.value') }}</th><th class="px-4 py-3 text-left">{{ t('admin.shippingCustomers.identifiers.status') }}</th><th class="px-4 py-3 text-left">{{ t('admin.shippingCustomers.identifiers.autoMatch') }}</th><th class="px-4 py-3 text-right">{{ t('admin.shippingCustomers.headers.actions') }}</th></tr></thead><tbody><tr v-if="!customer.identity_evidences?.length"><td colspan="5" class="admin-table-empty px-4">{{ t('admin.shippingCustomers.identifiers.empty') }}</td></tr><tr v-for="item in customer.identity_evidences" :key="item.id"><td class="px-4 py-3 text-sm"><div>{{ item.definition?.display_name || item.definition?.definition_code || item.definition_id }}</div><div class="text-xs text-muted">{{ item.definition?.evidence_label }}</div></td><td class="px-4 py-3 text-sm"><div>{{ item.raw_value }}</div><div class="text-xs text-muted">{{ item.normalized_value }}</div></td><td class="px-4 py-3 text-sm">{{ t(`admin.shippingCustomers.identifierStatus.${item.status}`) }}</td><td class="px-4 py-3 text-sm">{{ item.auto_match_allowed ? t('admin.shippingCustomers.yes') : t('admin.shippingCustomers.no') }}</td><td class="px-4 py-3"><div class="flex justify-end gap-2"><button v-if="item.status !== 'approved'" type="button" class="btn-ghost text-xs" @click="emit('updateEvidence', item.id, { status: 'approved' })">{{ t('admin.shippingCustomers.identifiers.approve') }}</button><button v-if="item.status === 'approved' && !item.auto_match_allowed && item.definition?.max_automation === 'conditional'" type="button" class="btn-ghost text-xs" @click="emit('updateEvidence', item.id, { auto_match_allowed: true })">{{ t('admin.shippingCustomers.identifiers.enableAuto') }}</button><button v-if="item.status !== 'disabled'" type="button" class="btn-ghost text-xs text-red-600" @click="emit('updateEvidence', item.id, { status: 'disabled' })">{{ t('admin.shippingCustomers.identifiers.disable') }}</button></div></td></tr></tbody></table></section>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+19
-12
@@ -10,7 +10,7 @@ import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
createShippingCustomer,
|
||||
createShippingCustomerExternalRef,
|
||||
createShippingCustomerIdentifier,
|
||||
createShippingIdentityEvidence,
|
||||
createShippingCustomerSite,
|
||||
deleteShippingCustomer,
|
||||
deactivateShippingCustomer,
|
||||
@@ -27,7 +27,8 @@ import {
|
||||
mergeShippingCustomer,
|
||||
publishShippingCustomerImport,
|
||||
updateShippingCustomer,
|
||||
updateShippingCustomerIdentifier,
|
||||
getShippingPublishedEvidenceDefinitions,
|
||||
updateShippingIdentityEvidence,
|
||||
uploadShippingCustomerImport,
|
||||
} from '@/features/shipping-notice/api/customer-master.api';
|
||||
import type {
|
||||
@@ -39,7 +40,8 @@ import type {
|
||||
ShippingCustomerImportRow,
|
||||
ShippingCustomerRow,
|
||||
ShippingCustomerShadowReport,
|
||||
ShippingIdentifierFormState,
|
||||
ShippingIdentityEvidenceFormState,
|
||||
ShippingPublishedEvidenceDefinitions,
|
||||
} from '@/features/shipping-notice/types/customer-master.types';
|
||||
import {
|
||||
createEmptyShippingCustomerForm,
|
||||
@@ -54,6 +56,7 @@ export function useShippingCustomersAdmin() {
|
||||
const customers = ref<ShippingCustomerRow[]>([]);
|
||||
const importTargetCustomers = ref<ShippingCustomerRow[]>([]);
|
||||
const selectedCustomer = ref<ShippingCustomerRow | null>(null);
|
||||
const publishedEvidenceDefinitions = ref<ShippingPublishedEvidenceDefinitions | null>(null);
|
||||
const customerForm = ref<ShippingCustomerFormState>(createEmptyShippingCustomerForm());
|
||||
const importBatch = ref<ShippingCustomerImportBatch | null>(null);
|
||||
const shadowReport = ref<ShippingCustomerShadowReport | null>(null);
|
||||
@@ -311,7 +314,11 @@ export function useShippingCustomersAdmin() {
|
||||
/** 拉取客户详情并打开识别证据面板。 */
|
||||
const openIdentifiers = async (customer: ShippingCustomerRow): Promise<void> => {
|
||||
try {
|
||||
selectedCustomer.value = await getShippingCustomer(customer.id);
|
||||
const [detail, definitions] = await Promise.all([
|
||||
getShippingCustomer(customer.id), getShippingPublishedEvidenceDefinitions('customer'),
|
||||
]);
|
||||
selectedCustomer.value = detail;
|
||||
publishedEvidenceDefinitions.value = definitions;
|
||||
showIdentifiersPanel.value = true;
|
||||
} catch (error) {
|
||||
showError(error, 'admin.shippingCustomers.msg.loadFailed');
|
||||
@@ -319,17 +326,17 @@ export function useShippingCustomersAdmin() {
|
||||
};
|
||||
|
||||
/** 新增识别证据后刷新当前客户详情和列表计数。 */
|
||||
const addIdentifier = async (form: ShippingIdentifierFormState): Promise<void> => {
|
||||
const addIdentityEvidence = async (form: ShippingIdentityEvidenceFormState): Promise<void> => {
|
||||
if (!selectedCustomer.value) return;
|
||||
if (!form.identifier_value.trim()) {
|
||||
if (!form.definition_id || !form.raw_value.trim() || !form.target_id) {
|
||||
msg.warning(t('admin.shippingCustomers.msg.identifierRequired'));
|
||||
return;
|
||||
}
|
||||
isSaving.value = true;
|
||||
try {
|
||||
await createShippingCustomerIdentifier(selectedCustomer.value.id, {
|
||||
await createShippingIdentityEvidence({
|
||||
...form,
|
||||
identifier_value: form.identifier_value.trim(),
|
||||
raw_value: form.raw_value.trim(),
|
||||
remark: form.remark.trim(),
|
||||
});
|
||||
selectedCustomer.value = await getShippingCustomer(selectedCustomer.value.id);
|
||||
@@ -343,12 +350,12 @@ export function useShippingCustomersAdmin() {
|
||||
};
|
||||
|
||||
/** 更新证据审核状态或自动匹配授权,并刷新详情。 */
|
||||
const updateIdentifier = async (identifierId: number, payload: Record<string, unknown>): Promise<void> => {
|
||||
const updateIdentityEvidence = async (evidenceId: number, payload: Record<string, unknown>): Promise<void> => {
|
||||
if (!selectedCustomer.value) return;
|
||||
try {
|
||||
const reason = window.prompt(t('admin.shippingCustomers.prompts.identifierChangeReason'))?.trim();
|
||||
if (!reason) return;
|
||||
await updateShippingCustomerIdentifier(identifierId, { ...payload, reason });
|
||||
await updateShippingIdentityEvidence(evidenceId, { ...payload, reason });
|
||||
selectedCustomer.value = await getShippingCustomer(selectedCustomer.value.id);
|
||||
} catch (error) {
|
||||
showError(error, 'admin.shippingCustomers.msg.saveFailed');
|
||||
@@ -491,12 +498,12 @@ export function useShippingCustomersAdmin() {
|
||||
};
|
||||
|
||||
return {
|
||||
customers, importTargetCustomers, selectedCustomer, customerForm, importBatch, shadowReport, deleteCustomer, deleteImpact, lifecycleCustomer, lifecycleTimeline, mergeCustomer, mergeImpact,
|
||||
customers, importTargetCustomers, selectedCustomer, publishedEvidenceDefinitions, customerForm, importBatch, shadowReport, deleteCustomer, deleteImpact, lifecycleCustomer, lifecycleTimeline, mergeCustomer, mergeImpact,
|
||||
searchQuery, statusFilter, page, pageSize, total, pages,
|
||||
isLoading, isSaving, isImporting, isShadowLoading,
|
||||
showCustomerModal, showIdentifiersPanel, showImportDialog, showDeleteDialog, showLifecyclePanel, showMergeDialog,
|
||||
loadCustomers, searchCustomers, openCreateCustomer, openEditCustomer, closeCustomerModal,
|
||||
saveCustomer, deactivateCustomer, openLifecycleTimeline, closeLifecycleTimeline, openDeleteCustomer, closeDeleteCustomer, confirmDeleteCustomer, openMergeCustomer, previewMergeCustomer, closeMergeCustomer, confirmMergeCustomer, openIdentifiers, addIdentifier, updateIdentifier, addExternalRef, addSite,
|
||||
saveCustomer, deactivateCustomer, openLifecycleTimeline, closeLifecycleTimeline, openDeleteCustomer, closeDeleteCustomer, confirmDeleteCustomer, openMergeCustomer, previewMergeCustomer, closeMergeCustomer, confirmMergeCustomer, openIdentifiers, addIdentityEvidence, updateIdentityEvidence, addExternalRef, addSite,
|
||||
openImport, uploadImport, decideImportRow, publishImport, downloadTemplate, downloadReconciliation,
|
||||
loadShadowReport, labelShadowResolution,
|
||||
};
|
||||
|
||||
@@ -31,7 +31,9 @@ export interface ShippingCustomerRow {
|
||||
remark?: string | null;
|
||||
case_count: number;
|
||||
identifier_count: number;
|
||||
identity_evidence_count?: number;
|
||||
identifiers?: ShippingCustomerIdentifier[];
|
||||
identity_evidences?: ShippingIdentityEvidence[];
|
||||
external_refs?: ShippingCustomerExternalRef[];
|
||||
sites?: ShippingCustomerSite[];
|
||||
created_at?: string | null;
|
||||
@@ -64,6 +66,42 @@ export interface ShippingCustomerSite {
|
||||
status: string;
|
||||
remark?: string | null;
|
||||
identifiers: Array<Record<string, unknown>>;
|
||||
identity_evidences?: ShippingIdentityEvidence[];
|
||||
}
|
||||
|
||||
export interface ShippingIdentityDefinitionOption {
|
||||
id: string;
|
||||
definition_code: string;
|
||||
display_name: string;
|
||||
description?: string | null;
|
||||
evidence_label: string;
|
||||
target_type: 'customer' | 'site';
|
||||
source_adapter_key: 'email_metadata' | 'document_template' | 'order_field';
|
||||
source_selector: Record<string, unknown>;
|
||||
attribute_key: string;
|
||||
normalizer_key: string;
|
||||
max_automation: 'none' | 'conditional';
|
||||
order_field?: { field_id: string; field_code: string; display_name?: string } | null;
|
||||
}
|
||||
|
||||
export interface ShippingIdentityEvidence {
|
||||
id: number;
|
||||
definition_id: string;
|
||||
definition?: ShippingIdentityDefinitionOption | null;
|
||||
customer_id?: number | null;
|
||||
site_id?: number | null;
|
||||
raw_value: string;
|
||||
normalized_value: string;
|
||||
status: ShippingIdentifierStatus;
|
||||
auto_match_allowed: boolean;
|
||||
remark?: string | null;
|
||||
confirmed_at?: string | null;
|
||||
}
|
||||
|
||||
export interface ShippingPublishedEvidenceDefinitions {
|
||||
rule_set: { id: number; version: number; checksum?: string | null } | null;
|
||||
definitions: ShippingIdentityDefinitionOption[];
|
||||
disabled_reason?: 'published_rule_set_required' | null;
|
||||
}
|
||||
|
||||
export interface ShippingCustomerLifecycleImpact {
|
||||
@@ -84,6 +122,7 @@ export interface ShippingCustomerLifecycleImpact {
|
||||
};
|
||||
cascade: {
|
||||
identifiers: number;
|
||||
identity_evidences: number;
|
||||
sites: number;
|
||||
};
|
||||
}
|
||||
@@ -106,6 +145,8 @@ export interface ShippingCustomerMergeImpact {
|
||||
migrate: {
|
||||
identifiers: number;
|
||||
duplicate_identifiers: number;
|
||||
identity_evidences: number;
|
||||
duplicate_identity_evidences: number;
|
||||
external_references: number;
|
||||
sites: number;
|
||||
};
|
||||
@@ -256,6 +297,16 @@ export interface ShippingIdentifierFormState {
|
||||
remark: string;
|
||||
}
|
||||
|
||||
export interface ShippingIdentityEvidenceFormState {
|
||||
target_type: 'customer' | 'site';
|
||||
target_id?: number;
|
||||
definition_id: string;
|
||||
raw_value: string;
|
||||
status: ShippingIdentifierStatus;
|
||||
auto_match_allowed: boolean;
|
||||
remark: string;
|
||||
}
|
||||
|
||||
/** 创建空客户表单,避免页面和弹窗各自维护默认值。 */
|
||||
export const createEmptyShippingCustomerForm = (): ShippingCustomerFormState => ({
|
||||
standard_name: '',
|
||||
@@ -283,3 +334,13 @@ export const createEmptyShippingIdentifierForm = (): ShippingIdentifierFormState
|
||||
auto_match_allowed: false,
|
||||
remark: '',
|
||||
});
|
||||
|
||||
/** 创建空配置化证据表单;定义下拉必须由当前已发布规则集提供。 */
|
||||
export const createEmptyShippingIdentityEvidenceForm = (): ShippingIdentityEvidenceFormState => ({
|
||||
target_type: 'customer',
|
||||
definition_id: '',
|
||||
raw_value: '',
|
||||
status: 'pending',
|
||||
auto_match_allowed: false,
|
||||
remark: '',
|
||||
});
|
||||
Reference in new issue
Block a user