Explorar el Código

台账分解,清单汇总,排序

MaiXinRong hace 2 años
padre
commit
4e66564e7e
Se han modificado 2 ficheros con 37 adiciones y 2 borrados
  1. 34 2
      app/public/js/global.js
  2. 3 0
      app/public/js/shares/cs_gcl_gather.js

+ 34 - 2
app/public/js/global.js

@@ -1057,7 +1057,39 @@ const checkUtils = {
                     : data.end_contract_qty < data.deal_final_1_qty || data.end_contract_qty > 0;
             }
         }
-    }
+    },
+    compareCode(str1, str2, symbol = '-') {
+        if (!str1) {
+            return 1;
+        } else if (!str2) {
+            return -1;
+        }
+
+        function compareSubCode(code1, code2) {
+            if (numReg.test(code1)) {
+                if (numReg.test(code2)) {
+                    return parseInt(code1) - parseInt(code2);
+                } else {
+                    return -1
+                }
+            } else {
+                if (numReg.test(code2)) {
+                    return 1;
+                } else {
+                    return code1 === code2 ? 0 : (code1 < code2 ? -1 : 1); //code1.localeCompare(code2);
+                }
+            }
+        }
+        const numReg = /^[0-9]+$/;
+        const aCodes = str1.split(symbol), bCodes = str2.split(symbol);
+        for (let i = 0, iLength = Math.min(aCodes.length, bCodes.length); i < iLength; ++i) {
+            const iCompare = compareSubCode(aCodes[i], bCodes[i]);
+            if (iCompare !== 0) {
+                return iCompare;
+            }
+        }
+        return aCodes.length - bCodes.length;
+    },
 };
 
 Number.prototype.format2Str = function (pattern) {
@@ -1167,4 +1199,4 @@ const spreadColor = {
 
 $(document).ready(function () {
   $('.modal').draggable({handle: '.modal-header'});
-});
+});

+ 3 - 0
app/public/js/shares/cs_gcl_gather.js

@@ -76,6 +76,9 @@
         const gather = function (node) {
             $(`#${setting.id}-info`).html(`${node.code || ''}${node.b_code || ''} ${node.name || ''} - ${moment(new Date()).format('YYYY-MM-DD HH:mm:ss')}`);
             recursiveGather([node]);
+            result.sort((a, b) => {
+                return checkUtils.compareCode(a.b_code, b.b_code);
+            });
             SpreadJsObj.reLoadSheetData(sheet);
         };