Report.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import { __assign, __extends, __read, __spread, __values } from "tslib";
  2. import { Scope } from "../Scope";
  3. import _ from 'lodash';
  4. import { invokeServer, showErrorDialog } from "../lib/systemLib";
  5. export function buildReportScope(config, reportId) {
  6. var _a = buildVjson(config), model = _a.model, vjson = _a.vjson, report = _a.report;
  7. var ret = new ReportScope({ model: model, vjson: vjson });
  8. ret.report_id = reportId;
  9. ret.report = report;
  10. return ret;
  11. }
  12. function buildVjson(config) {
  13. var e_1, _a, e_2, _b, e_3, _c;
  14. var model = {
  15. data: {
  16. report_name: config.report_name,
  17. query: {},
  18. sum: {},
  19. }
  20. };
  21. var report = config.report ? window['json5'].parse(config.report) : {};
  22. var conditionRows = [];
  23. var sumRows = [];
  24. model.data.has_sum = _.size(report.summary) > 0;
  25. // query 查询条件
  26. var newRow = false;
  27. var currentRow = { xtype: 'cols', items: [], };
  28. conditionRows.push(currentRow);
  29. try {
  30. for (var _d = __values(report.query), _e = _d.next(); !_e.done; _e = _d.next()) {
  31. var item = _e.value;
  32. if (newRow) {
  33. currentRow = { xtype: 'cols', items: [], };
  34. conditionRows.push(currentRow);
  35. }
  36. var vj = window['json5'].parse(item.conditionFieldExtend);
  37. if (item.conditionFieldXtype) {
  38. vj.xtype = item.conditionFieldXtype;
  39. if (item.conditionFieldXtype === 'combo') {
  40. vj.fix = ['system.getProjectDict("' + item.conditionFieldDict + '")'];
  41. }
  42. }
  43. else {
  44. // 没有组件类型,是个空占位符
  45. vj.border = false;
  46. }
  47. if (item.conditionFieldBind) {
  48. vj.bind = {
  49. value: '{query.' + item.conditionFieldBind + '}'
  50. };
  51. model.data.query[item.conditionFieldBind] = '';
  52. }
  53. if (item.conditionFieldFlex) {
  54. vj.flex = item.conditionFieldFlex;
  55. }
  56. if (item.conditionFieldXtype) {
  57. vj.fieldLabel = item.conditionFieldLabel;
  58. }
  59. if (item.fieldLabel) {
  60. vj.fieldLabel = item.fieldLabel;
  61. }
  62. newRow = item.conditionFieldWrap || false;
  63. currentRow.items.push(vj);
  64. }
  65. }
  66. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  67. finally {
  68. try {
  69. if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
  70. }
  71. finally { if (e_1) throw e_1.error; }
  72. }
  73. if (currentRow) {
  74. currentRow.margin = '10 0 10 0';
  75. }
  76. // sum 汇总条件
  77. newRow = true;
  78. try {
  79. for (var _f = __values(report.summary), _g = _f.next(); !_g.done; _g = _f.next()) {
  80. var item = _g.value;
  81. if (newRow) {
  82. currentRow = {
  83. xtype: 'cols',
  84. defaultType: 'displayfield',
  85. defaults: {
  86. labelWidth: 70,
  87. },
  88. items: []
  89. };
  90. sumRows.push(currentRow);
  91. }
  92. var vj = __assign({}, window['json5'].parse(item.sumFieldExtend));
  93. if (item.sumFieldBind) {
  94. vj.bind = '{sum.' + item.sumFieldBind + '}';
  95. model.data.sum[item.sumFieldBind] = '';
  96. }
  97. else {
  98. // 没有组件类型,是个空占位符
  99. vj.border = false;
  100. }
  101. if (item.sumFieldFlex) {
  102. vj.flex = item.sumFieldFlex;
  103. }
  104. if (item.sumFieldLabel) {
  105. vj.fieldLabel = item.sumFieldLabel;
  106. }
  107. // sumFieldBind: "zs"
  108. // sumFieldExtend: "{}"
  109. // sumFieldFlex: 1
  110. // sumFieldLabel: "总数"
  111. // sumFieldWrap: false
  112. newRow = item.sumFieldWrap || false;
  113. currentRow.items.push(vj);
  114. }
  115. }
  116. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  117. finally {
  118. try {
  119. if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
  120. }
  121. finally { if (e_2) throw e_2.error; }
  122. }
  123. if (currentRow) {
  124. currentRow.margin = '10 0 10 0';
  125. }
  126. // column 结果字段
  127. var columns = [];
  128. try {
  129. for (var _h = __values(report.columns), _j = _h.next(); !_j.done; _j = _h.next()) {
  130. var item = _j.value;
  131. var vj = __assign({ dataIndex: item.dataIndex, header: item.header, hidden: item.hidden, sortable: item.sortable, filterable: item.filterable }, window['json5'].parse(item.fieldExtend));
  132. if (item.xtype) {
  133. if (item.xtype == 'checkbox') {
  134. vj.xtype = 'checkcolumn';
  135. vj.disabled = true;
  136. }
  137. else {
  138. vj.xtype = item.xtype;
  139. }
  140. }
  141. if (item.dataType) {
  142. vj.dataType = item.dataType;
  143. }
  144. if (item.align) {
  145. vj.align = item.align;
  146. }
  147. if (item.width) {
  148. vj.width = item.width;
  149. }
  150. if (item.dict) {
  151. vj.fix = ['system.getProjectDict("' + item.dict + '")'];
  152. }
  153. columns.push(vj);
  154. }
  155. }
  156. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  157. finally {
  158. try {
  159. if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
  160. }
  161. finally { if (e_3) throw e_3.error; }
  162. }
  163. var vjson = {
  164. bind: {
  165. title: '{report_name}',
  166. },
  167. layout: 'fit',
  168. referenceHolder: true,
  169. items: [
  170. {
  171. layout: 'border',
  172. border: false,
  173. items: [
  174. {
  175. region: 'north',
  176. border: false,
  177. tbar: {
  178. xtype: 'toolbar',
  179. border: false,
  180. items: [
  181. {
  182. xtype: 'button',
  183. text: '查询',
  184. iconCls: 'x-fa fa-search',
  185. listeners: {
  186. click: 'scope.reload',
  187. },
  188. },
  189. {
  190. xtype: 'button',
  191. text: '关闭',
  192. iconCls: 'x-fa fa-times',
  193. listeners: {
  194. click: 'system.closeMe()',
  195. },
  196. },
  197. ],
  198. },
  199. defaults: {
  200. margin: '8 0 0 0'
  201. },
  202. items: __spread(conditionRows, sumRows),
  203. },
  204. __assign({ region: 'center', xtype: 'yvgrid', reference: 'grid1', border: false, selModel: { selType: 'rowmodel', mode: 'SINGLE', }, autoLoad: false, dataSource: {
  205. method: 'invoke',
  206. url: '/report/Report@execute',
  207. params: {
  208. dataSource: report.dataSource,
  209. pagination: report.grid.pagination || true,
  210. report_id: config.report_id,
  211. query: '{query}',
  212. },
  213. }, columns: columns }, report.grid),
  214. ],
  215. },
  216. ],
  217. };
  218. return { model: model, vjson: vjson, report: report };
  219. }
  220. var ReportScope = /** @class */ (function (_super) {
  221. __extends(ReportScope, _super);
  222. function ReportScope(_a) {
  223. var model = _a.model, vjson = _a.vjson;
  224. return _super.call(this, { model: model, vjson: vjson }) || this;
  225. }
  226. ReportScope.prototype.onLoad = function () {
  227. this.reload();
  228. };
  229. ReportScope.prototype.reload = function () {
  230. var _this = this;
  231. // http://127.0.0.1:8095/api/com/galaxis/wms/report/Report@executeSum
  232. if (this.viewModel.get('has_sum')) {
  233. invokeServer('/report/Report@executeSum', {
  234. dataSource: this.report.dataSource,
  235. report_id: this.report_id,
  236. query: this.viewModel.get('query'),
  237. }).then(function (res) {
  238. if (!res.success) {
  239. showErrorDialog(res.msg);
  240. }
  241. else {
  242. window['system'].mergeViewModel(_this.viewModel, 'sum', res.data, false);
  243. }
  244. });
  245. }
  246. this.refs.grid1.reload();
  247. };
  248. return ReportScope;
  249. }(Scope));
  250. export { ReportScope };
  251. //# sourceMappingURL=Report.js.map