rpt_tpl_band.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. 'use strict'
  2. let bandTreeOprObj = {
  3. treeObj : null,
  4. currentNode: null,
  5. innerCounter: 1,
  6. reportCfg: null,
  7. canTrickEvent: false,
  8. iniTree: function(rptTpl) {
  9. var me = this;
  10. let bandList = rptTpl[JV.NODE_BAND_COLLECTION];
  11. me.buildTreeData(bandList);
  12. me.treeObj = $.fn.zTree.init($("#band_tree_reversed"), bandSetting, bandList);
  13. me.treeObj.expandAll(true);
  14. },
  15. copyBandList: function (isAllParent) {
  16. let me = this, rst = null;
  17. if (me.treeObj) {
  18. rst = [];
  19. let nodes = me.treeObj.getNodes();
  20. let private_copy_nodes = function (parentNode, item) {
  21. item[JV.PROP_ID] = parentNode[JV.PROP_ID];
  22. item[JV.BAND_PROP_NAME] = parentNode[JV.BAND_PROP_NAME];
  23. item[JV.BAND_PROP_STYLE] = parentNode[JV.BAND_PROP_STYLE];
  24. item[JV.BAND_PROP_CONTROL] = parentNode[JV.BAND_PROP_CONTROL];
  25. if (parentNode[JV.BAND_PROP_HEIGHT]) item[JV.BAND_PROP_HEIGHT] = parentNode[JV.BAND_PROP_HEIGHT];
  26. if (parentNode[JV.BAND_PROP_WIDTH]) item[JV.BAND_PROP_WIDTH] = parentNode[JV.BAND_PROP_WIDTH];
  27. item[JV.BAND_PROP_DISPLAY_TYPE] = parentNode[JV.BAND_PROP_DISPLAY_TYPE];
  28. item[JV.BAND_PROP_ALIGNMENT] = parentNode[JV.BAND_PROP_ALIGNMENT];
  29. item[JV.BAND_PROP_MERGE_BORDER] = parentNode[JV.BAND_PROP_MERGE_BORDER];
  30. if (isAllParent) item.isParent = true;
  31. if (parentNode[JV.BAND_PROP_SUB_BANDS]) {
  32. item.items = [];
  33. for (let subNode of parentNode[JV.BAND_PROP_SUB_BANDS]) {
  34. let subItem = {};
  35. private_copy_nodes(subNode, subItem);
  36. item.items.push(subItem);
  37. }
  38. }
  39. }
  40. for (let node of nodes) {
  41. let item = {};
  42. if (isAllParent) item.isParent = true;
  43. private_copy_nodes(node, item);
  44. rst.push(item);
  45. }
  46. }
  47. return rst;
  48. },
  49. buildTreeData: function(bandList){
  50. let rst = [], startIdx = 1;
  51. //zTreeHelper.createTree(result, setting, "rptTplTree", me);
  52. let private_setBandId = function (parentBand) {
  53. if (parentBand[JV.BAND_PROP_SUB_BANDS]) {
  54. for (let band of parentBand[JV.BAND_PROP_SUB_BANDS]) {
  55. band.ID = startIdx;
  56. band.ParentID = parentBand.ID;
  57. startIdx++;
  58. private_setBandId(band);
  59. }
  60. }
  61. }
  62. for (let band of bandList) {
  63. band.ID = startIdx;
  64. band.ParentID = -1;
  65. startIdx++;
  66. private_setBandId(band);
  67. }
  68. return rst;
  69. },
  70. getReportTplCfg: function() {
  71. let me = this, params = {};
  72. params.userId = userID;
  73. CommonAjax.postEx("report_tpl_api/getUserRptCfg", params, 20000, true, function(result){
  74. me.reportCfg = result;
  75. me.refreshRptCfgs();
  76. }, null, null
  77. );
  78. },
  79. refreshRptCfgs: function () {
  80. let me = this;
  81. if (me.reportCfg) {
  82. me.reportCfg.borderArr = [];
  83. for (let style of me.reportCfg.styles) {
  84. me.reportCfg.borderArr.push(style.ID);
  85. $("#borderStyles").append("<option value='" + style.ID + "'>" + style.CfgDispName + "</option>");
  86. }
  87. }
  88. let pf = $("#pageFrequency");
  89. pf.append("<option value='" + JV.PAGE_STATUS[0] + "'>每页</option>");
  90. pf.append("<option value='" + JV.PAGE_STATUS[1] + "'>首页</option>");
  91. pf.append("<option value='" + JV.PAGE_STATUS[2] + "'>尾页</option>");
  92. pf.append("<option value='" + JV.PAGE_STATUS[3] + "'>章首页</option>");
  93. pf.append("<option value='" + JV.PAGE_STATUS[4] + "'>章尾页</option>");
  94. pf.append("<option value='" + JV.PAGE_STATUS[5] + "'>分组</option>");
  95. pf.append("<option value='" + JV.PAGE_STATUS[6] + "'>交叉行尾页</option>");
  96. pf.append("<option value='" + JV.PAGE_STATUS[7] + "'>交叉列尾页</option>");
  97. let ba = $("#bandAlignment");
  98. ba.append("<option value='" + JV.LAYOUT[0] + "'>上</option>");
  99. ba.append("<option value='" + JV.LAYOUT[1] + "'>下</option>");
  100. ba.append("<option value='" + JV.LAYOUT[2] + "'>左</option>");
  101. ba.append("<option value='" + JV.LAYOUT[3] + "'>右</option>");
  102. ba.append("<option value='" + JV.LAYOUT[4] + "'>填充</option>");
  103. },
  104. createBandFromNode: function(node) {
  105. let me = this, rst = {};
  106. rst[JV.BAND_PROP_ALIGNMENT] = node[JV.BAND_PROP_ALIGNMENT];
  107. rst[JV.BAND_PROP_DISPLAY_TYPE] = node[JV.BAND_PROP_DISPLAY_TYPE];
  108. let posIdx = JV.LAYOUT.indexOf(node[JV.BAND_PROP_ALIGNMENT])
  109. switch(posIdx) {
  110. case 0:
  111. case 1:
  112. rst[JV.BAND_PROP_HEIGHT] = node[JV.BAND_PROP_HEIGHT];
  113. break;
  114. case 2:
  115. case 3:
  116. rst[JV.BAND_PROP_WIDTH] = node[JV.BAND_PROP_WIDTH];
  117. break;
  118. }
  119. rst[JV.PROP_NAME] = node[JV.PROP_NAME];
  120. rst[JV.PROP_CONTROL] = node[JV.PROP_CONTROL];
  121. rst[JV.PROP_STYLE] = node[JV.PROP_STYLE];
  122. if (node[JV.BAND_PROP_MERGE_BORDER] != undefined) {
  123. rst[JV.BAND_PROP_MERGE_BORDER] = node[JV.BAND_PROP_MERGE_BORDER];
  124. } else {
  125. rst[JV.BAND_PROP_MERGE_BORDER] = 'F';
  126. }
  127. if (node[JV.BAND_PROP_SUB_BANDS]) {
  128. rst[JV.BAND_PROP_SUB_BANDS] = [];
  129. for (let subNode of node[JV.BAND_PROP_SUB_BANDS]) {
  130. rst[JV.BAND_PROP_SUB_BANDS].push(me.createBandFromNode(subNode));
  131. }
  132. }
  133. return rst;
  134. },
  135. createDftBand: function () {
  136. let me = this, rst = {};
  137. rst[JV.BAND_PROP_ALIGNMENT] = 'Top';
  138. rst[JV.BAND_PROP_DISPLAY_TYPE] = 'EveryPage';
  139. rst[JV.BAND_PROP_HEIGHT] = '3';
  140. rst[JV.PROP_NAME] = 'newBand_' + me.innerCounter;
  141. me.innerCounter++;
  142. rst[JV.PROP_CONTROL] = 'Default';
  143. rst[JV.PROP_STYLE] = 'Default_None';
  144. rst[JV.BAND_PROP_MERGE_BORDER] = 'F';
  145. return rst;
  146. },
  147. addRootBand: function (rptTpl) {
  148. let me = this;
  149. if (rptTpl) {
  150. let newBand = me.createDftBand();
  151. let newNodes = [], isSilent = false;
  152. newNodes.push(newBand);
  153. if (me.treeObj) {
  154. me.treeObj.addNodes(null, -1, newNodes, isSilent);
  155. } else {
  156. me.treeObj = $.fn.zTree.init($("#band_tree_reversed"), bandSetting, newNodes);
  157. }
  158. }
  159. },
  160. addSubBand: function (rptTpl) {
  161. let me = this;
  162. if (rptTpl && me.currentNode != null) {
  163. let newBand = me.createDftBand();
  164. let newNodes = [], isSilent = false;
  165. newNodes.push(newBand);
  166. me.treeObj.addNodes(me.currentNode, -1, newNodes, isSilent);
  167. }
  168. },
  169. moveDownBand: function (rptTpl) {
  170. let me = bandTreeOprObj;
  171. if (rptTpl && me.currentNode && me.currentNode.getNextNode()) {
  172. let nextNode = me.currentNode.getNextNode();
  173. me.treeObj.moveNode(nextNode, me.currentNode, "next", true);
  174. }
  175. },
  176. moveUpBand: function (rptTpl) {
  177. let me = bandTreeOprObj;
  178. if (rptTpl && me.currentNode && me.currentNode.getPreNode()) {
  179. let preNode = me.currentNode.getPreNode();
  180. me.treeObj.moveNode(preNode, me.currentNode, "prev", true);
  181. }
  182. },
  183. onClick: function(event,treeId,treeNode) {
  184. let me = bandTreeOprObj;
  185. me.currentNode = treeNode;
  186. me.canTrickEvent = false;
  187. //then refresh the band tab properties
  188. //边框样式borderStyles
  189. $("#borderStyles ").get(0).selectedIndex = me.reportCfg.borderArr.indexOf(treeNode[JV.PROP_STYLE]);
  190. //边框合并
  191. $("#mergeBandBorder").get(0).checked = stringUtil.convertStrToBoolean(treeNode[JV.BAND_PROP_MERGE_BORDER]);
  192. //位置
  193. let posIdx = JV.LAYOUT.indexOf(treeNode[JV.BAND_PROP_ALIGNMENT])
  194. $("#bandAlignment").get(0).selectedIndex = posIdx;
  195. //高与宽
  196. me.setupWidthHeightByPosition(posIdx);
  197. //频率
  198. $("#pageFrequency").get(0).selectedIndex = JV.PAGE_STATUS.indexOf(treeNode[JV.BAND_PROP_DISPLAY_TYPE])
  199. //
  200. me.canTrickEvent = true;
  201. },
  202. setupWidthHeightByPosition: function (posIdx) {
  203. let me = this, treeNode = me.currentNode;
  204. switch(posIdx) {
  205. case 0:
  206. case 1:
  207. $("#bandHeight").get(0).disabled = false;
  208. $("#bandHeight").get(0).value = treeNode[JV.BAND_PROP_HEIGHT];
  209. $("#bandWidth").get(0).disabled = true;
  210. $("#bandWidth").get(0).value = "";
  211. break;
  212. case 2:
  213. case 3:
  214. $("#bandHeight").get(0).disabled = true;
  215. $("#bandHeight").get(0).value = "";
  216. $("#bandWidth").get(0).disabled = false;
  217. $("#bandWidth").get(0).value = treeNode[JV.BAND_PROP_WIDTH];
  218. break;
  219. default:
  220. $("#bandHeight").get(0).disabled = true;
  221. $("#bandHeight").get(0).value = "";
  222. $("#bandWidth").get(0).disabled = true;
  223. $("#bandWidth").get(0).value = "";
  224. break;
  225. }
  226. },
  227. bandStyleChange: function (dom) {
  228. let me = this;
  229. if (me.currentNode) {
  230. me.currentNode[JV.PROP_STYLE] = me.reportCfg.borderArr[dom.selectedIndex];
  231. }
  232. },
  233. bandAlignmentChange: function (dom) {
  234. let me = this;
  235. if (me.currentNode) {
  236. let posIdx = dom.selectedIndex;
  237. me.currentNode[JV.BAND_PROP_ALIGNMENT] = JV.LAYOUT[posIdx];
  238. me.setupWidthHeightByPosition(posIdx);
  239. }
  240. },
  241. bandHeightWidthChange: function (dom) {
  242. let me = this, treeNode = me.currentNode;
  243. if (me.currentNode) {
  244. let posIdx = $("#bandAlignment").get(0).selectedIndex;
  245. switch(posIdx) {
  246. case 0:
  247. case 1:
  248. treeNode[JV.BAND_PROP_HEIGHT] = dom.value;
  249. break;
  250. case 2:
  251. case 3:
  252. treeNode[JV.BAND_PROP_WIDTH] = dom.value;
  253. break;
  254. }
  255. }
  256. },
  257. bandShowFrequencyChange: function (dom) {
  258. let me = this;
  259. if (me.currentNode) {
  260. me.currentNode[JV.BAND_PROP_DISPLAY_TYPE] = JV.PAGE_STATUS[dom.selectedIndex];
  261. }
  262. },
  263. bandBorderMergeChange: function (dom) {
  264. let me = this;
  265. if (me.currentNode) {
  266. me.currentNode[JV.BAND_PROP_MERGE_BORDER] = dom.checked?'T':'F';
  267. }
  268. },
  269. extractBands: function (rptTpl) {
  270. let me = this;
  271. if (rptTpl) {
  272. let newBandList = [];
  273. for (let node of me.treeObj.getNodes()) {
  274. newBandList.push(me.createBandFromNode(node));
  275. }
  276. rptTpl[JV.NODE_BAND_COLLECTION] = newBandList;
  277. }
  278. }
  279. };