油漆实验室
This commit is contained in:
@@ -398,89 +398,92 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
async saveAllChanges() {
|
||||
if (Object.keys(this.modifiedRows).length === 0) {
|
||||
this.$message.warning("没有需要保存的修改");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 创建分组映射
|
||||
const groupMap = new Map();
|
||||
|
||||
// 遍历所有修改的行
|
||||
Object.values(this.modifiedRows).forEach((row) => {
|
||||
// 找到当前行在表格中的索引
|
||||
const rowIndex = this.qualityStatistics.findIndex(
|
||||
(r) => r.id === row.id
|
||||
);
|
||||
// 计算所属分组的起始索引(每6行一组)
|
||||
const groupIndex = Math.floor(rowIndex / 6) * 6;
|
||||
|
||||
// 如果该组还未创建,初始化分组
|
||||
if (!groupMap.has(groupIndex)) {
|
||||
groupMap.set(groupIndex, {
|
||||
baseRow: this.qualityStatistics[groupIndex],
|
||||
modifiedRows: new Set(),
|
||||
});
|
||||
async saveAllChanges() {
|
||||
if (Object.keys(this.modifiedRows).length === 0) {
|
||||
this.$message.warning("没有需要保存的修改");
|
||||
return;
|
||||
}
|
||||
|
||||
// 将修改行添加到对应分组
|
||||
const group = groupMap.get(groupIndex);
|
||||
group.modifiedRows.add(rowIndex % 6); // 记录组内修改的位置
|
||||
});
|
||||
try {
|
||||
// 创建分组映射
|
||||
const groupMap = new Map();
|
||||
|
||||
// 构建最终更新数据
|
||||
const updateList = [];
|
||||
groupMap.forEach((group, groupIndex) => {
|
||||
const groupRows = this.qualityStatistics.slice(
|
||||
groupIndex,
|
||||
groupIndex + 6
|
||||
);
|
||||
// 遍历所有修改的行
|
||||
Object.values(this.modifiedRows).forEach((row) => {
|
||||
// 找到当前行在表格中的索引
|
||||
const rowIndex = this.qualityStatistics.findIndex(
|
||||
(r) => r.id === row.id
|
||||
);
|
||||
// 计算所属分组的起始索引(每6行一组)
|
||||
const groupIndex = Math.floor(rowIndex / 6) * 6;
|
||||
|
||||
// 生成6条更新记录(即使部分未修改)
|
||||
Array.from({ length: 6 }).forEach((_, i) => {
|
||||
const row = groupRows[i] || {};
|
||||
updateList.push({
|
||||
id: row.id,
|
||||
plIdGroup: row.idGroup,
|
||||
description: group.baseRow.description,
|
||||
plCode: group.baseRow.code,
|
||||
plPci: group.baseRow.pci,
|
||||
plValue01: row.value01,
|
||||
plValue02: row.value02,
|
||||
plValue03: row.value03,
|
||||
plValue04: row.value04,
|
||||
plValue05: row.value05,
|
||||
plValue06: group.baseRow.value06,
|
||||
plValue07: group.baseRow.value07,
|
||||
plValue08: group.baseRow.value08,
|
||||
plValue09: row.value09,
|
||||
plValue10: row.value10,
|
||||
plValue11: row.value11,
|
||||
plCreatedBy: row.createdBy,
|
||||
plCreatedTime: row.createdTime,
|
||||
plUpdatedBy: row.updatedBy,
|
||||
plUpdatedTime: row.updatedTime,
|
||||
// 如果该组还未创建,初始化分组
|
||||
if (!groupMap.has(groupIndex)) {
|
||||
groupMap.set(groupIndex, {
|
||||
baseRow: this.qualityStatistics[groupIndex],
|
||||
modifiedRows: new Set(),
|
||||
});
|
||||
}
|
||||
|
||||
// 将修改行添加到对应分组
|
||||
const group = groupMap.get(groupIndex);
|
||||
group.modifiedRows.add(rowIndex % 6); // 记录组内修改的位置
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const { code, data } = await UpdateRawMateriallist(updateList);
|
||||
if (code === 200) {
|
||||
this.$message.success(`成功保存${data}条记录`);
|
||||
this.modifiedRows = {};
|
||||
await this.fetchData();
|
||||
// 保持合并单元格状态
|
||||
this.mergeTableRows(6);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("保存失败:", error);
|
||||
this.$message.error(
|
||||
"保存失败: " + (error.response?.data?.message || error.message)
|
||||
);
|
||||
}
|
||||
},
|
||||
// 构建最终更新数据
|
||||
const updateList = [];
|
||||
groupMap.forEach((group, groupIndex) => {
|
||||
const groupRows = this.qualityStatistics.slice(
|
||||
groupIndex,
|
||||
groupIndex + 6
|
||||
);
|
||||
|
||||
// 生成6条更新记录(即使部分未修改)
|
||||
Array.from({ length: 6 }).forEach((_, i) => {
|
||||
const row = groupRows[i] || {};
|
||||
if (group.baseRow == undefined) {
|
||||
throw new Error("需要保存的数据不在当前页");
|
||||
}
|
||||
updateList.push({
|
||||
id: row.id,
|
||||
plIdGroup: row.idGroup,
|
||||
description: group.baseRow.description,
|
||||
plCode: group.baseRow.code,
|
||||
plPci: group.baseRow.pci,
|
||||
plValue01: row.value01,
|
||||
plValue02: row.value02,
|
||||
plValue03: row.value03,
|
||||
plValue04: row.value04,
|
||||
plValue05: row.value05,
|
||||
plValue06: group.baseRow.value06,
|
||||
plValue07: group.baseRow.value07,
|
||||
plValue08: group.baseRow.value08,
|
||||
plValue09: row.value09,
|
||||
plValue10: row.value10,
|
||||
plValue11: row.value11,
|
||||
plCreatedBy: row.createdBy,
|
||||
plCreatedTime: row.createdTime,
|
||||
plUpdatedBy: row.updatedBy,
|
||||
plUpdatedTime: row.updatedTime,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const { code, data } = await UpdateRawMateriallist(updateList);
|
||||
if (code === 200) {
|
||||
this.$message.success(`成功保存${data}条记录`);
|
||||
this.modifiedRows = {};
|
||||
await this.fetchData();
|
||||
// 保持合并单元格状态
|
||||
this.mergeTableRows(6);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("保存失败:", error);
|
||||
this.$message.error(
|
||||
"保存失败: " + (error.response?.data?.message || error.message)
|
||||
);
|
||||
}
|
||||
},
|
||||
updateUser(value) {
|
||||
console.log(value);
|
||||
},
|
||||
@@ -491,42 +494,46 @@ export default {
|
||||
if (res.code === 200) this.fetchData();
|
||||
});
|
||||
},
|
||||
async fetchData() {
|
||||
try {
|
||||
this.isLoading = true;
|
||||
|
||||
const query = {
|
||||
startDate: this.$dayjs(this.searchForm.startDate).format('YYYY-MM-DDTHH:mm:ss'),
|
||||
endDate: this.$dayjs(this.searchForm.endDate).format('YYYY-MM-DDTHH:mm:ss'),
|
||||
batchNumber: this.searchForm.batchNumber || undefined,
|
||||
colorCode: this.searchForm.colorCode || undefined,
|
||||
productDescription: this.searchForm.productDescription || undefined,
|
||||
pageNum: this.pagination.currentPage,
|
||||
pageSize: this.pagination.pageSize
|
||||
};
|
||||
async fetchData() {
|
||||
try {
|
||||
this.isLoading = true;
|
||||
|
||||
const { code, data } = await GetRawMateriallist(query);
|
||||
if (code === 200) {
|
||||
this.qualityStatistics = data.item1.map(item => ({
|
||||
...item,
|
||||
dt: this.$dayjs(item.dt).isValid()
|
||||
? this.$dayjs(item.dt).format('YYYY-MM-DD HH:mm:ss')
|
||||
: null
|
||||
}));
|
||||
const query = {
|
||||
startDate: this.$dayjs(this.searchForm.startDate).format(
|
||||
"YYYY-MM-DDTHH:mm:ss"
|
||||
),
|
||||
endDate: this.$dayjs(this.searchForm.endDate).format(
|
||||
"YYYY-MM-DDTHH:mm:ss"
|
||||
),
|
||||
batchNumber: this.searchForm.batchNumber || undefined,
|
||||
colorCode: this.searchForm.colorCode || undefined,
|
||||
productDescription: this.searchForm.productDescription || undefined,
|
||||
pageNum: this.pagination.currentPage,
|
||||
pageSize: this.pagination.pageSize,
|
||||
};
|
||||
|
||||
this.pagination.total = data.item2;
|
||||
this.realTotal = Math.ceil(data.item2 / 5); // 根据实际分组调整
|
||||
this.$nextTick(() => this.mergeTableRows(5)); // 根据实际分组调整
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("数据加载失败:", error);
|
||||
this.$message.error(
|
||||
"数据加载失败: " + (error.response?.data?.message || error.message)
|
||||
);
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
},
|
||||
const { code, data } = await GetRawMateriallist(query);
|
||||
if (code === 200) {
|
||||
this.qualityStatistics = data.item1.map((item) => ({
|
||||
...item,
|
||||
dt: this.$dayjs(item.dt).isValid()
|
||||
? this.$dayjs(item.dt).format("YYYY-MM-DD HH:mm:ss")
|
||||
: null,
|
||||
}));
|
||||
|
||||
this.pagination.total = data.item2;
|
||||
this.realTotal = Math.ceil(data.item2 / 5); // 根据实际分组调整
|
||||
this.$nextTick(() => this.mergeTableRows(5)); // 根据实际分组调整
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("数据加载失败:", error);
|
||||
this.$message.error(
|
||||
"数据加载失败: " + (error.response?.data?.message || error.message)
|
||||
);
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
},
|
||||
// fetchData() {
|
||||
// this.isLoading = true;
|
||||
// setTimeout(() => (this.isLoading = false), 30000);
|
||||
|
||||
Reference in New Issue
Block a user