jpc_helper_discrete.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 JpcDiscreteHelper = {
  9. outputDiscreteInfo: function(discreteArray, bands, dataObj, unitFactor, pageStatus, segIdx, multiCols, multiColIdx, $CURRENT_RPT, customizeCfg, signatureRst, signatureDateRst, signatureAuditRst) {
  10. const rst = [];
  11. if (discreteArray && dataObj) {
  12. for (let i = 0; i < discreteArray.length; i++) {
  13. const band = bands[discreteArray[i][JV.PROP_BAND_NAME]];
  14. if (band && pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] === true) {
  15. if (discreteArray[i][JV.PROP_TEXT]) {
  16. rst.push(JpcTextHelper.outputText(discreteArray[i][JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, multiCols, multiColIdx));
  17. }
  18. if (discreteArray[i][JV.PROP_TEXTS]) {
  19. for (let j = 0; j < discreteArray[i][JV.PROP_TEXTS].length; j++) {
  20. rst.push(JpcTextHelper.outputText(discreteArray[i][JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, multiCols, multiColIdx));
  21. }
  22. }
  23. if (discreteArray[i][JV.PROP_DISCRETE_FIELDS]) {
  24. let flexiblePrecisionRefObj = null;
  25. let flexibleRefField = null;
  26. for (let j = 0; j < discreteArray[i][JV.PROP_DISCRETE_FIELDS].length; j++) {
  27. const df = discreteArray[i][JV.PROP_DISCRETE_FIELDS][j];
  28. if (JE.isSignature(df[JV.PROP_FIELD_ID], $CURRENT_RPT)) {
  29. // 这里输出到signatureRst
  30. if (Array.isArray(signatureRst)) {
  31. const map_data_field = JE.F(df[JV.PROP_FIELD_ID], $CURRENT_RPT);
  32. const signatureItem = { signature_name: map_data_field[JV.PROP_NAME], path: null, pic: null };
  33. signatureItem[JV.PROP_CONTROL] = df[[JV.PROP_CONTROL]];
  34. signatureItem[JV.PROP_STYLE] = df[[JV.PROP_STYLE]];
  35. signatureItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  36. signatureRst.push(signatureItem);
  37. }
  38. } else if (JE.isDynamicParam(df[JV.PROP_PARAM_ID], $CURRENT_RPT)) {
  39. // 这里输出到signatureDateRst
  40. // console.log('current sign date df :');
  41. // console.log(df);
  42. if (Array.isArray(signatureDateRst)) {
  43. let pID = 0;
  44. if (df.hasOwnProperty(JV.PROP_PARAM_ID)) {
  45. pID = df[JV.PROP_PARAM_ID];
  46. } else {
  47. pID = df[JV.PROP_ID];
  48. }
  49. const param = JE.P(pID, $CURRENT_RPT);
  50. // const signatureDateItem = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, param[JV.PROP_DFT_VALUE], true);
  51. const signatureDateItem = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, df[JV.PROP_DFT_VALUE], true);
  52. // console.log('param :');
  53. // console.log(param);
  54. signatureDateItem.signature_name = param[JV.PROP_NAME];
  55. signatureDateItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  56. signatureDateRst.push(signatureDateItem);
  57. }
  58. } else if (JE.isSignatureAudit(df[JV.PROP_PARAM_ID], $CURRENT_RPT)) {
  59. if (Array.isArray(signatureAuditRst)) {
  60. let pID = 0;
  61. if (df.hasOwnProperty(JV.PROP_PARAM_ID)) {
  62. pID = df[JV.PROP_PARAM_ID];
  63. } else {
  64. pID = df[JV.PROP_ID];
  65. }
  66. const param = JE.P(pID, $CURRENT_RPT);
  67. const signatureAuditItem = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, df[JV.PROP_DFT_VALUE], true);
  68. signatureAuditItem.signature_name = param[JV.PROP_NAME];
  69. signatureAuditItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  70. signatureAuditRst.push(signatureAuditItem);
  71. }
  72. } else {
  73. let value = '';
  74. let isPic = false;
  75. if (df[JV.PROP_FIELD_ID]) {
  76. // let map_data_field = JE.F(df[JV.PROP_FIELD_ID], $CURRENT_RPT);
  77. const map_data_field = JE.F(df[JV.PROP_FIELD_ID], $CURRENT_RPT);
  78. isPic = (map_data_field.isPic !== undefined && map_data_field.isPic);
  79. if (map_data_field.DataSeq !== JV.BLANK_FIELD_INDEX) {
  80. const data = dataObj[map_data_field.DataNodeName][map_data_field.DataSeq];
  81. if (data && data.length > 0) {
  82. if (data.length > segIdx) {
  83. value = data[segIdx];
  84. } else {
  85. value = data[0];
  86. }
  87. }
  88. } else {
  89. if (map_data_field[JV.PROP_AD_HOC_DATA] && map_data_field[JV.PROP_AD_HOC_DATA].length > 0) {
  90. const data = map_data_field[JV.PROP_AD_HOC_DATA];
  91. if (data && data.length > 0) {
  92. if (data.length > segIdx) {
  93. value = data[segIdx];
  94. } else {
  95. value = data[0];
  96. }
  97. }
  98. // value = map_data_field[JV.PROP_AD_HOC_DATA][0];
  99. } else value = '';
  100. }
  101. if (map_data_field && map_data_field[JV.PROP_PRECISION] && map_data_field.flexiblePrecisionRefObj) {
  102. let pre_ref_data = null;
  103. if (flexiblePrecisionRefObj === null) {
  104. flexiblePrecisionRefObj = {};
  105. flexibleRefField = JE.F(map_data_field[JV.PROP_PRECISION][JV.PROP_FLEXIBLE_REF_FILED_ID], $CURRENT_RPT);
  106. pre_ref_data = dataObj[map_data_field.DataNodeName][flexibleRefField.DataSeq]; // 这里的引用指标必须得存在,哪怕不显示,也要存放在指标集合中!
  107. for (const decimalObj of map_data_field.flexiblePrecisionRefObj) {
  108. flexiblePrecisionRefObj['refUnit_' + decimalObj.unit] = decimalObj.decimal;
  109. }
  110. }
  111. JpcFieldHelper.resetFlexibleFormat(df, pre_ref_data, flexiblePrecisionRefObj, segIdx, customizeCfg);
  112. } else {
  113. JpcFieldHelper.resetFormat(df, map_data_field, customizeCfg);
  114. }
  115. } else if (df[JV.PROP_PARAM_ID] || df[JV.PROP_ID]) {
  116. let pID = df[JV.PROP_PARAM_ID];
  117. if (df[JV.PROP_ID]) pID = df[JV.PROP_ID];
  118. const param = JE.P(pID, $CURRENT_RPT);
  119. value = param[JV.PROP_DFT_VALUE];
  120. }
  121. // console.log(value);
  122. // if (typeof value === 'string') {
  123. // if (value.indexOf('清单1101-1') >= 0) {
  124. // console.log('before: ' + value);
  125. // }
  126. // }
  127. const item = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, value, true);
  128. // position
  129. item[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, multiCols, multiColIdx, false, false);
  130. if (isPic && item[JV.PROP_VALUE] !== undefined && item[JV.PROP_VALUE] !== null && item[JV.PROP_VALUE] !== '') {
  131. if (Array.isArray(signatureRst)) {
  132. if (item[JV.PROP_VALUE][0] !== '/') {
  133. item[JV.PROP_VALUE] = '/' + item[JV.PROP_VALUE];
  134. }
  135. const signatureItem = { signature_name: JV.SIGNATURE_NAME_DUMMY, path: item[JV.PROP_VALUE], pic: null }; // 这里的pic数据在指标中里已经处理过了
  136. signatureItem[JV.PROP_CONTROL] = item[[JV.PROP_CONTROL]];
  137. signatureItem[JV.PROP_STYLE] = item[[JV.PROP_STYLE]];
  138. signatureItem[JV.PROP_AREA] = item[JV.PROP_AREA];
  139. signatureRst.push(signatureItem);
  140. item[JV.PROP_VALUE] = '';
  141. }
  142. }
  143. rst.push(item); // 不管是不是Pic,都得保留一个壳子
  144. }
  145. }
  146. }
  147. }
  148. }
  149. }
  150. return rst;
  151. },
  152. outputPreviewDiscreteInfo: function(discreteArray, bands, unitFactor, pageStatus) {
  153. const rst = [];
  154. for (let i = 0; i < discreteArray.length; i++) {
  155. const band = bands[discreteArray[i][JV.PROP_BAND_NAME]];
  156. if (band && pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]] === true) {
  157. if (discreteArray[i][JV.PROP_TEXT]) {
  158. rst.push(JpcTextHelper.outputText(discreteArray[i][JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, 1, 0));
  159. }
  160. if (discreteArray[i][JV.PROP_TEXTS]) {
  161. for (let j = 0; j < discreteArray[i][JV.PROP_TEXTS].length; j++) {
  162. rst.push(JpcTextHelper.outputText(discreteArray[i][JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, 1, 0));
  163. }
  164. }
  165. if (discreteArray[i][JV.PROP_DISCRETE_FIELDS]) {
  166. for (let j = 0; j < discreteArray[i][JV.PROP_DISCRETE_FIELDS].length; j++) {
  167. const df = discreteArray[i][JV.PROP_DISCRETE_FIELDS][j];
  168. let value = '';
  169. if (df[JV.PROP_DFT_VALUE]) {
  170. value = df[JV.PROP_DFT_VALUE];
  171. }
  172. const item = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, value, null);
  173. // position
  174. item[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  175. rst.push(item);
  176. }
  177. }
  178. }
  179. }
  180. return rst;
  181. },
  182. outputPreviewSumInfoOutput: function(band, unitFactor, tab) {
  183. const rst = [];
  184. if (tab[JV.PROP_TEXT]) {
  185. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, 1, 0));
  186. }
  187. if (tab[JV.PROP_TEXTS]) {
  188. for (let j = 0; j < tab[JV.PROP_TEXTS].length; j++) {
  189. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, 1, 0));
  190. }
  191. }
  192. if (tab[JV.PROP_SUM_FIELDS]) {
  193. for (let i = 0; i < tab[JV.PROP_SUM_FIELDS].length; i++) {
  194. const tab_field = tab[JV.PROP_SUM_FIELDS][i];
  195. if (!(tab_field[JV.PROP_HIDDEN])) {
  196. // rst.push(me.outputTabField(band, tab_field, null, -1, -1, 1, 0, 1, 0, unitFactor, true, controls, 0));
  197. const value = '';
  198. const item = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(tab_field, value, null);
  199. // position
  200. item[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, 1, 0, false, false);
  201. rst.push(item);
  202. }
  203. }
  204. }
  205. return rst;
  206. },
  207. }
  208. module.exports = JpcDiscreteHelper;