瀏覽代碼

feat: 保存至总表可以只保存表里部分完善好的数据

vian 1 年之前
父節點
當前提交
6313cd262e
共有 1 個文件被更改,包括 20 次插入15 次删除
  1. 20 15
      web/maintain/price_info_lib/js/priceEmpty.js

+ 20 - 15
web/maintain/price_info_lib/js/priceEmpty.js

@@ -113,7 +113,6 @@ const EMPTY_BOOK = (() => {
 
   // 编辑处理
   async function handleEdit(changedCells, diffMap, needRefresh) {
-    $.bootstrapLoading.start();
     const postData = []; // 请求用
     // 更新缓存用
     const updateData = [];
@@ -155,6 +154,7 @@ const EMPTY_BOOK = (() => {
         }
       });
       if (postData.length) {
+        $.bootstrapLoading.start();
         await ajaxPost('/priceInfo/editPriceData', { postData }, TIME_OUT);
         // 更新缓存,先更新然后删除,最后再新增,防止先新增后缓存数据的下标与更新、删除数据的下标对应不上
         updateData.forEach(item => {
@@ -242,21 +242,22 @@ const EMPTY_BOOK = (() => {
 
   // 将空表的表格保存至总表
   const saveInSummary = async () => {
-    const documents = cache.map(item => ({
-      ID: uuid.v1(),
-      code: item.code,
-      classCode: item.classCode,
-      expString: item.expString,
-      name: item.name,
-      specs: item.specs,
-      unit: item.unit,
-    }));
+    const documents = [];
+    const removeIDs = [];
+    cache.filter(item => item.code && item.classCode).forEach(item => {
+      removeIDs.push(item.ID);
+      documents.push({
+        ID: uuid.v1(),
+        code: item.code,
+        classCode: item.classCode,
+        expString: item.expString,
+        name: item.name,
+        specs: item.specs,
+        unit: item.unit,
+      });
+    });
     if (!documents.length) {
-      alert('不存在空数据');
-      return;
-    }
-    if (documents.some(doc => !doc.classCode)) {
-      alert('请完善空数据别名编码!');
+      alert('不存在可保存数据');
       return;
     }
     console.log(documents);
@@ -267,6 +268,10 @@ const EMPTY_BOOK = (() => {
       setTimeout(() => {
         $.bootstrapLoading.progressEnd();
         alert('保存成功');
+        const filterCache = cache.filter(item => !removeIDs.includes(item.ID));
+        cache.length = 0;
+        cache.push(...filterCache);
+        showData(workBookObj.sheet, cache, setting.header);
       }, 1000);
     } catch (error) {
       setTimeout(() => {