rpt_tpl_calculation.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**
  2. * Created by Tony on 2017/7/7.
  3. */
  4. let calculationTreeOprObj = {
  5. treeObj : null,
  6. extCodeTreeObj: null,
  7. currentNode: null,
  8. currentExtCodeNode: null,
  9. iniTree: function(rptTpl) {
  10. var me = this;
  11. let fieldMapList = me.buildTreeData(rptTpl);
  12. me.treeObj = $.fn.zTree.init($("#rpt_tpl_formulas"), caculationSetting, fieldMapList);
  13. me.treeObj.expandAll(true);
  14. $("#exprDetail")[0].style.display = "none";
  15. },
  16. iniExtCodeTpl: function () {
  17. let me = this, params = {};
  18. CommonAjax.postEx("report_tpl_api/getExtCodeTpl", params, 10000, true, function(result){
  19. me.extCodeTreeObj = $.fn.zTree.init($("#rpt_ext_code_tpl"), extCodeSetting, result);
  20. let nodes = me.extCodeTreeObj.getNodes();
  21. for (let node of nodes) {
  22. me.extCodeTreeObj.expandNode(node, true, false);
  23. }
  24. // me.extCodeTreeObj.expandAll(true);
  25. }, null, null
  26. );
  27. },
  28. buildRunType: function() {
  29. let et = $("#exprRunType");
  30. et.append(`<option value="${JV.RUN_TYPE_BEFORE_PAGING}">默认运行</option>`);
  31. et.append(`<option value="${JV.RUN_TYPE_BEFORE_OUTPUT}">每页实时运行</option>`);
  32. et.append(`<option value="${JV.RUN_TYPE_BEFORE_ANALYZING}">数据分析前运行</option>`);
  33. et.append(`<option value="${JV.RUN_TYPE_BEFORE_COMBINE}">合并单元格前事件</option>`);
  34. et.append(`<option value="${JV.RUN_TYPE_AFTER_COMBINE}">合并单元格后事件</option>`);
  35. et.append(`<option value="${JV.RUN_TYPE_BEFORE_GROUP_TEXT_OUT}">分组text输出前事件</option>`);
  36. et.append(`<option value="${JV.RUN_TYPE_RESET_CROSS_COLUMNS}">重设交叉表列数</option>`);
  37. },
  38. buildTreeData: function (rptTpl) {
  39. let me = this, rst = {"Name": "计算式", items: []};
  40. if (rptTpl[JV.NODE_FORMULAS]) {
  41. for (let cItem of rptTpl[JV.NODE_FORMULAS]) {
  42. let node = {};
  43. me.copyContent(cItem, node);
  44. node[JV.PROP_NAME] = cItem[JV.PROP_NAME];
  45. node[JV.PROP_RUN_TYPE] = cItem[JV.PROP_RUN_TYPE];
  46. node[JV.PROP_EXPRESSION] = cItem[JV.PROP_EXPRESSION];
  47. node["format"] = (cItem["format"])?cItem["format"]:"";
  48. rst.items.push(node);
  49. }
  50. }
  51. return rst;
  52. },
  53. copyContent: function(source, target) {
  54. target[JV.PROP_NAME] = source[JV.PROP_NAME];
  55. target[JV.PROP_RUN_TYPE] = source[JV.PROP_RUN_TYPE];
  56. target[JV.PROP_EXPRESSION] = source[JV.PROP_EXPRESSION];
  57. target["format"] = (source["format"])?source["format"]:"";
  58. },
  59. changeRunType: function (dom) {
  60. let me = calculationTreeOprObj;
  61. if (me.currentNode) {
  62. me.currentNode[JV.PROP_RUN_TYPE] = dom.value;
  63. }
  64. },
  65. setExtCodeTemplate: function (dom) {
  66. let me = calculationTreeOprObj;
  67. if (me.currentExtCodeNode && me.currentExtCodeNode["Template"] !== '') {
  68. $("#exprContent")[0].value = me.currentExtCodeNode["Template"];
  69. editor2.setValue($("#exprContent")[0].value);
  70. }
  71. },
  72. addExtCodeTemplate: function (dom) {
  73. let me = calculationTreeOprObj;
  74. if (me.currentExtCodeNode && me.currentExtCodeNode["Template"] !== '') {
  75. $("#exprContent")[0].value += me.currentExtCodeNode["Template"];
  76. editor2.setValue($("#exprContent")[0].value);
  77. }
  78. },
  79. changeFormat: function (dom) {
  80. let me = calculationTreeOprObj;
  81. if (me.currentNode) {
  82. me.currentNode["format"] = dom.value;
  83. }
  84. },
  85. changeExpression: function (dom) {
  86. let me = calculationTreeOprObj;
  87. if (me.currentNode) {
  88. me.currentNode[JV.PROP_EXPRESSION] = dom.value;
  89. }
  90. },
  91. onClick: function (event,treeId,treeNode) {
  92. let me = calculationTreeOprObj;
  93. me.currentNode = treeNode;
  94. if (treeNode.level === 0) {
  95. $("#exprDetail")[0].style.display = "none";
  96. } else {
  97. $("#exprDetail")[0].style.display = "";
  98. if (treeNode[JV.PROP_RUN_TYPE] === JV.RUN_TYPE_BEFORE_PAGING) {
  99. $("#exprRunType")[0].selectedIndex = 0;
  100. } else if (treeNode[JV.PROP_RUN_TYPE] === JV.RUN_TYPE_BEFORE_OUTPUT) {
  101. $("#exprRunType")[0].selectedIndex = 1;
  102. } else if (treeNode[JV.PROP_RUN_TYPE] === JV.RUN_TYPE_BEFORE_ANALYZING) {
  103. $("#exprRunType")[0].selectedIndex = 2;
  104. } else if (treeNode[JV.PROP_RUN_TYPE] === JV.RUN_TYPE_BEFORE_COMBINE) {
  105. $("#exprRunType")[0].selectedIndex = 3;
  106. } else if (treeNode[JV.PROP_RUN_TYPE] === JV.RUN_TYPE_AFTER_COMBINE) {
  107. $("#exprRunType")[0].selectedIndex = 4;
  108. } else if (treeNode[JV.PROP_RUN_TYPE] === JV.RUN_TYPE_BEFORE_GROUP_TEXT_OUT) {
  109. $("#exprRunType")[0].selectedIndex = 5;
  110. } else if (treeNode[JV.PROP_RUN_TYPE] === JV.RUN_TYPE_RESET_CROSS_COLUMNS) {
  111. $("#exprRunType")[0].selectedIndex = 6;
  112. } else {
  113. $("#exprRunType")[0].selectedIndex = 2;
  114. }
  115. $("#exprFormat")[0].value = (treeNode["format"])?treeNode["format"]:"";
  116. $("#exprContent")[0].value = treeNode[JV.PROP_EXPRESSION];
  117. editor2.setValue($("#exprContent")[0].value);
  118. }
  119. },
  120. onExtCodeTreeClick: function (event, treeId, treeNode) {
  121. let me = calculationTreeOprObj;
  122. me.currentExtCodeNode = treeNode;
  123. },
  124. onBeforeRemove: function(treeId, treeNode){
  125. let rst = false;
  126. if (treeNode.level > 0) {
  127. rst = confirm('请确认是否真的删除?');
  128. }
  129. return rst;
  130. },
  131. beforeRename: function(treeId, treeNode, newName, isCancel) {
  132. if (isCancel) {
  133. return true;
  134. }
  135. if (treeNode.level === 0) {
  136. return false;
  137. }
  138. return true;
  139. },
  140. onBeforeDrop: function (treeId, treeNodes, targetNode, moveType) {
  141. let rst = false;
  142. if (targetNode.level === 1 && (moveType === "next" || moveType === "prev")) {
  143. return true;
  144. }
  145. return rst;
  146. },
  147. addHoverDom: function(treeId, treeNode) {
  148. let me = calculationTreeOprObj, sObj = $("#" + treeNode.tId + "_span");
  149. if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length > 0 || treeNode.level > 0) {
  150. return;
  151. } else {
  152. let addStr = "<span class='button add' id='addBtn_" + treeNode.tId + "' title='新增' onfocus='this.blur();'></span>";
  153. sObj.after(addStr);
  154. let btn = $("#addBtn_"+treeNode.tId);
  155. btn.bind("click", function(){
  156. let newNodes = [], node = {};
  157. node[JV.PROP_NAME] = "新计算式";
  158. node[JV.PROP_RUN_TYPE] = JV.RUN_TYPE_BEFORE_PAGING;
  159. node[JV.PROP_EXPRESSION] = "";
  160. node["format"] = "";
  161. newNodes.push(node);
  162. me.treeObj.addNodes(treeNode, -1, newNodes, true);
  163. });
  164. }
  165. },
  166. removeHoverDom: function(treeId, treeNode) {
  167. $("#addBtn_"+treeNode.tId).unbind().remove();
  168. },
  169. extractCalculation: function (rptTpl) {
  170. let me = this, newCaclList = [];
  171. let topNode = me.treeObj.getNodes()[0];
  172. for (let node of topNode.items) {
  173. let item = {};
  174. me.copyContent(node, item);
  175. newCaclList.push(item);
  176. }
  177. rptTpl[JV.NODE_FORMULAS] = newCaclList;
  178. }
  179. }
  180. $(document).ready(function () {
  181. editor2.on('change', function () {
  182. let me = calculationTreeOprObj;
  183. if (me.currentNode) {
  184. me.currentNode[JV.PROP_EXPRESSION] = editor2.getValue();
  185. }
  186. });
  187. });