diff --git a/js/aq_demand_plan/child/choose_tool_type_list.js b/js/aq_demand_plan/child/choose_tool_type_list.js index 5d280f2..03fc8e0 100644 --- a/js/aq_demand_plan/child/choose_tool_type_list.js +++ b/js/aq_demand_plan/child/choose_tool_type_list.js @@ -411,37 +411,49 @@ function importExcel() { $("#articleImageFile").val(""); } + function updateTableWithImportedData(data) { - // 更新当前表格中显示的数据 - const tableData = table.cache.currentTableId || [] - let updated = false + const tableData = table.cache.currentTableId || []; + let updated = false; + // 自动勾选当前行 + data.map((item) => { + if (!huancun.includes(item.id)) { + item.needNum = sanitizeNeedNum(item.needNum); + huancun.push(item.id); + huancunObj.push(item); + updateOrAddObject(item.id, item); + } + }) - // 遍历当前表格数据,更新匹配的行 for (let i = 0; i < tableData.length; i++) { - const rowData = tableData[i] - // 在导入数据中查找匹配项 - const importedItem = data.find((item) => item.id === rowData.id) + const rowData = tableData[i]; + const importedItem = data.find(item => item.id === rowData.id); if (importedItem) { - // 更新表格数据 - rowData.needNum = importedItem.needNum - rowData.times = importedItem.times - rowData.remarks = importedItem.remarks - updated = true + const needNum = Number(importedItem.needNum) || ""; + const times = importedItem.times || ""; + const remarks = importedItem.remarks || ""; - // 更新表格中对应单元格的显示 - const rowIndex = rowData.LAY_INDEX - // 更新需用量单元格 - $(`tr[data-index="${rowIndex}"] td[data-field="needNum"] .layui-table-cell`).text(importedItem.needNum || "") - // 更新预计使用时间单元格 - $(`tr[data-index="${rowIndex}"] td[data-field="times"] .layui-table-cell`).text(importedItem.times || "") - // 更新备注单元格 - $(`tr[data-index="${rowIndex}"] td[data-field="remarks"] .layui-table-cell`).text(importedItem.remarks || "") + rowData.needNum = needNum; + rowData.times = times; + rowData.remarks = remarks; + updated = true; + + const rowIndex = rowData.LAY_INDEX; + if (typeof rowIndex !== "undefined") { + $(`tr[data-index="${rowIndex}"] td[data-field="needNum"] .layui-table-cell`).text(needNum); + $(`tr[data-index="${rowIndex}"] td[data-field="times"] .layui-table-cell`).text(times); + $(`tr[data-index="${rowIndex}"] td[data-field="remarks"] .layui-table-cell`).text(remarks); + } + // 设置复选框选中样式 + $(`tr[data-index="${rowIndex}"] input[type="checkbox"]`).prop('checked', true); + $(`tr[data-index="${rowIndex}"] input[type="checkbox"]`).next().addClass('layui-form-checked'); } } - // 如果有更新,同步更新全局数据 if (updated) { - quanju = [...tableData] + quanju = [...tableData]; + $('#num').html(huancun.length); // 更新已选数量 } - layer.msg("数据导入成功", { icon: 1 }) + + layer.msg("数据导入成功", { icon: 1 }); }