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 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
const formsSuccess = async (formType,data) => {
@ -283,70 +224,65 @@ const importSuccess = () => {
getList()
}
const onChange =async (field,value, formRef)=>{
const setV = {};
if(field == 'sampleType'&& value == '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
}
})
setV["sampleSize"] = ''
setV["sampleProgCode"] = ''
const updateFormFields = (sampleType, formRef) => {
let sampleSizeLabel = '';
let sampleSizeDisabled = false;
let sampleProgCodeDisabled = true;
let sampleSizeRequired = false;
let sampleProgCodeRequired = false;
SamplingProcessRules.sampleSize[0].required = false;
SamplingProcessRules.sampleProgCode[0].required = false;
}else if(field == 'sampleType'&& value == '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
switch (sampleType) {
case '1':
sampleSizeLabel = '样品量';
sampleSizeDisabled = true;
break;
case '2':
sampleSizeLabel = '样品量(%)';
sampleSizeRequired = true;
break;
case '3':
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 => {
if(item.field == "sampleSize"){
item.componentProps.disabled = true
}
if(item.field == "sampleProgCode"){
item.component = 'Select'
item.componentProps.disabled = false
if (item.field === 'sampleSize') {
item.label = sampleSizeLabel;
item.componentProps.disabled = sampleSizeDisabled;
}
})
setV["sampleSize"] = ''
SamplingProcessRules.sampleSize[0].required = false;
SamplingProcessRules.sampleProgCode[0].required = true;
if (item.field === 'sampleProgCode') {
item.componentProps.disabled = sampleProgCodeDisabled;
}
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) => {

Loading…
Cancel
Save