|
|
@@ -78,14 +78,15 @@
|
|
|
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="720px" destroy-on-close @closed="resetForm">
|
|
|
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
|
|
<el-row :gutter="16">
|
|
|
- <el-col :span="12">
|
|
|
+ <!-- 公司/工厂已降级为系统后台归属字段:前台隐藏输入控件,form 值与 payload 仍由 openCreate 补默认 / openEdit 保值维护。 -->
|
|
|
+ <el-col v-if="false" :span="12">
|
|
|
<el-form-item label="公司" prop="companyRefId">
|
|
|
<el-select v-model="form.companyRefId" clearable filterable placeholder="请选择公司" style="width: 100%">
|
|
|
<el-option v-for="item in companyOptions" :key="item.id" :label="item.name || item.code || `${item.id}`" :value="item.id" />
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
- <el-col :span="12">
|
|
|
+ <el-col v-if="false" :span="12">
|
|
|
<el-form-item label="工厂" prop="factoryRefId">
|
|
|
<el-select
|
|
|
v-model="form.factoryRefId"
|
|
|
@@ -214,6 +215,12 @@ import {
|
|
|
type S0CustMasterRow,
|
|
|
type S0CustMasterUpsert,
|
|
|
} from '../api/s0SalesApi';
|
|
|
+import {
|
|
|
+ applyDefaultOrgScopeForCreate,
|
|
|
+ normalizeOrgScopeForSubmit,
|
|
|
+ preserveOrgScopeForEdit,
|
|
|
+ shouldClearFactoryOnCompanyChange,
|
|
|
+} from '../composables/useS0MfgOrgScope';
|
|
|
|
|
|
const route = useRoute();
|
|
|
const pageTitle = computed(() => (route.meta?.title as string) || '客户信息维护');
|
|
|
@@ -275,26 +282,8 @@ const form = reactive<CustomerFormModel>({
|
|
|
updateUser: '',
|
|
|
});
|
|
|
|
|
|
-function validateRequiredOrgField(message: string) {
|
|
|
- return (_rule: unknown, value: string | number | undefined | null, callback: (error?: Error) => void) => {
|
|
|
- // 组织 ID 语义:已选=非空字符串(雪花 ID),未选=undefined/null/''
|
|
|
- // 禁止 typeof === 'number' 假设,否则会拒绝合法的字符串雪花 ID
|
|
|
- if (value == null) {
|
|
|
- callback(new Error(message));
|
|
|
- return;
|
|
|
- }
|
|
|
- const s = typeof value === 'string' ? value : String(value);
|
|
|
- if (s === '' || s === '0') {
|
|
|
- callback(new Error(message));
|
|
|
- return;
|
|
|
- }
|
|
|
- callback();
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
+// 公司/工厂已降级为系统后台归属字段(新增自动补默认、编辑保留原值),不再作为用户前台必填项。
|
|
|
const rules: FormRules = {
|
|
|
- companyRefId: [{ validator: validateRequiredOrgField('请选择公司'), trigger: 'change' }],
|
|
|
- factoryRefId: [{ validator: validateRequiredOrgField('请选择工厂'), trigger: 'change' }],
|
|
|
cust: [{ required: true, message: '请填写客户编码', trigger: 'blur' }],
|
|
|
sortName: [{ required: true, message: '请填写客户简称', trigger: 'blur' }],
|
|
|
};
|
|
|
@@ -374,7 +363,9 @@ function buildPayload(): S0CustMasterUpsert | null {
|
|
|
watch(
|
|
|
() => form.companyRefId,
|
|
|
() => {
|
|
|
- if (!formFactoryOptions.value.some((item) => item.id === form.factoryRefId)) {
|
|
|
+ // 公司/工厂为隐藏的后台归属字段,此变化均为程序化载入(openCreate 补默认 / openEdit 回填),
|
|
|
+ // 非用户主动切换,故 userInitiated=false,永不清空已载入的工厂/域值(保护 legacy 归属)。
|
|
|
+ if (shouldClearFactoryOnCompanyChange(formFactoryOptions.value, form.factoryRefId, false)) {
|
|
|
form.factoryRefId = undefined;
|
|
|
form.domainCode = '';
|
|
|
}
|
|
|
@@ -473,6 +464,8 @@ function resetForm() {
|
|
|
|
|
|
function openCreate() {
|
|
|
resetForm();
|
|
|
+ // 新增:自动补默认 SysOrg 归属(公司/工厂/domainCode),用户无需选择公司/工厂。
|
|
|
+ applyDefaultOrgScopeForCreate(form, companyOptions.value, factoryOptions.value);
|
|
|
dialogTitle.value = '新增客户';
|
|
|
dialogVisible.value = true;
|
|
|
}
|
|
|
@@ -507,16 +500,15 @@ function openEdit(row: S0CustMasterRow) {
|
|
|
createUser: row.createUser ?? '',
|
|
|
updateUser: row.updateUser ?? '',
|
|
|
});
|
|
|
+ // 编辑:保留接口返回的原归属(legacy 值不转雪花)。
|
|
|
+ preserveOrgScopeForEdit(form, row);
|
|
|
dialogVisible.value = true;
|
|
|
}
|
|
|
|
|
|
async function submitForm() {
|
|
|
- if (selectedCompanyHasNoFactories.value) {
|
|
|
- ElMessage.warning('所选公司下暂无可用工厂,请先维护组织数据或机构权限。');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
await formRef.value?.validate();
|
|
|
+ // 提交前统一归属:缺则补默认、有则保留(含 legacy),不做 legacy↔雪花映射。
|
|
|
+ normalizeOrgScopeForSubmit(form, editingId.value ? 'edit' : 'create', companyOptions.value, factoryOptions.value);
|
|
|
saving.value = true;
|
|
|
try {
|
|
|
const payload = buildPayload();
|