fix(techproc): 修复工序表单初始化及选择逻辑
This commit is contained in:
parent
58650bccee
commit
d381961a9a
@ -29,6 +29,7 @@
|
|||||||
<div style="padding: 0 10px;">
|
<div style="padding: 0 10px;">
|
||||||
<div style="font-weight: bold; margin-bottom: 12px; color: #606266;">工序信息</div>
|
<div style="font-weight: bold; margin-bottom: 12px; color: #606266;">工序信息</div>
|
||||||
<el-table
|
<el-table
|
||||||
|
ref="procTable"
|
||||||
:data="procList"
|
:data="procList"
|
||||||
:border="true"
|
:border="true"
|
||||||
:style="{ width: '100%', maxHeight: '300px', overflow: 'auto' }"
|
:style="{ width: '100%', maxHeight: '300px', overflow: 'auto' }"
|
||||||
@ -95,6 +96,8 @@ export default {
|
|||||||
enabledStatusProps: { label: "fullName", value: "id" },
|
enabledStatusProps: { label: "fullName", value: "id" },
|
||||||
procList: [],
|
procList: [],
|
||||||
selectedProcs: [],
|
selectedProcs: [],
|
||||||
|
procListLoaded: false,
|
||||||
|
pendingEditId: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -106,8 +109,17 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
init(id) {
|
init(id) {
|
||||||
this.dataForm.id = id || '';
|
this.dataForm.id = id || '';
|
||||||
|
this.pendingEditId = this.dataForm.id;
|
||||||
this.dialogVisible = true;
|
this.dialogVisible = true;
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
|
// 如果工序列表已加载,直接初始化;否则等待加载完成
|
||||||
|
if (this.procListLoaded) {
|
||||||
|
this.doInit();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 实际初始化逻辑
|
||||||
|
doInit() {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.$refs.formRef.resetFields();
|
this.$refs.formRef.resetFields();
|
||||||
if (this.dataForm.id) {
|
if (this.dataForm.id) {
|
||||||
@ -117,7 +129,9 @@ export default {
|
|||||||
}).then(res => {
|
}).then(res => {
|
||||||
this.dataForm = res.data
|
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
|
this.loading = false
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@ -132,20 +146,50 @@ export default {
|
|||||||
method: 'get'
|
method: 'get'
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
this.procList = res.data || [];
|
this.procList = res.data || [];
|
||||||
|
this.procListLoaded = true;
|
||||||
|
// 如果有等待编辑的ID,继续初始化
|
||||||
|
if (this.pendingEditId && this.dialogVisible) {
|
||||||
|
this.doInit();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 将编码拼接转换为名称拼接显示
|
// 将编码拼接转换为名称拼接显示
|
||||||
convertCodeToName(codeStr) {
|
convertCodeToName(codeStr) {
|
||||||
if (!codeStr) {
|
if (!codeStr) {
|
||||||
this.techProcDisplay = ''
|
return ''
|
||||||
return
|
|
||||||
}
|
}
|
||||||
const codes = codeStr.split('_')
|
const codes = codeStr.split('_')
|
||||||
const names = codes.map(code => {
|
const names = codes.map(code => {
|
||||||
const proc = this.procList.find(item => item.procCd === code)
|
const proc = this.procList.find(item => item.procCd === code)
|
||||||
return proc ? proc.procName : 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) {
|
handleProcSelectionChange(val) {
|
||||||
@ -192,6 +236,7 @@ export default {
|
|||||||
},
|
},
|
||||||
handleClose() {
|
handleClose() {
|
||||||
this.dialogVisible = false;
|
this.dialogVisible = false;
|
||||||
|
this.pendingEditId = null;
|
||||||
this.$emit('refresh',true)
|
this.$emit('refresh',true)
|
||||||
},
|
},
|
||||||
changeData(model, index) {
|
changeData(model, index) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user