jpc_helper_discrete.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. 'use strict';
  2. const JV = require('../jpc_value_define');
  3. const JE = require('../jpc_rte');
  4. const JpcTextHelper = require('./jpc_helper_text');
  5. const JpcCommonOutputHelper = require('./jpc_helper_common_output');
  6. const JpcAreaHelper = require('./jpc_helper_area');
  7. const JpcFieldHelper = require('./jpc_helper_field');
  8. const SEG_PAGE_SPLIT_STR = '`';
  9. const JpcDiscreteHelper = {
  10. outputDiscreteInfo: function(discreteArray, bands, dataObj, unitFactor, pageStatus, segIdx, segPageIdx, multiCols, multiColIdx, $CURRENT_RPT, customizeCfg, signatureRst, signatureDateRst, signatureAuditRst) {
  11. const rst = [];
  12. if (discreteArray && dataObj) {
  13. for (let i = 0; i < discreteArray.length; i++) {
  14. const band = bands[discreteArray[i][JV.PROP_BAND_NAME]];
  15. if (band && pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] === true) {
  16. if (discreteArray[i][JV.PROP_TEXT]) {
  17. rst.push(JpcTextHelper.outputText(discreteArray[i][JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, multiCols, multiColIdx));
  18. }
  19. if (discreteArray[i][JV.PROP_TEXTS]) {
  20. for (let j = 0; j < discreteArray[i][JV.PROP_TEXTS].length; j++) {
  21. rst.push(JpcTextHelper.outputText(discreteArray[i][JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, multiCols, multiColIdx));
  22. }
  23. }
  24. if (discreteArray[i][JV.PROP_DISCRETE_FIELDS]) {
  25. let flexiblePrecisionRefObj = null;
  26. let flexibleRefField = null;
  27. for (let j = 0; j < discreteArray[i][JV.PROP_DISCRETE_FIELDS].length; j++) {
  28. const df = discreteArray[i][JV.PROP_DISCRETE_FIELDS][j];
  29. if (!this.setupSignatureFieldParam(signatureRst, signatureDateRst, signatureAuditRst, $CURRENT_RPT, band, unitFactor, df)) {
  30. let value = '';
  31. let isPic = false;
  32. if (df[JV.PROP_FIELD_ID]) {
  33. // let map_data_field = JE.F(df[JV.PROP_FIELD_ID], $CURRENT_RPT);
  34. const map_data_field = JE.F(df[JV.PROP_FIELD_ID], $CURRENT_RPT);
  35. isPic = (map_data_field.isPic !== undefined && map_data_field.isPic);
  36. if (map_data_field.DataSeq !== JV.BLANK_FIELD_INDEX) {
  37. const data = dataObj[map_data_field.DataNodeName][map_data_field.DataSeq];
  38. if (data && data.length > 0) {
  39. if (data.length > segIdx) {
  40. value = data[segIdx];
  41. } else {
  42. value = data[0];
  43. }
  44. value = this._getSegPageValue(value, segPageIdx);
  45. // console.log(value);
  46. }
  47. } else {
  48. if (map_data_field[JV.PROP_AD_HOC_DATA] && map_data_field[JV.PROP_AD_HOC_DATA].length > 0) {
  49. const data = map_data_field[JV.PROP_AD_HOC_DATA];
  50. if (data && data.length > 0) {
  51. if (data.length > segIdx) {
  52. value = data[segIdx];
  53. } else {
  54. value = data[0];
  55. }
  56. }
  57. // value = map_data_field[JV.PROP_AD_HOC_DATA][0];
  58. } else value = '';
  59. }
  60. if (map_data_field && map_data_field[JV.PROP_PRECISION] && map_data_field.flexiblePrecisionRefObj) {
  61. let pre_ref_data = null;
  62. if (flexiblePrecisionRefObj === null) {
  63. flexiblePrecisionRefObj = {};
  64. flexibleRefField = JE.F(map_data_field[JV.PROP_PRECISION][JV.PROP_FLEXIBLE_REF_FILED_ID], $CURRENT_RPT);
  65. pre_ref_data = dataObj[map_data_field.DataNodeName][flexibleRefField.DataSeq]; // 这里的引用指标必须得存在,哪怕不显示,也要存放在指标集合中!
  66. for (const decimalObj of map_data_field.flexiblePrecisionRefObj) {
  67. flexiblePrecisionRefObj['refUnit_' + decimalObj.unit] = decimalObj.decimal;
  68. }
  69. }
  70. JpcFieldHelper.resetFlexibleFormat(df, pre_ref_data, flexiblePrecisionRefObj, segIdx, customizeCfg);
  71. } else {
  72. JpcFieldHelper.resetFormat(df, map_data_field, customizeCfg);
  73. }
  74. } else if (df[JV.PROP_PARAM_ID] || df[JV.PROP_ID]) {
  75. let pID = df[JV.PROP_PARAM_ID];
  76. if (df[JV.PROP_ID]) pID = df[JV.PROP_ID];
  77. const param = JE.P(pID, $CURRENT_RPT);
  78. value = param[JV.PROP_DFT_VALUE];
  79. }
  80. // console.log(value);
  81. // if (typeof value === 'string') {
  82. // if (value.indexOf('清单1101-1') >= 0) {
  83. // console.log('before: ' + value);
  84. // }
  85. // }
  86. const item = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, value, true);
  87. // position
  88. item[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, multiCols, multiColIdx, false, false);
  89. if (isPic && item[JV.PROP_VALUE] !== undefined && item[JV.PROP_VALUE] !== null && item[JV.PROP_VALUE] !== '') {
  90. if (Array.isArray(signatureRst)) {
  91. if (item[JV.PROP_VALUE][0] !== '/') {
  92. item[JV.PROP_VALUE] = '/' + item[JV.PROP_VALUE];
  93. }
  94. const signatureItem = { signature_name: JV.SIGNATURE_NAME_DUMMY, path: item[JV.PROP_VALUE], pic: null }; // 这里的pic数据在指标中里已经处理过了
  95. signatureItem[JV.PROP_CONTROL] = item[[JV.PROP_CONTROL]];
  96. signatureItem[JV.PROP_STYLE] = item[[JV.PROP_STYLE]];
  97. signatureItem[JV.PROP_AREA] = item[JV.PROP_AREA];
  98. signatureRst.push(signatureItem);
  99. item[JV.PROP_VALUE] = '';
  100. }
  101. }
  102. rst.push(item); // 不管是不是Pic,都得保留一个壳子
  103. }
  104. /*
  105. if (JE.isSignature(df[JV.PROP_FIELD_ID], $CURRENT_RPT)) {
  106. // 这里输出到signatureRst
  107. if (Array.isArray(signatureRst)) {
  108. const map_data_field = JE.F(df[JV.PROP_FIELD_ID], $CURRENT_RPT);
  109. const signatureItem = { signature_name: map_data_field[JV.PROP_NAME], path: null, pic: null };
  110. signatureItem[JV.PROP_CONTROL] = df[[JV.PROP_CONTROL]];
  111. signatureItem[JV.PROP_STYLE] = df[[JV.PROP_STYLE]];
  112. signatureItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  113. signatureRst.push(signatureItem);
  114. }
  115. } else if (JE.isDynamicParam(df[JV.PROP_PARAM_ID], $CURRENT_RPT)) {
  116. // 这里输出到signatureDateRst
  117. // console.log('current sign date df :');
  118. // console.log(df);
  119. if (Array.isArray(signatureDateRst)) {
  120. let pID = 0;
  121. if (df.hasOwnProperty(JV.PROP_PARAM_ID)) {
  122. pID = df[JV.PROP_PARAM_ID];
  123. } else {
  124. pID = df[JV.PROP_ID];
  125. }
  126. const param = JE.P(pID, $CURRENT_RPT);
  127. // const signatureDateItem = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, param[JV.PROP_DFT_VALUE], true);
  128. const signatureDateItem = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, df[JV.PROP_DFT_VALUE], true);
  129. // console.log('Date param :');
  130. // console.log(param);
  131. signatureDateItem.signature_name = param[JV.PROP_NAME];
  132. signatureDateItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  133. signatureDateRst.push(signatureDateItem);
  134. }
  135. } else if (JE.isSignatureAudit(df[JV.PROP_PARAM_ID], $CURRENT_RPT)) {
  136. if (Array.isArray(signatureAuditRst)) {
  137. let pID = 0;
  138. if (df.hasOwnProperty(JV.PROP_PARAM_ID)) {
  139. pID = df[JV.PROP_PARAM_ID];
  140. } else {
  141. pID = df[JV.PROP_ID];
  142. }
  143. const param = JE.P(pID, $CURRENT_RPT);
  144. const signatureAuditItem = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, df[JV.PROP_DFT_VALUE], true);
  145. // console.log('Aidit param :');
  146. // console.log(param);
  147. signatureAuditItem.signature_name = param[JV.PROP_NAME];
  148. signatureAuditItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  149. signatureAuditRst.push(signatureAuditItem);
  150. }
  151. } else {
  152. }
  153. /*/
  154. }
  155. }
  156. }
  157. }
  158. }
  159. return rst;
  160. },
  161. setupSignatureFieldParam: function(signatureRst, signatureDateRst, signatureAuditRst, $CURRENT_RPT, band, unitFactor, df) {
  162. let rst = false;
  163. if (JE.isSignature(df[JV.PROP_FIELD_ID], $CURRENT_RPT)) {
  164. // 这里输出到signatureRst
  165. if (Array.isArray(signatureRst)) {
  166. const map_data_field = JE.F(df[JV.PROP_FIELD_ID], $CURRENT_RPT);
  167. const signatureItem = { signature_name: map_data_field[JV.PROP_NAME], path: null, pic: null };
  168. signatureItem[JV.PROP_CONTROL] = df[[JV.PROP_CONTROL]];
  169. signatureItem[JV.PROP_STYLE] = df[[JV.PROP_STYLE]];
  170. signatureItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  171. signatureRst.push(signatureItem);
  172. rst = true;
  173. }
  174. } else if (JE.isDynamicParam(df[JV.PROP_PARAM_ID], $CURRENT_RPT)) {
  175. // 这里输出到signatureDateRst
  176. // console.log('current sign date df :');
  177. // console.log(df);
  178. if (Array.isArray(signatureDateRst)) {
  179. let pID = 0;
  180. if (df.hasOwnProperty(JV.PROP_PARAM_ID)) {
  181. pID = df[JV.PROP_PARAM_ID];
  182. } else {
  183. pID = df[JV.PROP_ID];
  184. }
  185. const param = JE.P(pID, $CURRENT_RPT);
  186. // const signatureDateItem = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, param[JV.PROP_DFT_VALUE], true);
  187. const signatureDateItem = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, df[JV.PROP_DFT_VALUE], true);
  188. // console.log('Date param :');
  189. // console.log(param);
  190. signatureDateItem.signature_name = param[JV.PROP_NAME];
  191. signatureDateItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  192. signatureDateRst.push(signatureDateItem);
  193. rst = true;
  194. }
  195. } else if (JE.isSignatureAudit(df[JV.PROP_PARAM_ID], $CURRENT_RPT)) {
  196. if (Array.isArray(signatureAuditRst)) {
  197. let pID = 0;
  198. if (df.hasOwnProperty(JV.PROP_PARAM_ID)) {
  199. pID = df[JV.PROP_PARAM_ID];
  200. } else {
  201. pID = df[JV.PROP_ID];
  202. }
  203. const param = JE.P(pID, $CURRENT_RPT);
  204. const signatureAuditItem = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, df[JV.PROP_DFT_VALUE], true);
  205. // console.log('Aidit param :');
  206. // console.log(param);
  207. signatureAuditItem.signature_name = param[JV.PROP_NAME];
  208. signatureAuditItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  209. signatureAuditRst.push(signatureAuditItem);
  210. rst = true;
  211. }
  212. }
  213. return rst;
  214. },
  215. _getSegPageValue: function(orgData, segPageIdx) {
  216. let rst = orgData;
  217. if (typeof orgData === 'string') {
  218. const splitStrs = orgData.split(SEG_PAGE_SPLIT_STR);
  219. if (splitStrs.length > 1) {
  220. if (splitStrs.length > segPageIdx) {
  221. rst = splitStrs[segPageIdx];
  222. } else {
  223. rst = splitStrs[splitStrs.length - 1];
  224. }
  225. }
  226. }
  227. return rst;
  228. },
  229. outputPreviewDiscreteInfo: function(discreteArray, bands, unitFactor, pageStatus) {
  230. const rst = [];
  231. for (let i = 0; i < discreteArray.length; i++) {
  232. const band = bands[discreteArray[i][JV.PROP_BAND_NAME]];
  233. if (band && pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] === true) {
  234. if (discreteArray[i][JV.PROP_TEXT]) {
  235. rst.push(JpcTextHelper.outputText(discreteArray[i][JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, 1, 0));
  236. }
  237. if (discreteArray[i][JV.PROP_TEXTS]) {
  238. for (let j = 0; j < discreteArray[i][JV.PROP_TEXTS].length; j++) {
  239. rst.push(JpcTextHelper.outputText(discreteArray[i][JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, 1, 0));
  240. }
  241. }
  242. if (discreteArray[i][JV.PROP_DISCRETE_FIELDS]) {
  243. for (let j = 0; j < discreteArray[i][JV.PROP_DISCRETE_FIELDS].length; j++) {
  244. const df = discreteArray[i][JV.PROP_DISCRETE_FIELDS][j];
  245. let value = '';
  246. if (df[JV.PROP_DFT_VALUE]) {
  247. value = df[JV.PROP_DFT_VALUE];
  248. }
  249. const item = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, value, null);
  250. // position
  251. item[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  252. rst.push(item);
  253. }
  254. }
  255. }
  256. }
  257. return rst;
  258. },
  259. outputPreviewSumInfoOutput: function(band, unitFactor, tab) {
  260. const rst = [];
  261. if (tab[JV.PROP_TEXT]) {
  262. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, 1, 0));
  263. }
  264. if (tab[JV.PROP_TEXTS]) {
  265. for (let j = 0; j < tab[JV.PROP_TEXTS].length; j++) {
  266. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, 1, 0));
  267. }
  268. }
  269. if (tab[JV.PROP_SUM_FIELDS]) {
  270. for (let i = 0; i < tab[JV.PROP_SUM_FIELDS].length; i++) {
  271. const tab_field = tab[JV.PROP_SUM_FIELDS][i];
  272. if (!(tab_field[JV.PROP_HIDDEN])) {
  273. // rst.push(me.outputTabField(band, tab_field, null, -1, -1, 1, 0, 1, 0, unitFactor, true, controls, 0));
  274. const value = '';
  275. const item = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(tab_field, value, null);
  276. // position
  277. item[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  278. rst.push(item);
  279. }
  280. }
  281. }
  282. return rst;
  283. },
  284. }
  285. module.exports = JpcDiscreteHelper;