Browse Source

批量修改传参问题

java8
han\hanst 12 months ago
parent
commit
d35fe1760e
  1. 42
      src/views/modules/part/bom_create.vue

42
src/views/modules/part/bom_create.vue

@ -548,7 +548,7 @@
<el-dialog title="批量修改" :close-on-click-modal="false" v-drag :visible.sync="batchUpdateComponentsFlag" width="1500px">
<div class="rq ">
<el-table
:data="subDetailList"
:data="batchUpdateList"
height="286px"
border
style="width:100%">
@ -1017,6 +1017,7 @@ export default {
checkedDetail: [],
detailDataList: [],
subDetailList: [],
batchUpdateList: [], // 批量修改临时数据,避免直接修改原数据
componentPartList: [],
componentPartList1: [],
batchComponentPartList: [],
@ -3944,21 +3945,32 @@ export default {
this.getDataList()
},
/**
* 打开批量修改弹窗
* 深拷贝 subDetailList 到 batchUpdateList,避免修改时影响原数据
*/
batchUpdateComponents() {
// 深拷贝数据,确保修改时不影响原表格
this.batchUpdateList = JSON.parse(JSON.stringify(this.subDetailList))
this.batchUpdateComponentsFlag = true
},
/**
* 保存批量修改
* 使用 batchUpdateList 临时数据进行修改和保存
* 成功后同步回 subDetailList
*/
async batchUpdateComponentsSave() {
// 开启loading
this.batchUpdateSaveLoading = true
let flag = true
// 保存原始列表长度
const listLength = this.subDetailList.length
const listLength = this.batchUpdateList.length
for (let i = 0; i < listLength; i++) {
// 每次从最新的列表中获取数据,因为前面的计算可能已经更新了列表
let row = this.subDetailList[i]
let row = this.batchUpdateList[i]
this.componentData = {
flag: '2',
site: row.site,
@ -4050,8 +4062,25 @@ export default {
try {
const {data} = await computeQtyPerAssemblyEdit(this.componentData)
if (data && data.code === 0) {
// 更新列表数据
this.subDetailList = data.rows.subDetailList
// 从后端返回的列表中找到当前行(通过 componentPart 和 lineSequence 匹配)
// 然后只更新该行的计算字段,保留用户在弹窗中修改的其他行数据
const returnedList = data.rows.subDetailList || []
const currentRow = this.batchUpdateList[i]
// 在返回的列表中找到对应的行
const updatedRow = returnedList.find(item =>
item.componentPart === currentRow.componentPart &&
item.lineSequence === currentRow.lineSequence
)
if (updatedRow) {
// 只更新计算相关的字段,保留用户修改的其他字段
this.$set(this.batchUpdateList, i, {
...this.batchUpdateList[i],
qtyPerAssembly: updatedRow.qtyPerAssembly, // 单位用量(存储过程计算)
formula: updatedRow.formula, // 计算公式(setFormula方法设置)
})
}
} else if (data && data.code !== 0) {
flag = false
this.batchUpdateSaveLoading = false
@ -4074,6 +4103,9 @@ export default {
this.batchUpdateSaveLoading = false
if(flag) {
// 保存成功后,将修改后的数据同步回原数据
this.subDetailList = JSON.parse(JSON.stringify(this.batchUpdateList))
this.$message({
message: '批量修改并计算完成',
type: 'success',

Loading…
Cancel
Save