Explorar o código

Merge branch '1.0.0_online' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost into 1.0.0_online

Conflicts:
	modules/main/facade/ration_facade.js
zhangweicheng %!s(int64=6) %!d(string=hai) anos
pai
achega
67bf589e39

+ 3 - 3
modules/main/facade/ration_facade.js

@@ -17,7 +17,7 @@ const uuidV1 = require('uuid/v1');
 let std_glj_lib_gljList_model = mongoose.model('std_glj_lib_gljList');
 let complementary_glj_model =  mongoose.model('complementary_glj_lib');
 let rationItemModel = mongoose.model("std_ration_lib_ration_items");
-let complementaryGljModel = mongoose.model('complementary_glj_lib');
+let complementaryRationModel = mongoose.model('complementary_ration_items');
 
 let coeMolde = mongoose.model('std_ration_lib_coe_list');
 let _= require('lodash');
@@ -75,13 +75,13 @@ async function getSameSectionRations(data,userId){
         let ration = await rationItemModel.findOne({rationRepId:libID,code:code},['sectionId']);
         sectionId = ration? ration.sectionId:null;
     }else {
-        let ration = await complementaryGljModel.findOne({userId:userId,code:code},['sectionId']);
+        let ration = await complementaryRationModel.findOne({userId:userId,code:code},['sectionId']);
         sectionId = ration?ration.sectionId:null;
     }
     if(sectionId){
         //{
         let stdRations = await rationItemModel.find({sectionId: sectionId});
-        let comRations = await complementaryGljModel.find({userId: userId, sectionId: sectionId});
+        let comRations = await complementaryRationModel.find({userId: userId, sectionId: sectionId});
         rations = stdRations.concat(comRations);
         rations = _.sortBy(rations,'code');
     }

+ 41 - 34
modules/reports/rpt_component/helper/jpc_helper_common.js

@@ -133,48 +133,55 @@ let JpcCommonHelper = {
         }
         return rst;
     },
