fix(techproc): 修复工序表单初始化及选择逻辑

This commit is contained in:
zxy 2026-04-14 16:58:20 +08:00
parent 58650bccee
commit d381961a9a

View File

@ -29,6 +29,7 @@
<div style="padding: 0 10px;">
<div style="font-weight: bold; margin-bottom: 12px; color: #606266;">工序信息</div>
<el-table
ref="procTable"
:data="procList"
:border="true"
:style="{ width: '100%', maxHeight: '300px', overflow: 'auto' }"
@ -95,6 +96,8 @@ export default {
enabledStatusProps: { label: "fullName", value: "id" },
procList: [],
selectedProcs: [],
procListLoaded: false,
pendingEditId: null,
}
},
computed: {
@ -106,8 +109,17 @@ export default {
methods: {
init(id) {
this.dataForm.id = id || '';
this.pendingEditId = this.dataForm.id;
this.dialogVisible = true;
this.loading = true;
//
if (this.procListLoaded) {
this.doInit();
}
},
//
doInit() {
this.$nextTick(() => {
this.$refs.formRef.resetFields();
if (this.dataForm.id) {
@ -117,7 +129,9 @@ export default {
}).then(res => {
this.dataForm = res.data
//
this.convertCodeToName(res.data.techProc)
this.techProcDisplay = this.convertCodeToName(res.data.techProc)
//
this.setSelectedRows(res.data.procList || res.data.techProc)
this.loading = false
})
} else {
@ -132,20 +146,50 @@ export default {
method: 'get'
}).then(res => {
this.procList = res.data || [];
this.procListLoaded = true;
// ID
if (this.pendingEditId && this.dialogVisible) {
this.doInit();
}
});
},
//
convertCodeToName(codeStr) {
if (!codeStr) {
this.techProcDisplay = ''
return
return ''
}
const codes = codeStr.split('_')
const names = codes.map(code => {
const proc = this.procList.find(item => item.procCd === code)
return proc ? proc.procName : code
})
this.techProcDisplay = names.join('_')
return names.join('_')
},
//
setSelectedRows(procCodes) {
if (!procCodes || !this.$refs.procTable) {
return
}
let codes = []
if (Array.isArray(procCodes)) {
//
codes = procCodes
} else if (typeof procCodes === 'string') {
//
codes = procCodes.split('_')
}
if (codes.length > 0) {
const selectedRows = this.procList.filter(item => codes.includes(item.procCd))
this.selectedProcs = selectedRows
//
setTimeout(() => {
selectedRows.forEach(row => {
this.$refs.procTable.toggleRowSelection(row, true)
})
}, 100)
}
},
// -
handleProcSelectionChange(val) {
@ -192,6 +236,7 @@ export default {
},
handleClose() {
this.dialogVisible = false;
this.pendingEditId = null;
this.$emit('refresh',true)
},
changeData(model, index) {