zhongzewei 6 years ago
parent
commit
c763513289

+ 28 - 5
modules/complementary_ration_lib/models/compleRationModel.js

@@ -163,17 +163,39 @@ class CompleRatoinDao {
             });
             for(let ration of rations){
                 let hintsArr = [];
+                let stdGljIds = [],
+                    comGljIds = [],
+                    stdGljs = [],
+                    comGljs = [];
+                let gljAmtMapping = {};
                 for(let rationGlj of ration.rationGljList){
-                    let glj;
+                    gljAmtMapping[rationGlj.gljId] = rationGlj.consumeAmt;
                     if(!isDef(rationGlj.type) || rationGlj.type === 'std'){
-                         glj = await stdGljModel.findOne({ID: rationGlj.gljId});
+                        stdGljIds.push(rationGlj.gljId);
                     }
                     else {
-                         glj = await complementaryGljModel.findOne({uesrId: userId, ID: rationGlj.gljId});
+                        comGljIds.push(rationGlj.gljId);
                     }
-                    if(isDef(glj)){
-                        hintsArr.push(` ${glj.code} ${glj.name}${glj.specs ? '   ' + glj.specs : ''} &nbsp ${glj.unit}   ${rationGlj.consumeAmt}`);
+                }
+                if(stdGljIds.length > 0) {
+                    stdGljs = await stdGljModel.find({ID: {$in: stdGljIds}});
+                }
+                if(comGljIds.length > 0) {
+                    comGljs = await complementaryGljModel.find({userId: userId, ID: {$in: comGljIds}});
+                }
+                let gljDatas = stdGljs.concat(comGljs);
+                gljDatas.sort(function (a, b) {
+                    let aV = a.gljType + a.code,
+                        bV = b.gljType + b.code;
+                    if(aV > bV) {
+                        return 1;
+                    } else if (aV < bV) {
+                        return -1;
                     }
+                    return 0;
+                });
+                for(let glj of gljDatas){
+                    hintsArr.push(` ${glj.code} ${glj.name}${glj.specs ? '&nbsp;&nbsp;&nbsp;' + glj.specs : ''}&nbsp;&nbsp&nbsp;${glj.unit}&nbsp;&nbsp;&nbsp;${gljAmtMapping[glj.ID]}`)
                 }
                 hintsArr.push(`基价 元 ${ration.basePrice}`);
                 if(ration.jobContent && ration.jobContent.toString().trim() !== ''){
@@ -190,6 +212,7 @@ class CompleRatoinDao {
             callback(0, rations);
         }
         catch(err){
+            console.log(err);
             callback(err, null);
         }
     }

+ 16 - 1
modules/complementary_ration_lib/models/searchModel.js

@@ -95,7 +95,7 @@ class SearchDao{
             comGljIds = Array.from(new Set(comGljIds));
             let gljIDMapping = {};
             if(stdGljIds.length > 0){
-                let stdGljs = await stdGljModel.find({ID: {$in: stdGljIds}}, '-_id ID code name specs unit');
+                let stdGljs = await stdGljModel.find({ID: {$in: stdGljIds}}, '-_id ID code name specs unit gljType');
                 for(let stdGlj of stdGljs){
                     gljIDMapping[stdGlj.ID] = stdGlj;
                 }
@@ -108,6 +108,21 @@ class SearchDao{
             }
             for(let ration of stdRations){
                 let hintsArr = [];
+                //对人材机进行排序
+                ration.rationGljList.sort(function (a, b) {
+                    let gljA = gljIDMapping[a.gljId],
+                        gljB = gljIDMapping[b.gljId];
+                    if(gljA && gljB){
+                        let aV = gljA.gljType + gljA.code,
+                            bV = gljB.gljType + gljB.code;
+                        if(aV > bV) {
+                            return 1;
+                        } else if(aV < bV) {
+                            return -1;
+                        }
+                    }
+                    return 0;
+                });
                 for(let rationGlj of ration.rationGljList){
                     let glj = gljIDMapping[rationGlj.gljId];
                     if(glj){

+ 30 - 22
web/building_saas/complementary_ration_lib/js/ration_glj.js

@@ -405,10 +405,14 @@ var rationGLJOprObj = {
                         me.cache["_GLJ_" + me.currentRationItem.ID] = me.cache["_GLJ_" + me.currentRationItem.ID].concat(recoveryArr);
                     }
                     me.cache["_GLJ_" + me.currentRationItem.ID].sort(function(a, b) {
-                        var rst = 0;
-                        if (a.code > b.code) rst = 1
-                        else if (a.code < b.code) rst = -1;
-                        return rst;
+                        let aV = a.gljType + a.code,
+                            bV = b.gljType + b.code;
+                        if (aV > bV) {
+                            return 1;
+                        } else if (av < bV) {
+                            return -1
+                        }
+                        return 0;
                     });
                 }
                 me.showGljItems(me.currentRationItem.ID);
@@ -426,10 +430,14 @@ var rationGLJOprObj = {
                 }
                 //更新的工料机不存在
                 me.cache["_GLJ_" + me.currentRationItem.ID].sort(function(a, b) {
-                    var rst = 0;
-                    if (a.code > b.code) rst = 1
-                    else if (a.code < b.code) rst = -1;
-                    return rst;
+                    let aV = a.gljType + a.code,
+                        bV = b.gljType + b.code;
+                    if (aV > bV) {
+                        return 1;
+                    } else if (av < bV) {
+                        return -1
+                    }
+                    return 0;
                 });
                 $('#alertModalBtn').click();
                 $('#alertText').text("人材机"+ codes + "不存在,请查找你所需要的人材机,或新增人材机");
@@ -562,14 +570,14 @@ var rationGLJOprObj = {
                 }
                 function compare(){
                     return function (a, b) {
-                        let rst = 0;
-                        if (a.code > b.code) {
-                            rst = 1;
+                        let aV = a.gljType + a.code,
+                            bV = b.gljType + b.code;
+                        if (aV > bV) {
+                            return 1;
+                        } else if (av < bV) {
+                            return -1
                         }
-                        else if (a.code < b.code) {
-                            rst = -1;
-                        }
-                        return rst;
+                        return 0;
                     }
                 }
                 cacheArr.sort(compare());
@@ -584,14 +592,14 @@ var rationGLJOprObj = {
         if (me.cache["_GLJ_" + rationID]) {
             sheetCommonObj.cleanData(me.sheet, me.setting, -1);
             me.cache["_GLJ_" + rationID].sort(function (a, b) {
-                let rst = 0;
-                if(a.code > b.code){
-                    rst = 1;
-                }
-                else if(a.code < b.code){
-                    rst = -1;
+                let aV = a.gljType + a.code,
+                    bV = b.gljType + b.code;
+                if (aV > bV) {
+                    return 1;
+                } else if (av < bV) {
+                    return -1
                 }
-                return rst;
+                return 0;
             });
             sheetsOprObj.showData(me.sheet, me.setting, me.cache["_GLJ_" + rationID], me.distTypeTree);
         }