Browse Source

数值大写函数+固化清单选择(on going)

TonyKang 7 years ago
parent
commit
b48e5953de

+ 32 - 0
modules/reports/util/rpt_construct_data_util.js

@@ -601,6 +601,7 @@ function setupFunc(obj, prop, ownRawObj) {
     obj[prop].getFee = ext_getFee;
     obj[prop].getPropertyByForeignId = ext_getPropertyByForeignId;
     obj[prop].getArrayItemByKey = ext_getArrayItemByKey;
+    obj[prop].getPropertyByFlag = ext_getPropertyByFlag;
     if (prop === projectConst.CALC_PROGRAM) obj[prop].getCalcProperty = ext_getCalcProperty;
     if (prop === projectConst.FEERATE) obj[prop].getFeeRate = ext_getFeeRate;
 }
@@ -859,7 +860,38 @@ function ext_getArrayItemByKey(arrayKey, itemKey, itemKeyValue, itemRstKey){
             private_getItemValue(arr, itemKeyValue);
         }
     }
+}
 
+function ext_getPropertyByFlag(flagVal, rstKey, dftValIfEmpty) {
+    let rst = [], parentObj = this;
+    let dtObj = parentObj["myOwnRawDataObj"];
+    if (flagVal && rstKey && dtObj) {
+        let isArr = (flagVal instanceof Array);
+        for (let dItem of dtObj.data) {
+            let doc = (dItem._doc === null || dItem._doc === undefined)?dItem:dItem._doc;
+            if (doc.hasOwnProperty("flags")) {
+                let bFlag = false;
+                for (let flagItem of doc.flags) {
+                    if (isArr) {
+                        bFlag = (flagVal.indexOf(flagItem.flag) >= 0);
+                    } else {
+                        if (flagItem.flag === flagVal) {
+                            bFlag = true;
+                        }
+                    }
+                    if (bFlag) break;
+                }
+                if (bFlag) {
+                    rst.push(doc[rstKey]);
+                    break;
+                }
+            }
+        }
+    }
+    if (rst.length === 0 && dftValIfEmpty) {
+        rst.push(dftValIfEmpty);
+    }
+    return rst;
 }
 
 function ext_getPropertyByForeignId(foreignIdVal, adHocIdKey, propKey, dftValIfNotFound) {

+ 55 - 27
public/stringUtil.js

@@ -145,36 +145,64 @@ module.exports = {
     rightTrim: function(rst) {
         return str.replace(/(\s*$)/g,"");
     },
-    convertNumToChinese : function(num, isCurrency) {
-        if (!/^\d*(\.\d*)?$/.test(num)) { return "Number is wrong!"; }
-        let AA, BB;
-        if (isCurrency) {
-            AA = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
-            BB = ["", "拾", "佰", "仟", "萬", "億", "点", ""];
-        } else {
-            AA = ['零','一','二','三','四','五','六','七','八','九'];
-            BB = ["", "十", "百", "千", "万", "亿", "点", ""];
-        }
-        //let AA = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
-        //let BB = new Array("", "拾", "佰", "仟", "萬", "億", "点", "");
-        let a = ("" + num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
-        for (let i = a[0].length - 1; i >= 0; i--) {
-            switch (k) {
-                case 0: re = BB[7] + re; break;
-                case 4: if (!new RegExp("0{4}\\d{" + (a[0].length - i - 1) + "}$").test(a[0]))
-                    re = BB[4] + re; break;
-                case 8: re = BB[5] + re; BB[7] = BB[5]; k = 0; break;
+    replaceAll: function (targetStr, FindText, RepText) {
+        let regExp = new RegExp(FindText, "gm");
+        return targetStr.replace(regExp, RepText);
+    },
+    convertToCaptionNum: function(num, isCurrency, isTraditionalCap) {
+        let me = this, rst = "";
+        if (/^\d*(\.\d*)?$/.test(num)) {
+            let capChars, unitChars;
+            if (isTraditionalCap) {
+                capChars = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
+                unitChars = ["" , "拾", "佰", "仟", "萬", "拾", "佰", "仟", "億", "拾", "佰", "仟", "萬"];
+            } else {
+                capChars = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
+                unitChars = ["" , "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千", "万"];
             }
-            if (k % 4 === 2 && a[0].charAt(i + 2) !== 0 && a[0].charAt(i + 1) === 0) re = AA[0] + re;
-            if (a[0].charAt(i) !== 0) re = AA[a[0].charAt(i)] + BB[k % 4] + re; k++;
-        }
 
-        if (a.length > 1) //加上小数部分(如果有小数部分)
-        {
-            re += BB[6];
-            for (let i = 0; i < a[1].length; i++) re += AA[a[1].charAt(i)];
+            let numSplitArr = ("" + num).replace(/(^0*)/g, "").split(".");
+            if (numSplitArr[0] === "") numSplitArr[0] = "0";
+            let len = numSplitArr[0].length;
+            let intPartArr = [];
+            if (len <= 13) {
+                for (let idx = 0; idx < len; idx++) {
+                    intPartArr.push(capChars[ parseInt(numSplitArr[0].charAt(idx) )] + unitChars[len - idx - 1]);
+                }
+                rst = intPartArr.join('');
+                rst = me.replaceAll(rst, capChars[0] + unitChars[3], capChars[0]); //零千 -> 零
+                rst = me.replaceAll(rst, capChars[0] + unitChars[2], capChars[0]); //零百 -> 零
+                rst = me.replaceAll(rst, capChars[0] + unitChars[1], capChars[0]); //零十 -> 零
+                //
+                rst = me.replaceAll(me.replaceAll(rst, "零零", "零"), "零零", "零");
+                rst = me.replaceAll(rst, capChars[0] + unitChars[8], unitChars[8]); //零亿 -> 亿
+                rst = me.replaceAll(rst, capChars[0] + unitChars[4], unitChars[4]); //零万 -> 万
+                //
+                rst = me.replaceAll(rst, unitChars[8] + unitChars[4], unitChars[8] + capChars[0]); //亿万 -> 亿零
+                if (num === 0) {
+                    rst = "零";
+                } else if (rst.length > 1 && rst.charAt(rst.length - 1) === '零') {
+                    rst = rst.slice(0, rst.length - 1);
+                }
+                //小数部分处理
+                if (numSplitArr.length > 1) {
+                    len = numSplitArr[1].length;
+                    if (isCurrency && len > 2) len = 2;
+                    let fractionStr = [];
+                    for (let idx = 0; idx < len; idx++) {
+                        fractionStr.push(capChars[ parseInt(numSplitArr[1].charAt(idx))]+ (isCurrency?((idx === 0)?"角":"分"):""));
+                    }
+                    rst = rst + (isCurrency?"元":"点") + fractionStr.join("");
+                } else {
+                    rst = rst + (isCurrency?"元整":"");
+                }
+            } else {
+                rst = "Number is too big!";
+            }
+        } else {
+            rst = "Number is wrong!";
         }
-        return re;
+        return rst;
     },
     convertStrToBoolean: function(str) {
         let rst = false, me = this;

+ 79 - 53
test/demo/stringTest.js

@@ -4,62 +4,88 @@
 /**
  * Created by Tony on 2017/6/21.
  */
-var test = require('tape');
+let test = require('tape');
+let strUtil = require('../../public/stringUtil');
 
-test('string test1', function(t){
-    let str = "at('1.1') + at('1.2') + at('1.3') + at('1.4')";
-    //let re = /at(/g;
-    //let re = new RegExp("at\(", "g");
-    //let str1 = str.replaceAll('re', '@(');
-    //let str1 = str.replace('at(', '@(');
-    var str1 = str.split('at1(').join('@(');
-    //t.equal(str1, "@('1.1') + @('1.2') + @('1.3') + @('1.4')");
-    t.equal(str1, "at('1.1') + at('1.2') + at('1.3') + at('1.4')");
-    t.end();
-})
-
-test('string test2', function(t){
-    var str="hello(world)";
-    var nstr = str.replace(/\([^\)]*\)/g,"");
+// test('string test1', function(t){
+//     let str = "at('1.1') + at('1.2') + at('1.3') + at('1.4')";
+//     //let re = /at(/g;
+//     //let re = new RegExp("at\(", "g");
+//     //let str1 = str.replaceAll('re', '@(');
+//     //let str1 = str.replace('at(', '@(');
+//     var str1 = str.split('at1(').join('@(');
+//     //t.equal(str1, "@('1.1') + @('1.2') + @('1.3') + @('1.4')");
+//     t.equal(str1, "at('1.1') + at('1.2') + at('1.3') + at('1.4')");
+//     t.end();
+// })
+//
+// test('string test2', function(t){
+//     var str="hello(world)";
+//     var nstr = str.replace(/\([^\)]*\)/g,"");
+//
+//     t.equal(nstr , "hello");
+//     t.end();
+// })
+//
+// test('string test3', function(t){
+//     var str="共 (%S) 页";
+//     var nstr = str.replace("(%S)",10);
+//
+//     t.equal(nstr , "共 10 页");
+//     t.end();
+// })
+//
+// test('test extract', function(t){
+//     let private_extract_code = function(str, idx){
+//         let rst = '', lBracket = 0, rBracket = 0, firstIdx = idx, lastIdx = 0;
+//         for (let i = idx; i < str.length; i++) {
+//             if (str[i] === '(') {
+//                 lBracket++;
+//                 if (lBracket == 1) firstIdx = i + 1;
+//             }
+//             if (str[i] === ')') {
+//                 rBracket++;
+//                 if (lBracket == rBracket) {
+//                     lastIdx = i - 1;
+//                     if (lastIdx > firstIdx) {
+//                         if (str[firstIdx] === "'") firstIdx++;
+//                         if (str[lastIdx] !== "'") lastIdx++;
+//                         if (lastIdx > firstIdx) {
+//                             rst = str.slice(firstIdx, lastIdx);
+//                         }
+//                     }
+//                     break;
+//                 }
+//             }
+//         }
+//         return rst;
+//     };
+//     let code = private_extract_code("at('1.1') + at('1.2')", 10);
+//     t.equal(code , "1.2");
+//     t.end();
+// })
 
-    t.equal(nstr , "hello");
-    t.end();
-})
+test('test number to Chinese', function(t){
+    t.equal(strUtil.convertToCaptionNum(0, false, false), '零');
+    t.equal(strUtil.convertToCaptionNum(0, true, false), '零元整');
+    t.equal(strUtil.convertToCaptionNum(0.68, true, false), '零元六角八分');
+    t.equal(strUtil.convertToCaptionNum(0.68, true, true), '零元陆角捌分');
+    t.equal(strUtil.convertToCaptionNum(10, false, false), '一十');
+    t.equal(strUtil.convertToCaptionNum(10, false, true), '壹拾');
+    t.equal(strUtil.convertToCaptionNum(11, false, false), '一十一');
+    t.equal(strUtil.convertToCaptionNum(11, false, true), '壹拾壹');
+    t.equal(strUtil.convertToCaptionNum(12, false, false), '一十二');
+    t.equal(strUtil.convertToCaptionNum(12, false, true), '壹拾贰');
+    t.equal(strUtil.convertToCaptionNum(21, false, false), '二十一');
+    t.equal(strUtil.convertToCaptionNum(21, false, true), '贰拾壹');
 
-test('string test3', function(t){
-    var str="共 (%S) 页";
-    var nstr = str.replace("(%S)",10);
+    t.equal(strUtil.convertToCaptionNum(0.123456789, false, false), '零点一二三四五六七八九');
+    t.equal(strUtil.convertToCaptionNum(10.123456789, false, false), '一十点一二三四五六七八九');
 
-    t.equal(nstr , "共 10 页");
-    t.end();
-})
+    t.equal(strUtil.convertToCaptionNum(123456789.15, false, false), '一亿二千三百四十五万六千七百八十九点一五');
+    t.equal(strUtil.convertToCaptionNum(123456789.15, false, true), '壹億贰仟叁佰肆拾伍萬陆仟柒佰捌拾玖点壹伍');
+    t.equal(strUtil.convertToCaptionNum(123456789.15, true, false), '一亿二千三百四十五万六千七百八十九元一角五分');
+    t.equal(strUtil.convertToCaptionNum(123456789.15, true, true), '壹億贰仟叁佰肆拾伍萬陆仟柒佰捌拾玖元壹角伍分');
 
-test('test extract', function(t){
-    let private_extract_code = function(str, idx){
-        let rst = '', lBracket = 0, rBracket = 0, firstIdx = idx, lastIdx = 0;
-        for (let i = idx; i < str.length; i++) {
-            if (str[i] === '(') {
-                lBracket++;
-                if (lBracket == 1) firstIdx = i + 1;
-            }
-            if (str[i] === ')') {
-                rBracket++;
-                if (lBracket == rBracket) {
-                    lastIdx = i - 1;
-                    if (lastIdx > firstIdx) {
-                        if (str[firstIdx] === "'") firstIdx++;
-                        if (str[lastIdx] !== "'") lastIdx++;
-                        if (lastIdx > firstIdx) {
-                            rst = str.slice(firstIdx, lastIdx);
-                        }
-                    }
-                    break;
-                }
-            }
-        }
-        return rst;
-    };
-    let code = private_extract_code("at('1.1') + at('1.2')", 10);
-    t.equal(code , "1.2");
     t.end();
-})
+});

+ 3 - 1
web/maintain/report/js/cfg_const.js

@@ -233,7 +233,9 @@ let caculationSetting = {
     view: {
         showIcon: true,
         expandSpeed: "",
-        selectedMulti: false
+        selectedMulti: false,
+        addHoverDom: calculationTreeOprObj.addHoverDom,
+        removeHoverDom: calculationTreeOprObj.removeHoverDom
     },
     edit: {
         enable: true,

+ 42 - 1
web/maintain/report/js/rpt_tpl_calculation.js

@@ -10,6 +10,11 @@ let calculationTreeOprObj = {
         let fieldMapList = me.buildTreeData(rptTpl);
         me.treeObj = $.fn.zTree.init($("#rpt_tpl_formulas"), caculationSetting, fieldMapList);
         me.treeObj.expandAll(true);
+        $("#exprDetail")[0].style.display = "none";
+        // $("#exprFormat").get(0).value = "";
+        // $("#exprContent").get(0).value = "";
+    },
+    buildRunType: function() {
         let et = $("#exprRunType");
         et.append("<option value='" + JV.RUN_TYPE_BEFORE_PAGING + "'>预运行</option>");
         et.append("<option value='" + JV.RUN_TYPE_BEFORE_OUTPUT + "'>实时运行</option>");
@@ -19,6 +24,7 @@ let calculationTreeOprObj = {
         if (rptTpl[JV.NODE_FORMULAS]) {
             for (let cItem of rptTpl[JV.NODE_FORMULAS]) {
                 let node = {};
+                me.copyContent(cItem, node);
                 node[JV.PROP_NAME] = cItem[JV.PROP_NAME];
                 node[JV.PROP_RUN_TYPE] = cItem[JV.PROP_RUN_TYPE];
                 node[JV.PROP_EXPRESSION] = cItem[JV.PROP_EXPRESSION];
@@ -28,6 +34,12 @@ let calculationTreeOprObj = {
         }
         return rst;
     },
+    copyContent: function(source, target) {
+        target[JV.PROP_NAME] = source[JV.PROP_NAME];
+        target[JV.PROP_RUN_TYPE] = source[JV.PROP_RUN_TYPE];
+        target[JV.PROP_EXPRESSION] = source[JV.PROP_EXPRESSION];
+        target["format"] = (source["format"])?source["format"]:"";
+    },
     changeRunType: function (dom) {
         let me = calculationTreeOprObj;
         if (me.currentNode) {
@@ -86,7 +98,36 @@ let calculationTreeOprObj = {
         }
         return rst;
     },
+    addHoverDom: function(treeId, treeNode) {
+        let me = calculationTreeOprObj, sObj = $("#" + treeNode.tId + "_span");
+        if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length > 0 || treeNode.level > 0) {
+            return;
+        } else {
+            let addStr = "<span class='button add' id='addBtn_" + treeNode.tId + "' title='新增' onfocus='this.blur();'></span>";
+            sObj.after(addStr);
+            let btn = $("#addBtn_"+treeNode.tId);
+            btn.bind("click", function(){
+                let newNodes = [], node = {};
+                node[JV.PROP_NAME] = "新计算式";
+                node[JV.PROP_RUN_TYPE] = JV.RUN_TYPE_BEFORE_PAGING;
+                node[JV.PROP_EXPRESSION] = "";
+                node["format"] = "";
+                newNodes.push(node);
+                me.treeObj.addNodes(treeNode, -1, newNodes, true);
+            });
+        }
+    },
+    removeHoverDom: function(treeId, treeNode) {
+        $("#addBtn_"+treeNode.tId).unbind().remove();
+    },
     extractCalculation: function (rptTpl) {
-        //
+        let me = this, newCaclList = [];
+        let topNode = me.treeObj.getNodes()[0];
+        for (let node of topNode.items) {
+            let item = {};
+            me.copyContent(node, item);
+            newCaclList.push(item);
+        }
+        rptTpl[JV.NODE_FORMULAS] = newCaclList;
     }
 }

+ 6 - 6
web/maintain/report/js/rpt_tpl_data_map.js

@@ -15,6 +15,12 @@ let dataInfoMapTreeOprObj = {
         let fieldMapList = me.buildTreeData(rptTpl);
         me.treeObj = $.fn.zTree.init($("#tpl_data_info_reversed"), rptDataInfoSetting, fieldMapList);
         me.treeObj.expandAll(true);
+        $("#element_font")[0].style.display = "none";
+        $("#element_border")[0].style.display = "none";
+        $("#element_control")[0].style.display = "none";
+        $("#element_area_1")[0].style.display = "none";
+        $("#element_area_2")[0].style.display = "none";
+        $("#element_pre_suff")[0].style.display = "none";
     },
     iniDataMap: function () {
         let me = this, bandList = bandTreeOprObj.copyBandList(false);
@@ -395,12 +401,6 @@ let dataInfoMapTreeOprObj = {
     },
     extractTabFields: function (rptTpl) {
         let me = dataInfoMapTreeOprObj;
-        // for (let rootNode of me.treeObj.getNodes()) {
-        //     rptTpl[JV.NODE_FIELD_MAP][rootNode.Name] = [];
-        //     for (let mappingFieldNode of rootNode.items) {
-        //         rptTpl[JV.NODE_FIELD_MAP][rootNode.Name].push(me.createMapFieldByNode(mappingFieldNode));
-        //     }
-        // }
         if (rptTpl[JV.NODE_FLOW_INFO]) {
             //
         }

+ 1 - 0
web/maintain/report/js/rpt_tpl_main.js

@@ -7,6 +7,7 @@ let rptTplObj = {
         rpt_tpl_cfg_helper.getReportTplCfg();
         selectableFiledTreeOprObj.iniTree();
         preview_util.drawBorder($("#tplCanvas")[0]);
+        calculationTreeOprObj.buildRunType();
     }
 }
 

+ 12 - 10
web/maintain/report/rpt_tpl_detail.html

@@ -307,11 +307,11 @@
                         <div class="row" id="element_pre_suff">
                             <div class="input-group col-6">
                                 <div class="input-group-addon">前缀</div>
-                                <input class="form-control" id="elePrefix" value="" onchange="rpt_tpl_cfg_helper.changePreSuff(this, 'Prefix')">
+                                <input class="form-control" id="elePrefix" value="" onkeyup="rpt_tpl_cfg_helper.changePreSuff(this, 'Prefix')">
                             </div>
                             <div class="input-group col-6">
                                 <div class="input-group-addon">后缀</div>
-                                <input class="form-control" id="eleSuffix" value="" onchange="rpt_tpl_cfg_helper.changePreSuff(this, 'Suffix')">
+                                <input class="form-control" id="eleSuffix" value="" onkeyup="rpt_tpl_cfg_helper.changePreSuff(this, 'Suffix')">
                             </div>
                         </div>
                         <div class="form-group" id="dispRowHeight">
@@ -353,16 +353,18 @@
                         </div>
                     </div>
                     <div class="p-3" id="exprDetail">
-                        <div class="form-group">
-                            <label>计算式执行点</label>
-                            <select class="form-control" id="exprRunType" onchange="calculationTreeOprObj.changeRunType(this)"></select>
-                        </div>
-                        <div class="form-group">
-                            <label>Format</label>
-                            <input class="form-control" id="exprFormat" value="" onchange="calculationTreeOprObj.changeFormat(this)">
+                        <div class="row">
+                            <div class="form-group col-md-3">
+                                <label>计算式执行点</label>
+                                <select class="form-control" id="exprRunType" onchange="calculationTreeOprObj.changeRunType(this)"></select>
+                            </div>
+                            <div class="form-group col-md-9">
+                                <label>格式串(format)</label>
+                                <input class="form-control" id="exprFormat" value="" onkeyup="calculationTreeOprObj.changeFormat(this)">
+                            </div>
                         </div>
                         <div class="form-group">
-                            <textarea rows="8" cols="80" id="exprContent" onchange="calculationTreeOprObj.changeExpression(this)"></textarea>
+                            <textarea rows="16" cols="98" id="exprContent" onkeyup="calculationTreeOprObj.changeExpression(this)"></textarea>
                         </div>
                     </div>
                 </div>