rpt_tpl_field_map.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /**
  2. * Created by Tony on 2017/6/7.
  3. * 各种指标处理对象
  4. * 包括:可映射指标、报表已选指标集合、离散独立指标和参数
  5. */
  6. "use strict";
  7. let fieldMapTreeOprObj = {
  8. treeObj: null,
  9. currentNode: null,
  10. dataTypeDef: [
  11. "string",
  12. "int32",
  13. "int64",
  14. "double",
  15. "currency",
  16. "date",
  17. "image",
  18. "object",
  19. ],
  20. iniTree: function (rptTpl) {
  21. var me = this;
  22. let fieldMapList = me.buildTreeData(rptTpl);
  23. me.treeObj = $.fn.zTree.init(
  24. $("#field_map_tree_reversed"),
  25. fieldMapSetting,
  26. fieldMapList
  27. );
  28. me.treeObj.expandAll(true);
  29. let topNodes = me.treeObj.getNodes();
  30. for (let node of topNodes) {
  31. me.treeObj.setChkDisabled(node, true);
  32. }
  33. },
  34. buildTreeData: function (rptTpl) {
  35. let rst = [];
  36. let private_setSubFields = function (parent, fieldList) {
  37. for (let field of fieldList) {
  38. if (field[JV.PROP_IS_ID]) {
  39. field.checked = true;
  40. }
  41. field.Title = "ID: " + field[JV.PROP_ID];
  42. parent.items.push(field);
  43. }
  44. };
  45. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS]) {
  46. rst.push({ Name: JV.NODE_DISCRETE_FIELDS, items: [], isParent: true });
  47. private_setSubFields(
  48. rst[rst.length - 1],
  49. rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DISCRETE_FIELDS]
  50. );
  51. }
  52. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS]) {
  53. rst.push({ Name: JV.NODE_MASTER_FIELDS, items: [], isParent: true });
  54. private_setSubFields(
  55. rst[rst.length - 1],
  56. rptTpl[JV.NODE_FIELD_MAP][JV.NODE_MASTER_FIELDS]
  57. );
  58. }
  59. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  60. rst.push({ Name: JV.NODE_DETAIL_FIELDS, items: [], isParent: true });
  61. private_setSubFields(
  62. rst[rst.length - 1],
  63. rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]
  64. );
  65. }
  66. return rst;
  67. },
  68. copySelectedFieldList: function () {
  69. let me = fieldMapTreeOprObj,
  70. rst = [];
  71. if (me.treeObj) {
  72. let nodes = me.treeObj.getNodes();
  73. for (let node of nodes) {
  74. let item = { Name: node.Name, items: [], isParent: true, Title: "" };
  75. if (node.items) {
  76. for (let subNode of node.items) {
  77. let subItem = me.createMapFieldByNode(subNode);
  78. item.items.push(subItem);
  79. }
  80. }
  81. rst.push(item);
  82. }
  83. }
  84. return rst;
  85. },
  86. onClick: function (event, treeId, treeNode) {
  87. let me = fieldMapTreeOprObj;
  88. me.currentNode = treeNode;
  89. //then refresh the field map tab properties
  90. //数据类型
  91. // switch (me.dataTypeDef.indexOf(treeNode[JV.PROP_DATA_TYPE])) {
  92. // case 0:
  93. // $("#fieldDataTypeSelection").get(0).selectedIndex = 0;
  94. // break;
  95. // case 1:
  96. // case 2:
  97. // case 3:
  98. // case 4:
  99. // $("#fieldDataTypeSelection").get(0).selectedIndex = 1;
  100. // break;
  101. // case 5:
  102. // $("#fieldDataTypeSelection").get(0).selectedIndex = 2;
  103. // break;
  104. // case 6:
  105. // $("#fieldDataTypeSelection").get(0).selectedIndex = 3;
  106. // break;
  107. // default:
  108. // $("#fieldDataTypeSelection").get(0).selectedIndex = 0;
  109. // break;
  110. // }
  111. //映射指标
  112. },
  113. onBeforeRemove: function (treeId, treeNode) {
  114. if (treeNode.level === 0) {
  115. return false;
  116. }
  117. return true;
  118. },
  119. beforeRename: function (treeId, treeNode, newName, isCancel) {
  120. if (isCancel) {
  121. return true;
  122. }
  123. if (treeNode.level === 0) {
  124. return false;
  125. }
  126. return true;
  127. },
  128. onBeforeDrop: function (treeId, treeNodes, targetNode, moveType) {
  129. let rst = true;
  130. if (
  131. treeId === "selectable_field_tree_reversed" ||
  132. targetNode.level === 0 ||
  133. moveType === "inner"
  134. ) {
  135. rst = false;
  136. } else {
  137. //
  138. }
  139. return rst;
  140. },
  141. onRemove: function (e, treeId, treeNode) {
  142. //
  143. },
  144. onRename: function (e, treeId, treeNode, isCancel) {
  145. //
  146. },
  147. extractFieldMaps: function (rptTpl) {
  148. let me = this;
  149. for (let rootNode of me.treeObj.getNodes()) {
  150. rptTpl[JV.NODE_FIELD_MAP][rootNode.Name] = [];
  151. let idSeq = 1;
  152. for (let mappingFieldNode of rootNode.items) {
  153. let item = me.createMapFieldByNode(mappingFieldNode);
  154. if (mappingFieldNode.checked) {
  155. item[JV.PROP_IS_ID] = true;
  156. item[JV.PROP_ID_SEQ] = idSeq;
  157. idSeq++;
  158. }
  159. rptTpl[JV.NODE_FIELD_MAP][rootNode.Name].push(item);
  160. }
  161. }
  162. },
  163. createMapFieldByNode: function (node) {
  164. let rst = {},
  165. me = this;
  166. me.copyMapFieldNode(node, rst);
  167. return rst;
  168. },
  169. copyMapFieldNode: function (src, dest) {
  170. dest[JV.PROP_ID] = src[JV.PROP_ID];
  171. dest[JV.PROP_NAME] = src[JV.PROP_NAME];
  172. dest[JV.PROP_DATA_TYPE] = src[JV.PROP_DATA_TYPE];
  173. dest.mapExpression = src.mapExpression;
  174. dest.adHocFormula = src.adHocFormula;
  175. dest.descr = src.descr;
  176. dest.Title = "ID: " + src[JV.PROP_ID];
  177. if (src.Precision) {
  178. dest.Precision = src.Precision;
  179. }
  180. },
  181. refreshFields: function () {
  182. let me = this;
  183. if (me.treeObj && selectableFiledTreeOprObj.treeObj) {
  184. let selectableFields = [];
  185. let private_get_all_selectable_fields = function (fieldNode) {
  186. if (fieldNode.isParent) {
  187. for (let dtlSF of fieldNode.items) {
  188. private_get_all_selectable_fields(dtlSF);
  189. }
  190. } else {
  191. selectableFields.push(fieldNode);
  192. }
  193. };
  194. let selectableFieldNodes = selectableFiledTreeOprObj.treeObj.getNodes();
  195. for (let subFn of selectableFieldNodes) {
  196. private_get_all_selectable_fields(subFn);
  197. }
  198. let topNodes = me.treeObj.getNodes();
  199. for (let node of topNodes) {
  200. if (node.items && node.items.length > 0) {
  201. for (let dtl of node.items) {
  202. for (let sf of selectableFields) {
  203. if (sf.ID === dtl.ID) {
  204. me.copyMapFieldNode(sf, dtl);
  205. break;
  206. }
  207. }
  208. }
  209. }
  210. }
  211. }
  212. },
  213. };
  214. const setNodeFieldID = (data) => {
  215. if (data.items && data.items.length > 0) {
  216. data.items.forEach((i) => {
  217. setNodeFieldID(i);
  218. });
  219. } else {
  220. data.Name = data.Name + "(" + data.ID + ")";
  221. }
  222. };
  223. let selectableFiledTreeOprObj = {
  224. treeObj: null,
  225. currentNode: null,
  226. iniTree: function () {
  227. let me = this,
  228. params = {};
  229. params.userId = userID;
  230. CommonAjax.postEx(
  231. "report_tpl_api/getMappingFields",
  232. params,
  233. 20000,
  234. true,
  235. function (result) {
  236. let showRst = [];
  237. for (let item of result) {
  238. me.decorateMappingFieldList(item);
  239. if (item.items.length > 0) {
  240. setNodeFieldID(item);
  241. showRst.push(item);
  242. }
  243. }
  244. me.treeObj = $.fn.zTree.init(
  245. $("#selectable_field_tree_reversed"),
  246. selectableFieldSetting,
  247. showRst
  248. );
  249. let nodes = me.treeObj.getNodes();
  250. for (let node of nodes) {
  251. me.treeObj.expandNode(node, true, false);
  252. }
  253. // me.treeObj.expandAll(true);
  254. showRst = null;
  255. },
  256. null,
  257. null
  258. );
  259. },
  260. decorateMappingFieldList: function (rawMappingField) {
  261. let me = this;
  262. if (rawMappingField.items && rawMappingField.items.length > 0) {
  263. for (const subMappingField of rawMappingField.items) {
  264. me.decorateMappingFieldList(subMappingField);
  265. }
  266. } else {
  267. rawMappingField.Title = "ID: " + rawMappingField[JV.PROP_ID];
  268. }
  269. },
  270. onClick: function (event, treeId, treeNode) {
  271. let me = fieldMapTreeOprObj;
  272. me.currentNode = treeNode;
  273. },
  274. onBeforeDrag: function (treeId, treeNodes) {
  275. let rst = true;
  276. for (let node of treeNodes) {
  277. if (node.level === 0) {
  278. rst = false;
  279. break;
  280. }
  281. }
  282. return rst;
  283. },
  284. onBeforeDrop: function (treeId, treeNodes, targetNode, moveType) {
  285. let rst = true;
  286. if (treeId === "field_map_tree_reversed") {
  287. if (
  288. (targetNode.level === 0 && moveType !== "inner") ||
  289. (targetNode.level > 0 && moveType === "inner")
  290. ) {
  291. rst = false;
  292. }
  293. } else {
  294. rst = false;
  295. }
  296. return rst;
  297. },
  298. addDiyDom: function (treeId, treeNode) {
  299. if (treeNode.level > 0) {
  300. let aObj = $("#" + treeNode.tId + "_a");
  301. if ($("#diyBtn_" + treeNode.ID).length > 0) return;
  302. let editStr = "<span>&nbsp(" + treeNode.DataType + ")</span>";
  303. aObj.append(editStr);
  304. let btn = $("#diyBtn_" + treeNode.ID);
  305. if (btn)
  306. btn.bind("click", function () {
  307. alert("diy Button for " + treeNode.name);
  308. });
  309. }
  310. },
  311. };
  312. let discreteFieldParamTreeOprObj = {
  313. treeObj: null,
  314. currentNode: null,
  315. local_idx: 12000,
  316. iniTree: function (rptTpl) {
  317. var me = this;
  318. let fieldMapList = me.buildTreeData(rptTpl);
  319. me.treeObj = $.fn.zTree.init(
  320. $("#tpl_discrete_fields_params_reversed"),
  321. discreteFieldParamSetting,
  322. fieldMapList
  323. );
  324. me.treeObj.expandAll(true);
  325. },
  326. buildTreeData: function (rptTpl) {
  327. let me = this,
  328. rst = [];
  329. let disFieldNode = {
  330. Name: JV.NODE_NO_MAPPING_FIELDS,
  331. items: [],
  332. isParent: true,
  333. Title: "",
  334. };
  335. let disParamNode = {
  336. Name: JV.NODE_DISCRETE_PARAMS,
  337. items: [],
  338. isParent: true,
  339. Title: "",
  340. };
  341. rst.push(disFieldNode);
  342. rst.push(disParamNode);
  343. if (
  344. rptTpl[JV.NODE_NO_MAPPING_FIELDS] &&
  345. rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0
  346. ) {
  347. for (let df of rptTpl[JV.NODE_NO_MAPPING_FIELDS]) {
  348. let node = {};
  349. node[JV.PROP_ID] = df[JV.PROP_ID];
  350. node[JV.PROP_FIELD_ID] = df[JV.PROP_ID];
  351. node[JV.PROP_NAME] = df[JV.PROP_NAME];
  352. node[JV.PROP_DATA_TYPE] = df[JV.PROP_DATA_TYPE];
  353. node.Title = "ID: " + df[JV.PROP_ID];
  354. disFieldNode.items.push(node);
  355. if (parseInt(df[JV.PROP_ID]) >= me.local_idx)
  356. me.local_idx = parseInt(df[JV.PROP_ID]) + 1;
  357. }
  358. }
  359. if (rptTpl[JV.NODE_DISCRETE_PARAMS]) {
  360. for (let dp of rptTpl[JV.NODE_DISCRETE_PARAMS]) {
  361. let node = {};
  362. node[JV.PROP_ID] = dp[JV.PROP_ID];
  363. node[JV.PROP_PARAM_ID] = dp[JV.PROP_ID];
  364. node[JV.PROP_NAME] = dp[JV.PROP_NAME];
  365. node[JV.PROP_DATA_TYPE] = dp[JV.PROP_DATA_TYPE];
  366. node[JV.PROP_DFT_VALUE] = dp[JV.PROP_DFT_VALUE];
  367. node.Title = "ID: " + dp[JV.PROP_ID];
  368. disParamNode.items.push(node);
  369. if (parseInt(dp[JV.PROP_ID]) >= me.local_idx)
  370. me.local_idx = parseInt(dp[JV.PROP_ID]) + 1;
  371. }
  372. }
  373. return rst;
  374. },
  375. getAndModifyLocalIdx: function () {
  376. let me = discreteFieldParamTreeOprObj,
  377. rst = me.local_idx;
  378. me.local_idx++;
  379. return rst;
  380. },
  381. addHoverDom: function (treeId, treeNode) {
  382. let me = discreteFieldParamTreeOprObj,
  383. sObj = $("#" + treeNode.tId + "_span");
  384. if (treeNode.level > 0 || $("#addBtn_" + treeNode.tId).length > 0) return;
  385. let addStr =
  386. "<span class='button add' id='addBtn_" +
  387. treeNode.tId +
  388. "' title='新增子节点' onfocus='this.blur();'></span>";
  389. sObj.after(addStr);
  390. let btn = $("#addBtn_" + treeNode.tId);
  391. if (btn)
  392. btn.bind("click", function () {
  393. if (treeNode[JV.PROP_NAME] === JV.NODE_NO_MAPPING_FIELDS) {
  394. let field = me.private_setup_dummy_discrete_field_node();
  395. let newNodes = [field];
  396. me.treeObj.addNodes(treeNode, -1, newNodes, true);
  397. } else if (treeNode[JV.PROP_NAME] === JV.NODE_DISCRETE_PARAMS) {
  398. let param = me.private_setup_dummy_discrete_param_node();
  399. let newNodes = [param];
  400. me.treeObj.addNodes(treeNode, -1, newNodes, true);
  401. }
  402. });
  403. },
  404. private_setup_dummy_discrete_field_node: function () {
  405. let me = discreteFieldParamTreeOprObj,
  406. rst = {};
  407. rst[JV.PROP_ID] = me.getAndModifyLocalIdx();
  408. rst[JV.PROP_NAME] = "新离散指标";
  409. rst[JV.PROP_DATA_TYPE] = "string";
  410. rst.descr = "";
  411. rst.Title = "ID: " + rst[JV.PROP_ID];
  412. return rst;
  413. },
  414. private_setup_dummy_discrete_param_node: function () {
  415. let me = discreteFieldParamTreeOprObj,
  416. rst = {};
  417. rst[JV.PROP_ID] = me.getAndModifyLocalIdx();
  418. rst[JV.PROP_NAME] = "新离散参数";
  419. rst[JV.PROP_DATA_TYPE] = "string";
  420. rst[JV.PROP_DFT_VALUE] = "";
  421. rst.Title = "ID: " + rst[JV.PROP_ID];
  422. return rst;
  423. },
  424. removeHoverDom: function (treeId, treeNode) {
  425. $("#addBtn_" + treeNode.tId)
  426. .unbind()
  427. .remove();
  428. },
  429. onBeforeRemove: function (treeId, treeNode) {
  430. let rst = true;
  431. if (treeNode.isParent) {
  432. rst = false;
  433. }
  434. return rst;
  435. },
  436. beforeRename: function (treeId, treeNode, newName, isCancel) {
  437. let rst = true;
  438. if (treeNode.isParent && !isCancel) {
  439. rst = false;
  440. }
  441. return rst;
  442. },
  443. onBeforeDrag: function (treeId, treeNodes) {
  444. let rst = true;
  445. for (let node of treeNodes) {
  446. if (node.level === 0) {
  447. rst = false;
  448. break;
  449. }
  450. }
  451. return rst;
  452. },
  453. onBeforeDrop: function (treeId, treeNodes, targetNode, moveType) {
  454. // let rst = false;
  455. // if (targetNode.tId && targetNode.tId.indexOf("tpl_data_info_reversed") >= 0 && (!(targetNode.isParent && moveType !== 'inner')) ) {
  456. // if (targetNode.level === 0) {
  457. // if (targetNode.Name !== "离散信息" && moveType === 'inner') {
  458. // rst = true;
  459. // }
  460. // } else {
  461. // let parentNode = targetNode.getParentNode();
  462. // if (parentNode.Name === "离散信息") {
  463. // if (targetNode.Name === "Fields") {
  464. // rst = true;
  465. // }
  466. // } else if (parentNode.Name === "Fields") {
  467. // rst = true;
  468. // }
  469. // }
  470. // }
  471. // return rst;
  472. },
  473. onRemove: function () {
  474. //
  475. },
  476. onRename: function () {
  477. //
  478. },
  479. extractFieldMaps: function (rptTpl) {
  480. let me = this;
  481. for (let rootNode of me.treeObj.getNodes()) {
  482. if (rootNode[JV.PROP_NAME] === JV.NODE_NO_MAPPING_FIELDS) {
  483. rptTpl[JV.NODE_NO_MAPPING_FIELDS] = [];
  484. for (let fNode of rootNode.items) {
  485. rptTpl[JV.NODE_NO_MAPPING_FIELDS].push(
  486. me.createDiscreteFieldByNode(fNode)
  487. );
  488. }
  489. } else if (rootNode[JV.PROP_NAME] === JV.NODE_DISCRETE_PARAMS) {
  490. rptTpl[JV.NODE_DISCRETE_PARAMS] = [];
  491. for (let pNode of rootNode.items) {
  492. rptTpl[JV.NODE_DISCRETE_PARAMS].push(
  493. me.createDiscreteParamByNode(pNode)
  494. );
  495. }
  496. }
  497. }
  498. },
  499. createDiscreteFieldByNode: function (node) {
  500. let rst = {};
  501. rst[JV.PROP_ID] = node[JV.PROP_ID];
  502. rst[JV.PROP_NAME] = node[JV.PROP_NAME];
  503. rst[JV.PROP_DATA_TYPE] = node[JV.PROP_DATA_TYPE];
  504. rst.descr = node.descr;
  505. return rst;
  506. },
  507. createDiscreteParamByNode: function (node) {
  508. let rst = {};
  509. rst[JV.PROP_ID] = node[JV.PROP_ID];
  510. rst[JV.PROP_NAME] = node[JV.PROP_NAME];
  511. rst[JV.PROP_DATA_TYPE] = node[JV.PROP_DATA_TYPE];
  512. rst[JV.PROP_DFT_VALUE] = node[JV.PROP_DFT_VALUE];
  513. return rst;
  514. },
  515. };