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="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) {