-    getStringLinesInArea: function(area, strVal, pdfDoc) {
-        let areaWidth = area[JV.PROP_RIGHT] - area[JV.PROP_LEFT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT] - 2;
-        // let re = /[\u4E00-\u9FA5]/g;
-        let re = /[^\x00-\xff]/ig; //普通ASCII以外的字符
-        let cStr = strVal.match(re);
-        let chnAmt = (cStr)?cStr.length:0;
-        let chnW = pdfDoc.widthOfString('一'), otherW = pdfDoc.widthOfString('_');
-        //备注: 因后台的pdfDoc判断字符串长度与前端的不一样,需要做些调整,不一次性地判断字符串长度。
+    getStringLinesInArea: function(area, strVal, pdfDoc, chnW, otherW) {
+        //备注: 因后台的pdf kit判断字符串长度与前端的不一样,需要做些调整,不一次性地判断字符串长度。
         //      分2种字符:中文与非中文,按照各种字符的数量分别乘以相关一个字符的宽度再累计。
-        // let txtWidth = pdfDoc.widthOfString(strVal);
-        let txtWidth = chnAmt * chnW + (strVal.length - chnAmt) * otherW;
-        let rst = parseInt(txtWidth / areaWidth);
-        if (txtWidth % areaWidth > 0) {
-            rst++;
+        //      另判断行数还不能直接用总长度除以宽度来计算,因每一行都会有不同的余量,所以得一行行走过来判断。
+        let rst = 0;
+        if (strVal) {
+            let areaWidth = area[JV.PROP_RIGHT] - area[JV.PROP_LEFT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT] - 1;
+            let txtWidth = 0, currentW = 0;
+            for (let sIdx = 0; sIdx < strVal.length; sIdx++) {
+                currentW = (strVal.charCodeAt(sIdx) > 127)?chnW:otherW;
+                txtWidth += currentW;
+                if (txtWidth > areaWidth) {
+                    rst++;
+                    txtWidth = currentW;
+                }
+                if (sIdx === strVal.length - 1) {
+                    rst++;
+                }
+            }
         }
         if (rst === 0) rst = 1; //即使是空字符串,也得有一行啊
         return rst;
-        //备注: 其实是想用canvas的,但node canvas装起来麻烦,暂时用PDF Kit来顶用一下,以后换新方法再用
+        //备注: 其实是想用canvas的,但node canvas装起来麻烦,暂时用PDF Kit来顶用一下,以后有更好的再换
     },
-    splitString: function (area, strVal, pdfDoc) {
+    splitString: function (area, strVal, pdfDoc, chnW, otherW) {
         let rst = [];
-        // let re = /[\u4E00-\u9FA5]/g;
-        let re = /[^\x00-\xff]/ig; //普通ASCII以外的字符
-        let chnW = pdfDoc.widthOfString('一'), otherW = pdfDoc.widthOfString('_');
-        let areaWidth = area[JV.PROP_RIGHT] - area[JV.PROP_LEFT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT] - 2;
-        let preSIdx = 0, txtWidth = 0;
-
-        for (let sIdx = 1; sIdx <= strVal.length; sIdx++) {
-            let tmpStr = strVal.substr(preSIdx, sIdx - preSIdx);
-            let cStr = tmpStr.match(re);
-            let chnAmt = (cStr)?cStr.length:0;
-            // let chnAmt = tmpStr.match(re).length;
-            // txtWidth = pdfDoc.widthOfString(strVal.substr(preSIdx, sIdx - preSIdx));
-            txtWidth = chnAmt * chnW + (tmpStr.length - chnAmt) * otherW;
-            if (txtWidth > areaWidth) {
-                rst.push(strVal.substr(preSIdx, sIdx - preSIdx - 1));
-                preSIdx = sIdx - 1;
-            }
-            if (sIdx === strVal.length) {
-                rst.push(strVal.substr(preSIdx, sIdx - preSIdx));
+        if (strVal) {
+            let areaWidth = area[JV.PROP_RIGHT] - area[JV.PROP_LEFT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_RIGHT] - JV.OUTPUT_OFFSET[JV.OFFSET_IDX_LEFT] - 1;
+            let preSIdx = 0, txtWidth = 0;
+            let currentW = 0;
+            for (let sIdx = 0; sIdx < strVal.length; sIdx++) {
+                currentW = (strVal.charCodeAt(sIdx) > 127)?chnW:otherW;
+                txtWidth += currentW;
+                if (txtWidth > areaWidth) {
+                    if (preSIdx < sIdx) {
+                        rst.push(strVal.substr(preSIdx, sIdx - preSIdx));
+                        preSIdx = sIdx;
+                    } else {
+                        rst.push(strVal.substr(preSIdx, 1));
+                        preSIdx = sIdx + 1;
+                    }
+                    txtWidth = currentW;
+                }
+                if (sIdx === strVal.length - 1) {
+                    rst.push(strVal.substr(preSIdx, strVal.length - preSIdx));
+                }
             }
         }
+        if (rst.length === 0) rst.push(''); //什么都没有,也得整个空串
         return rst;
     }
 };

+ 3 - 3
modules/reports/rpt_component/jpc_flow_tab.js

@@ -343,10 +343,10 @@ JpcFlowTabSrv.prototype.createNew = function(){
                         }
                         let hasSplitStr = false, splitStrArr = [];
                         let accAmt = 0;
+                        let chnW = doc.widthOfString('一'), otherW = doc.widthOfString('_');
                         for (let i = 0; i < values.length; i++) {
-                            let amt = JpcCommonHelper.getStringLinesInArea(area, values[i], doc);
+                            let amt = JpcCommonHelper.getStringLinesInArea(area, values[i], doc, chnW, otherW);
                             accAmt += amt;
-                            // rst += amt;
                             if (amt > 1) {
                                 hasSplitStr = true;
                                 splitStrArr.push(i);
@@ -359,7 +359,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
                                 if (splitStrArr.indexOf(i) < 0) {
                                     newValArr.push(values[i]);
                                 } else {
-                                    newValArr = newValArr.concat(JpcCommonHelper.splitString(area, values[i], doc));
+                                    newValArr = newValArr.concat(JpcCommonHelper.splitString(area, values[i], doc, chnW, otherW));
                                 }
                             }
                             JpcFieldHelper.setValue(data_field, theRecIdx, newValArr.join('|'));

+ 31 - 3
test/unit/reports/rpt_cfg.js

@@ -359,12 +359,40 @@ module.exports = {
             "Wrap" : "false"
         },
         {
-            "ID" : "Numeric",
+            "ID" : "Currency",
+            "CfgDispName" : "金额型",
             "Shrink" : "T",
             "ShowZero" : "F",
             "Horizon" : "right",
-            "Vertical" : "bottom",
-            "Wrap" : "false"
+            "Vertical" : "center",
+            "Wrap" : "F"
+        },
+        {
+            "ID" : "Left_Top",
+            "CfgDispName" : "上靠_左",
+            "Shrink" : "F",
+            "ShowZero" : "T",
+            "Horizon" : "left",
+            "Vertical" : "top",
+            "Wrap" : "F"
+        },
+        {
+            "ID" : "Center_Top",
+            "CfgDispName" : "上靠_中",
+            "Shrink" : "F",
+            "ShowZero" : "T",
+            "Horizon" : "center",
+            "Vertical" : "top",
+            "Wrap" : "F"
+        },
+        {
+            "ID" : "Right_Top",
+            "CfgDispName" : "上靠_右",
+            "Shrink" : "F",
+            "ShowZero" : "T",
+            "Horizon" : "right",
+            "Vertical" : "top",
+            "Wrap" : "F"
         }
     ]
 }

+ 6 - 0
web/building_saas/complementary_glj_lib/js/glj.js

@@ -139,6 +139,12 @@ let repositoryGljObj = {
         let me = this;
         CommonAjax.post('complementartGlj/api/getGljItems', {stdGljLibId: stdGljLibId}, function (rstData) {
             me.stdGljList = rstData.stdGljs;
+            //兼容多单价情况
+            for(let sGlj of me.stdGljList){
+                if(sGlj.priceProperty && typeof sGlj.priceProperty.price1 !== 'undefined') {
+                    sGlj.basePrice = sGlj.priceProperty.price1;
+                }
+            }
             me.complementaryGljList = rstData.complementaryGljs;
             me.workBook.getSheet(0).setRowCount(me.stdGljList.length);
             me.sortGlj(me.stdGljList);

+ 6 - 0
web/building_saas/complementary_ration_lib/js/gljSelect.js

@@ -43,6 +43,12 @@ let gljSelOprObj = {
         let me = this;
         CommonAjax.post('/complementartGlj/api/getGljItems', {stdGljLibId: stdGljLibId}, function (rstData) {
             me.stdGljList = rstData.stdGljs;
+            //兼容多单价,计算补充定额价格时,套多单价人材机的时候,默认取第一个价格
+            for(let sGlj of me.stdGljList){
+                if(sGlj.priceProperty && typeof sGlj.priceProperty.price1 !== 'undefined'){
+                    sGlj.basePrice = sGlj.priceProperty.price1;
+                }
+            }
             me.complementaryGljList = rstData.complementaryGljs;
             me.switchToGljId(me.stdGljList);
             me.switchToGljId(me.complementaryGljList);