jpc_bill_tab.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. 'use strict';
  2. const JV = require('./jpc_value_define');
  3. const JE = require('./jpc_rte');
  4. const JpcFieldHelper = require('./helper/jpc_helper_field');
  5. const JpcBandHelper = require('./helper/jpc_helper_band');
  6. const JpcCommonHelper = require('./helper/jpc_helper_common');
  7. const JpcDiscreteHelper = require('./helper/jpc_helper_discrete');
  8. const JpcTextHelper = require('./helper/jpc_helper_text');
  9. const JpcCommonOutputHelper = require('./helper/jpc_helper_common_output');
  10. const JpcAreaHelper = require('./helper/jpc_helper_area');
  11. const JpcBillTabSrv = function() {};
  12. JpcBillTabSrv.prototype.createNew = function() {
  13. const JpcBillTabResult = {};
  14. JpcBillTabResult.initialize = function() {
  15. const me = this;
  16. me.disp_fields_idx = [];
  17. me.signatureRst = [];
  18. me.signatureDateRst = [];
  19. me.signatureAuditRst = [];
  20. me.figureRst = [];
  21. me.totalPages = 0;
  22. };
  23. JpcBillTabResult.sorting = function(rptTpl) {
  24. const me = this;
  25. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[JV.NODE_BILL_INFO][JV.NODE_BILL_CONTENT][JV.PROP_BILL_FIELDS], null, me.disp_fields_idx);
  26. };
  27. JpcBillTabResult.paging = function(rptTpl, dataObj) {
  28. let rst = 0;
  29. const me = this;
  30. function getDataLength(fields_str) {
  31. const dataFields = dataObj[fields_str];
  32. if (dataFields && dataFields.length > 0) {
  33. rst = dataFields[0].length;
  34. }
  35. }
  36. if (rptTpl[JV.NODE_FIELD_MAP]) {
  37. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  38. getDataLength(JV.DATA_DETAIL_DATA);
  39. } else if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS]) {
  40. getDataLength(JV.DATA_MASTER_DATA);
  41. } else if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS]) {
  42. getDataLength(JV.DATA_DISCRETE_DATA);
  43. } else if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_PARAMS]) {
  44. rst = 1;
  45. }
  46. }
  47. me.totalPages = rst;
  48. if (dataObj.splitArcVals) {
  49. // 账单式表 分割
  50. let preVal = dataObj.splitArcVals[0];
  51. let pgIdx = 1;
  52. const pagesForPreSplit = [];
  53. pagesForPreSplit.push(pgIdx);
  54. for (let idx = 1; idx < dataObj.splitArcVals.length; idx++) {
  55. if (preVal !== dataObj.splitArcVals[idx]) {
  56. preVal = dataObj.splitArcVals[idx];
  57. pgIdx++;
  58. }
  59. pagesForPreSplit.push(pgIdx);
  60. }
  61. dataObj.splitArcPages = pagesForPreSplit;
  62. }
  63. return rst;
  64. };
  65. JpcBillTabResult.outputAsPreviewPage = function(rptTpl, bands, controls, $CURRENT_RPT) {
  66. const me = this;
  67. let rst = [];
  68. // const vIdx = [];
  69. // 只预览第一页的数据
  70. const pageStatus = [true, true, true, true, true, true, true, true];
  71. JpcBandHelper.setBandArea(bands, rptTpl, pageStatus, true, false);
  72. const unitFactor = JpcCommonHelper.getUnitFactor(rptTpl);
  73. me.signatureRst = [];
  74. me.signatureDateRst = [];
  75. me.signatureAuditRst = [];
  76. me.interactRst = [];
  77. rst = rst.concat(me.outputPreviewContent(rptTpl, bands, unitFactor, controls, pageStatus, $CURRENT_RPT));
  78. rst = rst.concat(JpcDiscreteHelper.outputPreviewDiscreteInfo(rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO], bands, unitFactor, pageStatus, $CURRENT_RPT, me.interactRst, me.signatureRst, me.signatureDateRst, me.signatureAuditRst));
  79. return rst;
  80. };
  81. JpcBillTabResult.outputAsSimpleJSONPage = function(rptTpl, dataObj, page, bands, controls, fonts, $CURRENT_RPT, customizeCfg) {
  82. const me = this;
  83. let rst = [];
  84. me.signatureRst = [];
  85. me.signatureDateRst = [];
  86. me.signatureAuditRst = [];
  87. me.interactRst = [];
  88. const tabRstLst = [];
  89. // 1. calculate the band position
  90. const pageStatus = [true, false, false, false, false, false, false, false];
  91. if (page === 1) {
  92. pageStatus[JV.STATUS_REPORT_START] = true;
  93. pageStatus[JV.STATUS_SEGMENT_START] = true;
  94. }
  95. if (page === me.totalPages) {
  96. pageStatus[JV.STATUS_REPORT_END] = true;
  97. pageStatus[JV.STATUS_SEGMENT_END] = true;
  98. }
  99. JpcBandHelper.setBandArea(bands, rptTpl, pageStatus);
  100. // 2. start to output detail-part
  101. const unitFactor = JpcCommonHelper.getUnitFactor(rptTpl);
  102. // 2.1 output content
  103. tabRstLst.push(me.outputContent(rptTpl, dataObj, page, bands, unitFactor, controls, pageStatus, $CURRENT_RPT, customizeCfg));
  104. // 2.2 output discrete
  105. tabRstLst.push(JpcDiscreteHelper.outputDiscreteInfo(rptTpl[JV.NODE_BILL_INFO][JV.NODE_DISCRETE_INFO], bands, dataObj, unitFactor, pageStatus, page - 1, 0, 1, 0, $CURRENT_RPT, customizeCfg, me.signatureRst, me.signatureDateRst, me.signatureAuditRst, me.interactRst));
  106. for (let i = 0; i < tabRstLst.length; i++) {
  107. rst = rst.concat(tabRstLst[i]);
  108. tabRstLst[i] = null;
  109. }
  110. return rst;
  111. };
  112. JpcBillTabResult.outputPreviewContent = function(rptTpl, bands, unitFactor, controls, pageStatus, $CURRENT_RPT) {
  113. const me = this;
  114. let rst = [];
  115. const tab = rptTpl[JV.NODE_BILL_INFO][JV.NODE_BILL_CONTENT];
  116. const band = bands[tab[JV.PROP_BAND_NAME]];
  117. if (band) {
  118. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
  119. const tab_fields = tab[JV.PROP_BILL_FIELDS];
  120. for (let i = 0; i < tab_fields.length; i++) {
  121. const tab_field = tab_fields[i];
  122. if (!(tab_field[JV.PROP_HIDDEN])) {
  123. if (!JpcDiscreteHelper.setupSignatureFieldParam(me.signatureRst, me.signatureDateRst, me.signatureAuditRst, me.interactRst, $CURRENT_RPT, band, unitFactor, tab_field)) {
  124. const cellItem = JpcCommonOutputHelper.createCommonOutput(tab_field, '', controls);
  125. cellItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  126. if (JE.isInterActionParam(tab_field[JV.PROP_PARAM_ID], $CURRENT_RPT)) {
  127. const iParam = JE.P(tab_field[JV.PROP_PARAM_ID], $CURRENT_RPT);
  128. cellItem[JV.PROP_BAND_NAME] = band.Name;
  129. cellItem[JV.PROP_DATA_TYPE] = iParam[JV.PROP_DATA_TYPE];
  130. cellItem[JV.PROP_LABEL] = iParam[JV.PROP_NAME];
  131. cellItem[JV.PROP_PREFIX] = tab_field[JV.PROP_PREFIX];
  132. this.interactRst.push(cellItem);
  133. } else {
  134. rst.push(cellItem);
  135. }
  136. }
  137. }
  138. }
  139. if (tab[JV.PROP_TEXT]) {
  140. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, 1, 0));
  141. }
  142. if (tab[JV.PROP_TEXTS]) {
  143. for (let j = 0; j < tab[JV.PROP_TEXTS].length; j++) {
  144. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, 1, 0));
  145. }
  146. }
  147. if (tab[JV.NODE_DISCRETE_INFO]) {
  148. rst = rst.concat(JpcDiscreteHelper.outputPreviewDiscreteInfo(tab[JV.NODE_DISCRETE_INFO], bands, unitFactor, pageStatus, $CURRENT_RPT, this.interactRst, me.signatureRst, me.signatureDateRst, me.signatureAuditRst));
  149. }
  150. }
  151. }
  152. return rst;
  153. };
  154. JpcBillTabResult.outputContent = function(rptTpl, dataObj, page, bands, unitFactor, controls, pageStatus, $CURRENT_RPT, customizeCfg) {
  155. const me = this;
  156. let rst = [];
  157. const tab = rptTpl[JV.NODE_BILL_INFO][JV.NODE_BILL_CONTENT];
  158. const band = bands[tab[JV.PROP_BAND_NAME]];
  159. if (band) {
  160. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
  161. const tab_fields = tab[JV.PROP_BILL_FIELDS];
  162. let data_details = null;
  163. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  164. data_details = dataObj[JV.DATA_DETAIL_DATA];
  165. } else if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS]) {
  166. data_details = dataObj[JV.DATA_MASTER_DATA];
  167. }
  168. let flexiblePrecisionRefObj = null;
  169. let flexibleRefField;
  170. let precision_ref_data;
  171. let isPic = false;
  172. for (let i = 0; i < tab_fields.length; i++) {
  173. const tab_field = tab_fields[i];
  174. if (!JpcDiscreteHelper.setupSignatureFieldParam(me.signatureRst, me.signatureDateRst, me.signatureAuditRst, me.interactRst, $CURRENT_RPT, band, unitFactor, tab_field)) {
  175. let data_field = null;
  176. const map_data_field = JE.F(tab_field[JV.PROP_FIELD_ID], $CURRENT_RPT);
  177. isPic = (map_data_field.isPic !== undefined && map_data_field.isPic);
  178. if (me.disp_fields_idx.length > i && me.disp_fields_idx[i] !== JV.BLANK_FIELD_INDEX && (typeof me.disp_fields_idx[i] !== 'object')) {
  179. data_field = data_details[me.disp_fields_idx[i]];
  180. } else {
  181. if (map_data_field) {
  182. data_field = map_data_field[JV.PROP_AD_HOC_DATA];
  183. }
  184. }
  185. if (map_data_field && map_data_field[JV.PROP_PRECISION] && map_data_field.flexiblePrecisionRefObj) {
  186. if (flexiblePrecisionRefObj === null) {
  187. flexiblePrecisionRefObj = {};
  188. flexibleRefField = JE.F(map_data_field[JV.PROP_PRECISION][JV.PROP_FLEXIBLE_REF_FILED_ID], $CURRENT_RPT);
  189. precision_ref_data = dataObj[map_data_field.DataNodeName][flexibleRefField.DataSeq];
  190. for (const decimalObj of map_data_field.flexiblePrecisionRefObj) {
  191. flexiblePrecisionRefObj['refUnit_' + decimalObj.unit] = decimalObj.decimal;
  192. }
  193. }
  194. JpcFieldHelper.resetFlexibleFormat(tab_field, precision_ref_data, flexiblePrecisionRefObj, page - 1, customizeCfg);
  195. } else {
  196. if (page === 1) JpcFieldHelper.resetFormat(tab_field, map_data_field, customizeCfg);
  197. }
  198. if (!(tab_field[JV.PROP_HIDDEN])) {
  199. const val = JpcFieldHelper.getValue(data_field, page - 1);
  200. const cellItem = JpcCommonOutputHelper.createCommonOutput(tab_field, val, controls);
  201. cellItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  202. if (isPic && cellItem[JV.PROP_VALUE] !== undefined && cellItem[JV.PROP_VALUE] !== null && cellItem[JV.PROP_VALUE] !== '') {
  203. if (Array.isArray(me.signatureRst)) {
  204. if (cellItem[JV.PROP_VALUE][0] !== '/') {
  205. cellItem[JV.PROP_VALUE] = '/' + cellItem[JV.PROP_VALUE];
  206. }
  207. const signatureItem = { signature_name: JV.SIGNATURE_NAME_DUMMY, path: cellItem[JV.PROP_VALUE], pic: null }; // 这里的pic数据在指标中里已经处理过了
  208. signatureItem[JV.PROP_CONTROL] = cellItem[[JV.PROP_CONTROL]];
  209. signatureItem[JV.PROP_STYLE] = cellItem[[JV.PROP_STYLE]];
  210. signatureItem[JV.PROP_AREA] = cellItem[JV.PROP_AREA];
  211. me.signatureRst.push(signatureItem);
  212. cellItem[JV.PROP_VALUE] = '';
  213. }
  214. }
  215. rst.push(cellItem); // 不管是不是Pic,都得保留一个壳子
  216. }
  217. }
  218. }
  219. if (tab[JV.PROP_TEXT]) {
  220. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, 1, 0));
  221. }
  222. if (tab[JV.PROP_TEXTS]) {
  223. for (let j = 0; j < tab[JV.PROP_TEXTS].length; j++) {
  224. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, 1, 0));
  225. }
  226. }
  227. if (tab[JV.NODE_DISCRETE_INFO]) {
  228. rst = rst.concat(JpcDiscreteHelper.outputDiscreteInfo(tab[JV.NODE_DISCRETE_INFO], bands, dataObj, unitFactor, pageStatus, page - 1, 0, 1, 0, customizeCfg, me.signatureRst, me.signatureDateRst, me.signatureAuditRst, me.interactRst));
  229. }
  230. }
  231. }
  232. return rst;
  233. };
  234. return JpcBillTabResult;
  235. };
  236. module.exports = new JpcBillTabSrv();