Browse Source

优化代码

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

178
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 switch (sampleType) {
} case '1':
if(item.field == "sampleProgCode"){ sampleSizeLabel = '样品量';
item.componentProps.disabled = true sampleSizeDisabled = true;
} break;
}) case '2':
setV["sampleSize"] = '' sampleSizeLabel = '样品量(%)';
setV["sampleProgCode"] = '' sampleSizeRequired = true;
break;
SamplingProcessRules.sampleSize[0].required = false; case '3':
SamplingProcessRules.sampleProgCode[0].required = false; sampleSizeLabel = '样品量';
}else if(field == 'sampleType'&& value == '2'){ sampleSizeRequired = true;
SamplingProcess.allSchemas.formSchema.forEach(item=>{ break;
if(item.field == "sampleSize"){ case '4':
item.label='样品量(%)' sampleSizeLabel = '样品量';
item.component = 'Input' sampleSizeDisabled = true;
item.componentProps.disabled = false sampleProgCodeDisabled = false;
} sampleProgCodeRequired = true;
if(item.field == "sampleProgCode"){ break;
item.componentProps.disabled = true 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=>{
if(item.field == "sampleSize"){
item.componentProps.disabled = true
}
if(item.field == "sampleProgCode"){
item.component = 'Select'
item.componentProps.disabled = false
}
})
setV["sampleSize"] = ''
SamplingProcessRules.sampleSize[0].required = false;
SamplingProcessRules.sampleProgCode[0].required = true;
} }
nextTick(() => {
formRef.value.setValues(setV); SamplingProcess.allSchemas.formSchema.forEach(item => {
if (item.field === 'sampleSize') {
item.label = sampleSizeLabel;
item.componentProps.disabled = sampleSizeDisabled;
}
if (item.field === 'sampleProgCode') {
item.componentProps.disabled = sampleProgCodeDisabled;
}
}); });
}
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