Browse Source

fix: 清单指引广东定额排序问题

vian 3 years ago
parent
commit
75619dae7a
1 changed files with 38 additions and 2 deletions
  1. 38 2
      web/maintain/billsGuidance_lib/js/billsGuidance.js

+ 38 - 2
web/maintain/billsGuidance_lib/js/billsGuidance.js

@@ -11,6 +11,41 @@ const billsGuidance = (function () {
     function _isDef(v) {
         return typeof v !== 'undefined' && v !== null;
     }
+
+
+    function sortByCode(arr) {
+        function recurCompare(a, b, index){
+            if (a[index] && !b[index]) {
+                return 1;
+            } else if (!a[index] && b[index]) {
+                return -1;
+            } else if (a[index] && b[index]) {
+                let aV = a[index],
+                    bV = b[index];
+                if (!isNaN(aV) && !isNaN(bV)) {
+                    aV = parseFloat(a[index]);
+                    bV = parseFloat(b[index]);
+                }
+                if (aV > bV) {
+                    return 1;
+                } else if (aV < bV) {
+                    return -1;
+                } else {
+                    return recurCompare(a, b, index + 1);
+                }
+            }
+            return 0;
+        }
+        arr.sort(function (a, b) {
+            if (!_isDef(a.code) || !_isDef(b.code)) {
+                return 0;
+            }
+            let aArr = a.code.split('-'),
+                bArr = b.code.split('-');
+            return recurCompare(aArr, bArr, 0);
+        });
+    }
+
     const locked = lockUtil.getLocked();
     let moduleName = 'stdBillsGuidance';
     //上下拖动的拖动条高度
@@ -777,7 +812,8 @@ const billsGuidance = (function () {
                 initTree(section, section.workBook.getActiveSheet(), section.treeSetting, sectionDatas);
                 //初始焦点在第一行(切换库)
                 sectionSheet.setActiveCell(0, 0);
-                rstData.sort(function (a, b) {
+                sortByCode(rstData);
+                /* rstData.sort(function (a, b) {
                     let rst = 0;
                     if(a.code > b.code){
                         rst = 1;
@@ -786,7 +822,7 @@ const billsGuidance = (function () {
                         rst = -1;
                     }
                     return rst;
-                });
+                }); */
                 ration.datas = rstData;
                 sectionInitSel(0);
                 $.bootstrapLoading.end();