xujunjie 3 年之前
父節點
當前提交
c41bc8fade
共有 1 個文件被更改,包括 20 次插入2 次删除
  1. 20 2
      src/pages/PurchaseAdmin/PurchaseList/Detail/LuckySheet.js

+ 20 - 2
src/pages/PurchaseAdmin/PurchaseList/Detail/LuckySheet.js

@@ -142,15 +142,33 @@ class LuckySheet extends React.Component {
   getSheetJson() {
     let data = JSON.parse(JSON.stringify(this.luckysheet.toJson()));
     data.data.forEach(sheet => {
+      let allCell = {},
+        unknowCid = [];
+      // 将cell以cid为界分别存储
       (sheet.celldata || []).forEach(cell => {
-        // 添加cid
-        if (!cell.v.cid) cell.v.cid = this.getUUID();
+        if (!cell.v.cid) {
+          unknowCid.push(cell);
+        } else {
+          allCell[cell.v.cid] = cell;
+        }
         // 清除比对样式
         if (cell.v.bg == DIFF_COLOR || cell.v.bg == ADD_COLOR) {
           delete cell.v.bg;
         }
       });
+
+      unknowCid.forEach(cell => {
+        // 根据坐标生成唯一key,重复则增加后缀直至不重复
+        let key = `${cell.r}-${cell.c}`;
+        while (allCell[key]) {
+          key += '|c';
+        }
+        cell.v.cid = key;
+        allCell[key] = cell;
+      });
+      sheet.celldata = Object.values(allCell);
     });
+
     return data;
   }