fix(techproc): 修复工序表单初始化及选择逻辑
This commit is contained in:
parent
58650bccee
commit
d381961a9a
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user