소스 검색

依据单位控制小数位数方案(后台)

TonyKang 7 년 전
부모
커밋
6743c5b066
3개의 변경된 파일39개의 추가작업 그리고 2개의 파일을 삭제
  1. 37 1
      public/stringUtil.js
  2. 1 0
      web/maintain/report/js/rpt_tpl_calculation.js
  3. 1 1
      web/maintain/report/rpt_tpl_detail_calculation.html

+ 37 - 1
public/stringUtil.js

@@ -227,5 +227,41 @@ module.exports = {
     },
     getPinYinCamelChars: function(value) {
         return pinyin.getCamelChars(value);
+    },
+    formatNumber: function(formatStr, val) {
+        let rst = val;
+        if (formatStr) {
+            if (!(isNaN(parseFloat(val)))) {
+                function comdify(numStr){
+                    let re = /\d{1,3}(?=(\d{3})+$)/g;
+                    return numStr.replace(/^(\d+)((\.\d+)?)$/,function(s,s1,s2){return s1.replace(re,"$&,")+s2;});
+                }
+                let dotIdx = formatStr.indexOf(".");
+                if (dotIdx >= 0) {
+                    let tmpStr = parseFloat(val).toFixed(formatStr.length - dotIdx - 1);
+                    let digStr = formatStr.substr(dotIdx + 1, formatStr.length - dotIdx);
+                    for (let sIdx = digStr.length - 1; sIdx >= 0; sIdx--) {
+                        if (digStr[sIdx] === '#') {
+                            if (tmpStr.length > 0 && tmpStr[tmpStr.length - 1] === '0') {
+                                tmpStr = tmpStr.substr(0, tmpStr.length - 1);
+                            } else {
+                                break;
+                            }
+                        } else {
+                            break;
+                        }
+                    }
+                    if (tmpStr[tmpStr.length - 1] === '.') tmpStr = tmpStr.substr(0, tmpStr.length - 1);
+                    rst = tmpStr;
+                } else {
+                    rst = parseFloat(val).toFixed(0);
+                }
+                let commaIdx = formatStr.indexOf(",");
+                if (commaIdx >= 0) {
+                    rst = comdify(val.toString());
+                }
+            }
+        }
+        return rst;
     }
-};
+}

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 1 - 0
web/maintain/report/js/rpt_tpl_calculation.js


+ 1 - 1
web/maintain/report/rpt_tpl_detail_calculation.html

@@ -8,7 +8,7 @@
         </div>
         <div class="p-3" id="exprDetail">
             <div class="row">
-                <div class="form-group col-md-3">
+                <div class="form-group col-md-5">
                     <label></label>
                     <select class="form-control" id="exprTemplatesSelect"></select>
                 </div>