Przeglądaj źródła

定额,1-2,1-10排序

zhongzewei 6 lat temu
rodzic
commit
7d091d0c8b
1 zmienionych plików z 29 dodań i 4 usunięć
  1. 29 4
      web/maintain/ration_repository/js/ration.js

+ 29 - 4
web/maintain/ration_repository/js/ration.js

@@ -587,12 +587,13 @@ let rationOprObj = {
                     me.getRationItems(me.currentSectionId);
                 } else {
                     let cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
-                    cacheSection.sort(function(a, b){
+                    me.sortByCode(cacheSection);
+                    /*cacheSection.sort(function(a, b){
                         let rst = 0;
                         if (a.code > b.code) rst = 1
                         else if (a.code < b.code) rst = -1;
                         return rst;
-                    });
+                    });*/
                     //add
                     let curRow = me.workBook.getActiveSheet().getActiveRowIndex();
                     me.rationSelInit(curRow);
@@ -730,7 +731,31 @@ let rationOprObj = {
         sectionTreeObj.workBook.focus(true);
     },
     sortByCode: function(arr){
-        function compare(){
+        arr.sort(function (a, b) {
+            let rst = 0;
+            let splitA = a.code.split('-'),
+                splitB = b.code.split('-');
+            if(splitA[0] > splitB[0]){
+                rst = 1;
+            }
+            else if(splitA[0] < splitB[0]){
+                rst = -1;
+            }
+            else {
+                if(splitA[1] && splitB[1]){
+                    let floatA = parseFloat(splitA[1]),
+                        floatB = parseFloat(splitB[1]);
+                    if(floatA > floatB){
+                        rst = 1;
+                    }
+                    else if(floatA < floatB){
+                        rst = -1;
+                    }
+                }
+            }
+            return rst;
+        });
+        /*function compare(){
             return function (a, b) {
                 let rst = 0;
                 if (a.code > b.code) {
@@ -742,7 +767,7 @@ let rationOprObj = {
                 return rst;
             }
         }
-        arr.sort(compare());
+        arr.sort(compare());*/
     },
     saveInString(datas){
         for(let i = 0, len = datas.length; i < len; i++){