1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- let JV = require('../jpc_value_define');
- let JpcFieldHelper = require('./jpc_helper_field');
- let JpcCommonOutputHelper = {
- createCommonOutputWithoutDecorate: function (node, value, forceCombine) {
- let me = this, rst = {};
- //1. font/style/control
- rst[JV.PROP_FONT] = node[[JV.PROP_FONT]];
- rst[JV.PROP_CONTROL] = node[[JV.PROP_CONTROL]];
- rst[JV.PROP_STYLE] = node[[JV.PROP_STYLE]];
- //2. value
- rst[JV.PROP_VALUE] = value;
- me.formatCell(node[JV.PROP_FORMAT], rst);
- // innerFormat(node[JV.PROP_FORMAT], rst);
- if (node[JV.PROP_PREFIX] && rst[JV.PROP_VALUE] !== null) {
- rst[JV.PROP_VALUE] = node[JV.PROP_PREFIX] + rst[JV.PROP_VALUE];
- } else if (node[JV.PROP_PREFIX] && forceCombine) {
- rst[JV.PROP_VALUE] = node[JV.PROP_PREFIX];
- }
- if (node[JV.PROP_SUFFIX] && rst[JV.PROP_VALUE] !== null) {
- rst[JV.PROP_VALUE] = rst[JV.PROP_VALUE] + node[JV.PROP_SUFFIX];
- } else if (node[JV.PROP_SUFFIX] && forceCombine) {
- rst[JV.PROP_VALUE] = node[JV.PROP_SUFFIX];
- }
- return rst;
- },
- createCommonOutput: function (node, value, controls) {
- let me = this, rst = {};
- //1. font/style/control
- rst[JV.PROP_FONT] = node[[JV.PROP_FONT]];
- rst[JV.PROP_CONTROL] = node[[JV.PROP_CONTROL]];
- rst[JV.PROP_STYLE] = node[[JV.PROP_STYLE]];
- //2. value
- rst[JV.PROP_VALUE] = value;
- JpcFieldHelper.decorateValue(rst, controls);
- me.formatCell(node[JV.PROP_FORMAT], rst);
- // innerFormat(node[JV.PROP_FORMAT], rst);
- if (node[JV.PROP_PREFIX] && rst[JV.PROP_VALUE] !== null && rst[JV.PROP_VALUE] !== "") {
- rst[JV.PROP_VALUE] = node[JV.PROP_PREFIX] + rst[JV.PROP_VALUE];
- }
- if (node[JV.PROP_SUFFIX] && rst[JV.PROP_VALUE] !== null && rst[JV.PROP_VALUE] !== "") {
- rst[JV.PROP_VALUE] = rst[JV.PROP_VALUE] + node[JV.PROP_SUFFIX];
- }
- return rst;
- },
- formatCell: function (formatStr, rstCell) {
- if (formatStr) {
- if (!(isNaN(parseFloat(rstCell[JV.PROP_VALUE])))) {
- let dotIdx = formatStr.indexOf(".");
- if (dotIdx >= 0) {
- let tmpStr = parseFloat(rstCell[JV.PROP_VALUE]).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);
- rstCell[JV.PROP_VALUE] = tmpStr;
- } else {
- rstCell[JV.PROP_VALUE] = parseFloat(rstCell[JV.PROP_VALUE]).toFixed(0);
- }
- let commaIdx = formatStr.indexOf(",");
- if (commaIdx >= 0) {
- rstCell[JV.PROP_VALUE] = comdify(rstCell[JV.PROP_VALUE].toString());
- }
- }
- }
- }
- };
- 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;});
- }
- module.exports = JpcCommonOutputHelper;
|