Files
syops/frontend/src/features/shipping-notice/customers/components/CustomerIdentifiersPanel.vue
T

139 lines
9.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!--
features/shipping-notice/customers/components/CustomerIdentifiersPanel.vue
用途:展示、新增、审核和停用客户识别证据。
依赖:customer-master.types、vue-i18n。
逻辑:所有修改通过事件上送 composable;本组件不直接访问 API。
-->
<script setup lang="ts">
import { ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import type {
ShippingCustomerRow,
ShippingIdentifierFormState,
} from '@/features/shipping-notice/types/customer-master.types';
import { createEmptyShippingIdentifierForm } from '@/features/shipping-notice/types/customer-master.types';
const props = defineProps<{ visible: boolean; customer: ShippingCustomerRow | null; isSaving: boolean }>();
const emit = defineEmits<{
close: [];
add: [form: ShippingIdentifierFormState];
update: [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 externalRefForm = ref({ source_system: '', customer_code: '' });
const siteForm = ref({ site_name: '', site_code: '', address: '', city: '', country: '', remark: '' });
/** 切换客户或关闭面板时清空未提交证据。 */
watch(() => [props.visible, props.customer?.id], () => {
form.value = createEmptyShippingIdentifierForm();
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();
};
/** 提交来源系统客户编码;客户简称仍由客户基本信息统一维护。 */
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: '' };
};
</script>
<template>
<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>
<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">
<section class="rounded-xl border border-default p-4 space-y-4">
<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>
</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>
<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="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')" />
</div>
<div class="flex justify-end"><button type="button" class="btn-primary" :disabled="isSaving" @click="submit">{{ t('admin.add') }}</button></div>
</div>
</div>
</div>
</div>
</template>