Browse Source

优化代码

master_hella_20240701
zhaoyiran 7 months ago
parent
commit
1a11456ccf
  1. 168
      src/views/qms/samplingProcess/index.vue

168
src/views/qms/samplingProcess/index.vue

@ -149,65 +149,6 @@ const buttonTableClick = async (val, row) => {
/** 添加/修改操作 */ /** 添加/修改操作 */
const basicFormRef = ref() const basicFormRef = ref()
const openForm = async (type: string, row?: any) => {
basicFormRef.value.open(type, row)
SamplingProcess.allSchemas.formSchema.forEach(item=>{
if(item.field =="sampleType"){
if(row.sampleType == "1"){
SamplingProcess.allSchemas.formSchema.forEach(item=>{
if(item.field == "sampleSize"){
item.label='样品量'
item.component = 'Input'
item.componentProps.disabled = true
}
if(item.field == "sampleProgCode"){
item.componentProps.disabled = true
}
})
SamplingProcessRules.sampleSize[0].required = false;
SamplingProcessRules.sampleProgCode[0].required = false;
}else if(row.sampleType == "2"){
SamplingProcess.allSchemas.formSchema.forEach(item=>{
if(item.field == "sampleSize"){
item.label='样品量(%)'
item.component = 'Input'
item.componentProps.disabled = false
}
if(item.field == "sampleProgCode"){
item.componentProps.disabled = true
}
})
SamplingProcessRules.sampleSize[0].required = true;
SamplingProcessRules.sampleProgCode[0].required = false;
}else if(row.sampleType == "3"){
SamplingProcess.allSchemas.formSchema.forEach(item=>{
if(item.field == "sampleSize"){
item.label='样品量'
item.component = 'Input'
item.componentProps.disabled = false
}
if(item.field == "sampleProgCode"){
item.componentProps.disabled = true
}
})
SamplingProcessRules.sampleSize[0].required = true;
SamplingProcessRules.sampleProgCode[0].required = false;
}else if(row.sampleType == "4"){
SamplingProcess.allSchemas.formSchema.forEach(item=>{
if(item.field == "sampleSize"){
item.componentProps.disabled = true
}
if(item.field == "sampleProgCode"){
item.component = 'Select'
item.componentProps.disabled = false
}
})
SamplingProcessRules.sampleSize[0].required = false;
SamplingProcessRules.sampleProgCode[0].required = true;
}
}
})
}
// form // form
const formsSuccess = async (formType,data) => { const formsSuccess = async (formType,data) => {
@ -283,70 +224,65 @@ const importSuccess = () => {
getList() getList()
} }
const onChange =async (field,value, formRef)=>{ const updateFormFields = (sampleType, formRef) => {
const setV = {}; let sampleSizeLabel = '';
if(field == 'sampleType'&& value == '1'){ let sampleSizeDisabled = false;
SamplingProcess.allSchemas.formSchema.forEach(item=>{ let sampleProgCodeDisabled = true;
if(item.field == "sampleSize"){ let sampleSizeRequired = false;
item.label='样品量' let sampleProgCodeRequired = false;
item.component = 'Input'
item.componentProps.disabled = true
}
if(item.field == "sampleProgCode"){
item.componentProps.disabled = true
}
})
setV["sampleSize"] = ''
setV["sampleProgCode"] = ''
SamplingProcessRules.sampleSize[0].required = false; switch (sampleType) {
SamplingProcessRules.sampleProgCode[0].required = false; case '1':
}else if(field == 'sampleType'&& value == '2'){ sampleSizeLabel = '样品量';
SamplingProcess.allSchemas.formSchema.forEach(item=>{ sampleSizeDisabled = true;
if(item.field == "sampleSize"){ break;
item.label='样品量(%)' case '2':
item.component = 'Input' sampleSizeLabel = '样品量(%)';
item.componentProps.disabled = false sampleSizeRequired = true;
} break;
if(item.field == "sampleProgCode"){ case '3':
item.componentProps.disabled = true sampleSizeLabel = '样品量';
sampleSizeRequired = true;
break;
case '4':
sampleSizeLabel = '样品量';
sampleSizeDisabled = true;
sampleProgCodeDisabled = false;
sampleProgCodeRequired = true;
break;
default:
break;
} }
})
setV["sampleProgCode"] = ''
SamplingProcessRules.sampleSize[0].required = true;
SamplingProcessRules.sampleProgCode[0].required = false;
}else if(field == 'sampleType'&& value == '3'){
SamplingProcess.allSchemas.formSchema.forEach(item=>{
if(item.field == "sampleSize"){
item.label='样品量'
item.component = 'Input'
item.componentProps.disabled = false
}
if(item.field == "sampleProgCode"){
item.componentProps.disabled = true
}
})
setV["sampleProgCode"] = ''
SamplingProcessRules.sampleSize[0].required = true;
SamplingProcessRules.sampleProgCode[0].required = false;
}else if(field == 'sampleType'&& value == '4'){
SamplingProcess.allSchemas.formSchema.forEach(item => { SamplingProcess.allSchemas.formSchema.forEach(item => {
if(item.field == "sampleSize"){ if (item.field === 'sampleSize') {
item.componentProps.disabled = true item.label = sampleSizeLabel;
} item.componentProps.disabled = sampleSizeDisabled;
if(item.field == "sampleProgCode"){
item.component = 'Select'
item.componentProps.disabled = false
} }
}) if (item.field === 'sampleProgCode') {
setV["sampleSize"] = '' item.componentProps.disabled = sampleProgCodeDisabled;
SamplingProcessRules.sampleSize[0].required = false;
SamplingProcessRules.sampleProgCode[0].required = true;
} }
nextTick(() => {
formRef.value.setValues(setV);
}); });
SamplingProcessRules.sampleSize[0].required = sampleSizeRequired;
SamplingProcessRules.sampleProgCode[0].required = sampleProgCodeRequired;
formRef.value.setValues({
sampleSize: '',
sampleProgCode: '',
});
};
const openForm = async (type, row) => {
basicFormRef.value.open(type, row);
updateFormFields(row.sampleType, basicFormRef);
};
const onChange = async (field, value, formRef) => {
if (field === 'sampleType') {
updateFormFields(value, formRef);
} }
};
// //
const searchFormClick = (searchData) => { const searchFormClick = (searchData) => {

Loading…
Cancel
Save