rpt_tpl_main.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681
  1. "use strict";
  2. const IDMark_Switch = "_switch",
  3. IDMark_Icon = "_ico",
  4. IDMark_Span = "_span",
  5. IDMark_Input = "_input",
  6. IDMark_Check = "_check",
  7. IDMark_Edit = "_edit",
  8. IDMark_Remove = "_remove",
  9. IDMark_Ul = "_ul",
  10. IDMark_A = "_a",
  11. //以上的常量是在查找zTree默认生成的dom对象时用到(tID + 后缀)
  12. NODE_LEVEL_COMPILATION_NEW = 1,
  13. NODE_LEVEL_USER = 0;
  14. // 工程类型枚举值
  15. const valuationSelectorMap = {
  16. valuationSelector_NA: "N/A",
  17. valuationSelector_suggestion: "建议估算",
  18. valuationSelector_feasibility: "可行性估算",
  19. valuationSelector_rough: "概算",
  20. valuationSelector_bill: "预算",
  21. valuationSelector_three_bill_budget: "三级清单预算",
  22. valuationSelector_ration: "清单预算",
  23. valuationSelector_changeBudget: "变更预算",
  24. valuationSelector_settlement: "结算",
  25. };
  26. let rptTplObj = {
  27. iniPage: function () {
  28. zTreeOprObj.getCompilationList();
  29. rpt_tpl_cfg_helper.getReportTplCfg();
  30. selectableFiledTreeOprObj.iniTree();
  31. preview_util.drawBorder($("#tplCanvas")[0]);
  32. calculationTreeOprObj.buildRunType();
  33. preHandleObj.buildTypeData();
  34. calculationTreeOprObj.iniExtCodeTpl();
  35. },
  36. };
  37. let zTreeOprObj = {
  38. treeObj: null,
  39. currentNode: null,
  40. moveSrcTopNode: null,
  41. dupTplIds: null,
  42. hasRefreshedDupRefIds: false,
  43. getCompilationList: function () {
  44. let me = zTreeOprObj,
  45. params = {};
  46. CommonAjax.postEx(
  47. "report_tpl_api/getCompilationList",
  48. params,
  49. 20000,
  50. true,
  51. function (result) {
  52. //console.log(result);
  53. for (let item of result) {
  54. // if (item.is_release) {
  55. $("#compilations").append(
  56. "<option value='" + item._id + "'>" + item.name + "</option>"
  57. );
  58. // }
  59. }
  60. // me.getReportTemplateTree($("#compilations").get(0));
  61. me.getReportTemplateTreeEx($("#compilations").get(0));
  62. },
  63. null,
  64. null
  65. );
  66. },
  67. refreshNodes: function () {
  68. let me = this;
  69. let private_setupIsParent = function (node) {
  70. // if (node.nodeType === RT.NodeType.NODE || node.level === 0) {
  71. if (
  72. node.nodeType === RT.NodeType.NODE ||
  73. node.level <= NODE_LEVEL_COMPILATION_NEW
  74. ) {
  75. node.isParent = true;
  76. } else {
  77. node.isParent = false;
  78. }
  79. if (node.items && node.items.length) {
  80. for (let i = 0; i < node.items.length; i++) {
  81. private_setupIsParent(node.items[i]);
  82. }
  83. }
  84. };
  85. let topNodes = me.treeObj.getNodes();
  86. for (let i = 0; i < topNodes.length; i++) {
  87. private_setupIsParent(topNodes[i]);
  88. }
  89. me.treeObj.refresh();
  90. },
  91. removeTreeRootNode: function (rawNode, isAsync, callback, failCallback) {
  92. let params = {};
  93. params.compilationId = rawNode.compilationId;
  94. params.engineerId = rawNode.engineerId;
  95. params.userId = rawNode.userId;
  96. params.isPhysically = true;
  97. CommonAjax.postEx(
  98. "report_tpl_api/removeTreeRootNode",
  99. params,
  100. 5000,
  101. isAsync,
  102. callback,
  103. failCallback,
  104. null
  105. );
  106. },
  107. copyReportTemplate: function (orgID, newID, isAsync, callback, failCallback) {
  108. let params = {};
  109. params.orgRptTplId = orgID;
  110. params.newRptTplId = newID;
  111. CommonAjax.postEx(
  112. "report_tpl_api/copyRptTpl",
  113. params,
  114. 5000,
  115. isAsync,
  116. callback,
  117. failCallback,
  118. null
  119. );
  120. },
  121. updateTreeRootNode: function (rawNode, isAsync, callback, failCallback) {
  122. let params = {};
  123. params.doc = rawNode;
  124. CommonAjax.postEx(
  125. "report_tpl_api/updateTreeRootNode",
  126. params,
  127. 5000,
  128. isAsync,
  129. callback,
  130. failCallback,
  131. null
  132. );
  133. },
  134. partialUpdateTreeNode: function (
  135. rawNode,
  136. pathArray,
  137. nodeArray,
  138. isAsync,
  139. callback,
  140. failCallback
  141. ) {
  142. // 这个是局部刷新,原理是根据topNodeId找到后台的topNode,根据路径(有多个路径,可以实现多个子节点同时刷新)来替换(nodeArray里的)后台数据库的相关节点
  143. // 这里需要一个调整,就是新增目录及模板需要加给后缀(new(Date)).getTime() ,以保证不重叠(真重叠了算倒霉)
  144. // path描述:{ operation_type: '', // 操作类型:‘update’ ‘add’、‘delete’
  145. // node_path: [], // 节点路径:如:['02.广东', '03.增城北绕线项目定制报表'],表示Top节点的items下的那个‘02.广东’子节点(要full scan)的items下的 ‘03.增城北绕线项目定制报表’子节点
  146. // }
  147. // nodeArray: 与pathArray一一对应
  148. //
  149. let params = {};
  150. params.compilationId = rawNode.compilationId;
  151. params.engineerId = rawNode.engineerId;
  152. params.userId = rawNode.userId;
  153. params.pathArray = pathArray;
  154. params.nodeArray = nodeArray;
  155. CommonAjax.postEx(
  156. "report_tpl_api/partialUpdateTreeNode",
  157. params,
  158. 5000,
  159. isAsync,
  160. callback,
  161. failCallback,
  162. null
  163. );
  164. },
  165. updateTopNodeName: function (topNode, isAsync, callback, failCallback) {
  166. let params = {};
  167. params.compilationId = topNode.compilationId;
  168. params.engineerId = topNode.engineerId;
  169. params.userId = topNode.userId;
  170. params.nodeName = topNode.name;
  171. CommonAjax.postEx(
  172. "report_tpl_api/updateTopNodeName",
  173. params,
  174. 5000,
  175. isAsync,
  176. callback,
  177. failCallback,
  178. null
  179. );
  180. },
  181. updateSubNode: function (topNode, subNode, isAsync, callback, failCallback) {
  182. let params = {};
  183. params.compilationId = topNode.compilationId;
  184. params.engineerId = topNode.engineerId;
  185. params.userId = topNode.userId;
  186. params.subNode = subNode;
  187. CommonAjax.postEx(
  188. "report_tpl_api/updateSubLevelOneNode",
  189. params,
  190. 5000,
  191. isAsync,
  192. callback,
  193. failCallback,
  194. null
  195. );
  196. },
  197. createIniNode: function () {
  198. return {
  199. nodeType: RT.NodeType.TEMPLATE,
  200. refId: -1,
  201. name: "",
  202. ID: -1,
  203. items: null,
  204. };
  205. },
  206. buildRootNodeDoc: function (topNode, excludeNode) {
  207. let me = this,
  208. rst = null;
  209. if (topNode) {
  210. rst = {
  211. compilationId: topNode.compilationId,
  212. engineerId: topNode.engineerId,
  213. userId: topNode.userId,
  214. properties: topNode.properties,
  215. released: true,
  216. isDeleted: topNode.isDeleted,
  217. items: me.private_build_items(topNode.items, excludeNode),
  218. name: topNode.name,
  219. UUID: topNode.UUID,
  220. };
  221. }
  222. return rst;
  223. },
  224. getNodePath: function (node, includeCurrentNode) {
  225. const rst = [];
  226. if (includeCurrentNode && node.level > 1) {
  227. // 备注:因结构有所变化,这里level判断要>1 (多了一层)
  228. rst.push(node.name);
  229. }
  230. let parentNode = node.getParentNode();
  231. while (parentNode && parentNode.level > 0) {
  232. //顶节点是dummy的
  233. rst.unshift(parentNode.name);
  234. parentNode = parentNode.getParentNode();
  235. if (
  236. parentNode === null ||
  237. parentNode === undefined ||
  238. parentNode.level === 0
  239. ) {
  240. rst.splice(0, 1); // 删除头节点(后台不需要)
  241. }
  242. }
  243. return rst;
  244. },
  245. buildSubRootNodeDoc: function (subNode) {
  246. let me = this,
  247. rst = null;
  248. if (subNode) {
  249. let isReleased = false;
  250. if (subNode.nodeType === RT.NodeType.TEMPLATE) {
  251. isReleased = subNode.checked;
  252. }
  253. rst = {
  254. nodeType: subNode.nodeType,
  255. refId: subNode.refId,
  256. ID: subNode.ID,
  257. released: isReleased,
  258. items: me.private_build_items(subNode.items, null),
  259. name: subNode.name,
  260. UUID: subNode.UUID,
  261. };
  262. if (subNode.hasOwnProperty("flags")) {
  263. rst.flags = subNode.flags;
  264. }
  265. }
  266. return rst;
  267. },
  268. generateRandomString() {
  269. const charset =
  270. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  271. let randomString = "";
  272. for (let i = 0; i < 10; i++) {
  273. const randomIndex = Math.floor(Math.random() * charset.length);
  274. randomString += charset[randomIndex];
  275. }
  276. return randomString;
  277. },
  278. private_build_items: function (items, excludeNode) {
  279. let me = this,
  280. itemRst = null;
  281. if (items && items.length > 0) {
  282. itemRst = [];
  283. for (let item of items) {
  284. if (item !== excludeNode) {
  285. let isReleased = false;
  286. if (item.nodeType === RT.NodeType.TEMPLATE) {
  287. isReleased = item.checked;
  288. }
  289. let ir = {};
  290. ir.nodeType = item.nodeType;
  291. ir.refId = item.refId;
  292. ir.name = item.name;
  293. ir.ID = item.ID;
  294. ir.released = isReleased;
  295. ir.UUID =
  296. item.UUID ||
  297. `${new Date().getTime()}_${this.generateRandomString()}`;
  298. if (item.hasOwnProperty("flags")) {
  299. ir.flags = item.flags;
  300. }
  301. // 同类表(associateRefIds)处理
  302. if (item.hasOwnProperty("associateRefIds")) {
  303. ir.associateRefIds = item.associateRefIds;
  304. }
  305. ir.items = me.private_build_items(item.items);
  306. itemRst.push(ir);
  307. }
  308. }
  309. }
  310. return itemRst;
  311. },
  312. addHoverDom: function (treeId, treeNode) {
  313. let me = zTreeOprObj,
  314. sObj = $("#" + treeNode.tId + "_span");
  315. if (
  316. treeNode.editNameFlag ||
  317. $("#addBtn_" + treeNode.tId).length > 0 ||
  318. treeNode.nodeType === RT.NodeType.TEMPLATE
  319. )
  320. return;
  321. if (treeNode.level === 0) {
  322. let addStr =
  323. "<span class='button star' id='addBtn_" +
  324. treeNode.tId +
  325. "' title='新增编办类型' onfocus='this.blur();'></span>";
  326. sObj.after(addStr);
  327. let btn = $("#addBtn_" + treeNode.tId);
  328. if (btn)
  329. btn.bind("click", function () {
  330. let rawNode = me.createIniComilationNode();
  331. if (!me.chkIfDupCompilationNode(rawNode, treeNode)) {
  332. rawNode.userId = treeNode.userId;
  333. me.addNewNodeEx(
  334. rawNode,
  335. function (rst) {
  336. if (rst) {
  337. let newNodes = [],
  338. isSilent = false;
  339. rawNode.isParent = true;
  340. newNodes.push(rawNode);
  341. if (treeNode.items && treeNode.items.length > 0) {
  342. let insertIdx = -1;
  343. for (let i = 0; i < treeNode.items.length; i++) {
  344. if (
  345. treeNode.items[i].compilationId ===
  346. rawNode.compilationId
  347. ) {
  348. if (treeNode.items[i].engineerId > rawNode.engineerId) {
  349. insertIdx = i;
  350. break;
  351. }
  352. }
  353. }
  354. me.treeObj.addNodes(
  355. treeNode,
  356. insertIdx,
  357. newNodes,
  358. isSilent
  359. );
  360. } else {
  361. me.treeObj.addNodes(treeNode, 0, newNodes, isSilent);
  362. }
  363. } else {
  364. alert("后台创建失败,请确认是否有重复类型跟节点!");
  365. }
  366. },
  367. null
  368. );
  369. } else {
  370. alert("有重复编办!");
  371. }
  372. });
  373. } else {
  374. let addStr =
  375. "<span class='button add' id='addBtn_" +
  376. treeNode.tId +
  377. "' title='新增子目录' onfocus='this.blur();'></span>";
  378. sObj.after(addStr);
  379. let btn = $("#addBtn_" + treeNode.tId);
  380. if (btn)
  381. btn.bind("click", function () {
  382. me.getNewNodeID(1, function (newNodeID) {
  383. let rawNode = me.createIniNode();
  384. rawNode.nodeType = RT.NodeType.NODE;
  385. rawNode.name = "新增子节点" + new Date().getTime();
  386. rawNode.ID = newNodeID;
  387. rawNode.isParent = true;
  388. rawNode.items = [];
  389. let newNodes = [],
  390. isSilent = false;
  391. newNodes.push(rawNode);
  392. if (me.treeObj) {
  393. let insertIdx = -1;
  394. if (treeNode.items && treeNode.items.length > 0) {
  395. for (let i = treeNode.items.length - 1; i >= 0; i--) {
  396. if (treeNode.items[i].nodeType === RT.NodeType.NODE) {
  397. insertIdx = i + 1;
  398. break;
  399. } else {
  400. insertIdx = i;
  401. }
  402. }
  403. }
  404. me.treeObj.addNodes(treeNode, insertIdx, newNodes, isSilent);
  405. let tn = me.getParentNodeByNodeLevel(
  406. treeNode,
  407. NODE_LEVEL_COMPILATION_NEW
  408. );
  409. let newTopNode = me.buildRootNodeDoc(tn);
  410. //*
  411. let pathArr = [];
  412. let nodeArr = [];
  413. let path = { operation_type: "add", node_path: [] };
  414. path.node_path = me.getNodePath(treeNode, true);
  415. pathArr.push(path);
  416. nodeArr.push(rawNode);
  417. me.partialUpdateTreeNode(
  418. newTopNode,
  419. pathArr,
  420. nodeArr,
  421. true,
  422. function (rst) {
  423. if (!rst) {
  424. alert("新增节点失败!");
  425. }
  426. me.refreshNodes();
  427. },
  428. null
  429. );
  430. /*/
  431. me.updateTreeRootNode(newTopNode, true, function(rst){
  432. if (!(rst)) {
  433. alert("新增节点失败!");
  434. }
  435. me.refreshNodes();
  436. }, null);
  437. //*/
  438. }
  439. });
  440. });
  441. addStr =
  442. "<span class='button blue_core' id='addBtn2_" +
  443. treeNode.tId +
  444. "' title='新增报表模板' onfocus='this.blur();'></span>";
  445. sObj.after(addStr);
  446. btn = $("#addBtn2_" + treeNode.tId + "");
  447. if (btn)
  448. btn.bind("click", function () {
  449. // let me = zTreeOprObj;
  450. if (
  451. treeNode.nodeType === RT.NodeType.NODE ||
  452. treeNode.level === NODE_LEVEL_COMPILATION_NEW
  453. ) {
  454. me.getNewNodeID(1, function (newNodeID) {
  455. let rawNode = me.createIniNode();
  456. rawNode.nodeType = RT.NodeType.TEMPLATE;
  457. rawNode.name = "新增报表模板" + new Date().getTime();
  458. rawNode.ID = newNodeID;
  459. rawNode.released = false;
  460. let newNodes = [],
  461. isSilent = false;
  462. newNodes.push(rawNode);
  463. me.treeObj.addNodes(treeNode, -1, newNodes, isSilent);
  464. let tn = me.getParentNodeByNodeLevel(
  465. treeNode,
  466. NODE_LEVEL_COMPILATION_NEW
  467. );
  468. let topNode = me.buildRootNodeDoc(tn);
  469. //*
  470. let pathArr = [];
  471. let nodeArr = [];
  472. let path = { operation_type: "add", node_path: [] };
  473. path.node_path = me.getNodePath(treeNode, true);
  474. pathArr.push(path);
  475. nodeArr.push(rawNode);
  476. me.partialUpdateTreeNode(
  477. topNode,
  478. pathArr,
  479. nodeArr,
  480. true,
  481. function (rst) {
  482. if (!rst) {
  483. alert("新增节点失败!");
  484. }
  485. me.refreshNodes();
  486. },
  487. null
  488. );
  489. /*/
  490. me.updateTreeRootNode(topNode, true, function(rst){
  491. if (!(rst)) {
  492. alert("新增空白模板失败!");
  493. }
  494. me.refreshNodes();
  495. }, null);
  496. //*/
  497. });
  498. }
  499. });
  500. }
  501. },
  502. removeHoverDom: function (treeId, treeNode) {
  503. $("#addBtn_" + treeNode.tId)
  504. .unbind()
  505. .remove();
  506. $("#addBtn2_" + treeNode.tId)
  507. .unbind()
  508. .remove();
  509. },
  510. addNewNodeEx: function (rawNode, callback, failCallback) {
  511. let params = {};
  512. params.doc = rawNode;
  513. CommonAjax.postEx(
  514. "report_tpl_api/createTreeRootNode",
  515. params,
  516. 5000,
  517. true,
  518. callback,
  519. failCallback,
  520. null
  521. );
  522. },
  523. onCheck: function (event, treeId, treeNode) {
  524. let me = zTreeOprObj;
  525. let topPNode = me.getParentNodeByNodeLevel(
  526. treeNode,
  527. NODE_LEVEL_COMPILATION_NEW
  528. );
  529. let newTopNode = me.buildRootNodeDoc(topPNode);
  530. me.updateTreeRootNode(newTopNode, true, function (rst) {
  531. if (!rst) {
  532. alert("修改发布状态失败!");
  533. }
  534. });
  535. },
  536. onBeforeDrag: function (treeId, treeNodes) {
  537. let rst = true;
  538. for (let node of treeNodes) {
  539. if (node.level === 0 || node.nodeType !== RT.NodeType.TEMPLATE) {
  540. rst = false;
  541. break;
  542. }
  543. }
  544. return rst;
  545. },
  546. onBeforeDrop: function (treeId, treeNodes, targetNode, moveType, isCopy) {
  547. let me = zTreeOprObj,
  548. rst = true;
  549. let srcNode = treeNodes[0];
  550. let sourceTopNode = me.getParentNodeByNodeLevel(
  551. srcNode,
  552. NODE_LEVEL_COMPILATION_NEW
  553. );
  554. let targetTopNode = me.getParentNodeByNodeLevel(
  555. targetNode,
  556. NODE_LEVEL_COMPILATION_NEW
  557. );
  558. me.moveSrcTopNode = null;
  559. if (moveType === "inner") {
  560. if (targetNode.nodeType === RT.NodeType.TEMPLATE) {
  561. //模板节点不能成为另一个模板节点的子节点。不过zTree控件默认会处理,这里的代码应该走不到,放在这里以防万一
  562. rst = false;
  563. } else {
  564. if (sourceTopNode !== targetTopNode) {
  565. if (!isCopy) {
  566. if (!confirm("是否真的要把报表模板移动到另一个工程类型?")) {
  567. rst = false;
  568. }
  569. }
  570. } else {
  571. //同一根节点下,可以随便移动或copy
  572. }
  573. }
  574. } else {
  575. if (
  576. targetNode.level === 0 ||
  577. targetNode.nodeType !== RT.NodeType.TEMPLATE
  578. ) {
  579. //模板节点不能与类型节点或目录节点同级!
  580. rst = false;
  581. } else {
  582. if (sourceTopNode !== targetTopNode) {
  583. if (!isCopy) {
  584. if (!confirm("是否真的要把报表模板移动到另一个工程类型?")) {
  585. rst = false;
  586. }
  587. }
  588. } else {
  589. //同一根节点下,可以随便移动或copy
  590. }
  591. }
  592. }
  593. if (rst && !isCopy && sourceTopNode !== targetTopNode) {
  594. me.moveSrcTopNode = sourceTopNode;
  595. }
  596. return rst;
  597. },
  598. onDrop: function (event, treeId, treeNodes, targetNode, moveType, isCopy) {
  599. let me = zTreeOprObj;
  600. zTreeOprObj.treeObj.checkNode(treeNodes[0], false, false);
  601. treeNodes[0].released = false;
  602. // 拷贝后的uuid重复的问题
  603. if (isCopy) {
  604. treeNodes[0].UUID = `${new Date().getTime()}_${me.generateRandomString()}`;
  605. }
  606. let targetTopNode = me.getParentNodeByNodeLevel(
  607. targetNode,
  608. NODE_LEVEL_COMPILATION_NEW
  609. );
  610. let newTopNode = null;
  611. let canContinue = false;
  612. if (isCopy) {
  613. me.getNewNodeID(1, function (newNodeID) {
  614. let orgID = treeNodes[0].refId; //refId才是正确的模板ID(因可能copy一个有引用的节点),
  615. treeNodes[0].ID = newNodeID;
  616. if (confirm("是否引用相同的报表模板?")) {
  617. newTopNode = me.buildRootNodeDoc(targetTopNode);
  618. me.updateTreeRootNode(
  619. newTopNode,
  620. false,
  621. function (goodRst) {
  622. canContinue = true;
  623. if (treeNodes[0].rptTpl) {
  624. treeNodes[0].rptTpl.ID = newNodeID;
  625. }
  626. me.currentNode = treeNodes[0];
  627. me.chkAndSetDupRefTplIds(me.treeObj.getNodes(), null);
  628. me.treeObj.refresh();
  629. me.chkAndRreshRefTpl();
  630. },
  631. function (badRst) {
  632. displayMessage("更新模板节点失败!", "red", 2000);
  633. // console.log(badRst.toString());
  634. console.log(badRst);
  635. }
  636. );
  637. } else {
  638. treeNodes[0].refId = newNodeID;
  639. // targetNode.refId = newNodeID; //targetNode可以是父节点也可以是兄弟节点,没必要引用相同的tplID
  640. newTopNode = me.buildRootNodeDoc(targetTopNode);
  641. me.copyReportTemplate(
  642. orgID,
  643. newNodeID,
  644. true,
  645. function (goodResult) {
  646. me.updateTreeRootNode(
  647. newTopNode,
  648. true,
  649. function (goodRst) {
  650. canContinue = true;
  651. // treeObj.updateNode(nodes[0]);
  652. zTreeOprObj.treeObj.updateNode(treeNodes[0]);
  653. if (treeNodes[0].rptTpl) {
  654. treeNodes[0].rptTpl.ID = newNodeID;
  655. }
  656. me.currentNode = treeNodes[0];
  657. me.chkAndSetDupRefTplIds(me.treeObj.getNodes(), null);
  658. me.treeObj.refresh();
  659. me.chkAndRreshRefTpl();
  660. },
  661. function (badRst) {
  662. displayMessage("更新模板节点失败!", "red", 2000);
  663. // console.log(badRst.toString());
  664. console.log(badRst);
  665. }
  666. );
  667. },
  668. function (badResult) {
  669. displayMessage("Copy请求失败!", "red", 2000);
  670. // console.log(badResult.toString());
  671. console.log(badResult);
  672. }
  673. );
  674. }
  675. });
  676. // if (canContinue) {
  677. // me.chkAndRreshRefTpl();
  678. // }
  679. } else {
  680. newTopNode = me.buildRootNodeDoc(targetTopNode);
  681. me.updateTreeRootNode(
  682. newTopNode,
  683. false,
  684. function (rst) {
  685. canContinue = true;
  686. me.currentNode = treeNodes[0];
  687. },
  688. function (badResult) {
  689. displayMessage("移动请求失败!", "red", 2000);
  690. console.log(badResult.toString());
  691. canContinue = false;
  692. }
  693. );
  694. if (canContinue && !isCopy && me.moveSrcTopNode) {
  695. let newSrcTopNode = me.buildRootNodeDoc(me.moveSrcTopNode);
  696. me.updateTreeRootNode(
  697. newSrcTopNode,
  698. true,
  699. function (rst) {
  700. // canContinue = true;
  701. },
  702. function (badResult) {
  703. displayMessage("移动请求失败!", "red", 2000);
  704. canContinue = true;
  705. }
  706. );
  707. }
  708. me.moveSrcTopNode = null;
  709. }
  710. },
  711. addReportTemplate: function (newUsers) {
  712. let me = zTreeOprObj,
  713. params = {};
  714. params.compilationId = $("#compilations").get(0).value;
  715. params.userId = [];
  716. if (newUsers.length > 0) {
  717. for (let user of newUsers) {
  718. params.userId.push(user.userId);
  719. }
  720. }
  721. let allEngIds = [];
  722. for (let item of engineeringList) {
  723. allEngIds.push(item.value);
  724. }
  725. params.engineerId = allEngIds;
  726. CommonAjax.postEx(
  727. "report_tpl_api/getRptTplTree",
  728. params,
  729. 20000,
  730. true,
  731. function (result) {
  732. result.sort(function (item1, item2) {
  733. let rst = 0;
  734. if (item1.userId === item2.userId) {
  735. rst =
  736. item1.engineerId > item2.engineerId
  737. ? 1
  738. : item1.engineerId < item2.engineerId
  739. ? -1
  740. : 0;
  741. } else {
  742. if (item1.userId === "-100") {
  743. rst = 1;
  744. } else if (item2.userId === "-100") {
  745. rst = -1;
  746. } else {
  747. let idx1 = -1,
  748. idx2 = -1;
  749. for (let uidx = 0; uidx < newUsers.length; uidx++) {
  750. if (newUsers[uidx].userId === item1.userId) idx1 = uidx;
  751. if (newUsers[uidx].userId === item2.userId) idx2 = uidx;
  752. if (idx1 >= 0 && idx2 >= 0) {
  753. break;
  754. }
  755. rst = idx1 > idx2 ? 1 : idx1 < idx2 ? -1 : 0;
  756. }
  757. }
  758. }
  759. return rst;
  760. });
  761. let allTopUserIdNodes = [];
  762. let allTopTplNodes = [];
  763. for (let user of newUsers) {
  764. allTopUserIdNodes.push(user.userId);
  765. allTopTplNodes.push({
  766. userId: user.userId,
  767. name: user.real_name,
  768. items: [],
  769. isParent: true,
  770. });
  771. }
  772. for (let item of result) {
  773. let uidx = allTopUserIdNodes.indexOf(item.userId);
  774. if (uidx >= 0) {
  775. item.isParent = true;
  776. allTopTplNodes[uidx].items.push(item);
  777. }
  778. }
  779. // zTreeHelper.createTreeDirectly(allTopTplNodes, setting, "rptTplTree", me);
  780. //add template nodes
  781. let isSilent = false;
  782. me.treeObj.addNodes(null, -1, allTopTplNodes, isSilent);
  783. me.refreshNodes();
  784. let private_setup_checked = function (itemNode) {
  785. if (itemNode.nodeType === RT.NodeType.NODE) {
  786. me.treeObj.setChkDisabled(itemNode, true);
  787. } else if (itemNode.nodeType === RT.NodeType.TEMPLATE) {
  788. me.treeObj.checkNode(itemNode, !!itemNode.released);
  789. }
  790. if (itemNode.items && itemNode.items.length > 0) {
  791. for (let subItem of itemNode.items) {
  792. private_setup_checked(subItem);
  793. }
  794. }
  795. };
  796. let topNodes = me.treeObj.getNodes();
  797. // me.treeObj.expandAll(true);
  798. for (let node of topNodes) {
  799. me.treeObj.setChkDisabled(node, true);
  800. if (node.items && node.items.length > 0) {
  801. for (let item of node.items) {
  802. me.treeObj.setChkDisabled(item, true);
  803. private_setup_checked(item);
  804. }
  805. }
  806. }
  807. },
  808. null,
  809. null
  810. );
  811. },
  812. chkAndSetDupRefTplIds: function (tplNodes, selectedRefId) {
  813. let me = zTreeOprObj,
  814. tmpRefIds = [];
  815. me.dupTplIds = [];
  816. let private_get_dup_ids = function (tplNode) {
  817. if (tplNode.refId && tplNode.refId !== -1) {
  818. let refId = tplNode.refId;
  819. if (tmpRefIds.indexOf(refId) < 0) {
  820. tmpRefIds.push(refId);
  821. } else {
  822. if (me.dupTplIds.indexOf(refId) < 0) {
  823. me.dupTplIds.push(refId);
  824. } else {
  825. //
  826. }
  827. }
  828. }
  829. if (tplNode.items && tplNode.items.length > 0) {
  830. for (let subTplNode of tplNode.items) {
  831. private_get_dup_ids(subTplNode);
  832. }
  833. }
  834. };
  835. let private_set_dup_icon = function (tplNode) {
  836. if (me.dupTplIds.indexOf(tplNode.refId) >= 0) {
  837. // tplNode.icon = "../../../../lib/ztree/css/img/diy/3.png"; //or below:
  838. if (selectedRefId && selectedRefId === tplNode.refId) {
  839. tplNode.icon = "/lib/ztree/css/img/diy/5.png";
  840. } else {
  841. tplNode.icon = "/lib/ztree/css/img/diy/3.png";
  842. }
  843. // tplNode.style = "background:url(/lib/ztree/css/img/diy/3.png) 0 0 no-repeat;"
  844. } else {
  845. //设置白板
  846. // if (!tplNode.isParent) tplNode.icon = "/lib/ztree/css/img/diy/10.png";
  847. if (!tplNode.isParent) tplNode.className = "button ico_docu";
  848. }
  849. if (tplNode.items && tplNode.items.length > 0) {
  850. for (let subTplNode of tplNode.items) {
  851. private_set_dup_icon(subTplNode);
  852. }
  853. }
  854. };
  855. for (let tplNodeItem of tplNodes) {
  856. private_get_dup_ids(tplNodeItem);
  857. }
  858. for (let tplNodeItem of tplNodes) {
  859. private_set_dup_icon(tplNodeItem);
  860. }
  861. if (selectedRefId) {
  862. me.hasRefreshedDupRefIds = true;
  863. } else {
  864. me.hasRefreshedDupRefIds = false;
  865. }
  866. },
  867. getReportTemplateTreeEx: function (compilationSelect) {
  868. let me = zTreeOprObj,
  869. params = {};
  870. params.compilationId = compilationSelect.value;
  871. CommonAjax.postEx(
  872. "report_tpl_api/getTplTreeByCompilation",
  873. params,
  874. 20000,
  875. true,
  876. function (result) {
  877. result.sort(function (item1, item2) {
  878. let rst = 0;
  879. if (item1.userId === "-100") {
  880. rst = -1;
  881. } else if (item2.userId === "-100") {
  882. rst = 1;
  883. }
  884. return rst;
  885. });
  886. // me.chkAndSetDupRefTplIds(result);
  887. // console.log(dupRefIds);
  888. let allTopTplNodes = [
  889. {
  890. userId: "-100",
  891. name: "公共模板",
  892. items: [],
  893. isParent: true,
  894. refId: "",
  895. },
  896. ];
  897. if (result.length > 0) {
  898. if (!result[0].hasOwnProperty("refId")) {
  899. result[0].refId = "";
  900. }
  901. allTopTplNodes[0].items.push(result[0]);
  902. }
  903. let userIds = [];
  904. for (let idx = 1; idx < result.length; idx++) {
  905. let item = result[idx];
  906. if (!item.hasOwnProperty("refId")) {
  907. item.refId = "";
  908. }
  909. userIds.push(item.userId);
  910. }
  911. userListObj.findUsersByIds(userIds, function (userObjs) {
  912. for (let user of userObjs) {
  913. for (let itemIdx = 1; itemIdx < result.length; itemIdx++) {
  914. let item = result[itemIdx];
  915. if (item.userId === user._id) {
  916. allTopTplNodes.push({
  917. userId: user.userId,
  918. name: user.real_name,
  919. items: [],
  920. isParent: true,
  921. refId: "",
  922. });
  923. allTopTplNodes[allTopTplNodes.length - 1].items.push(
  924. result[itemIdx]
  925. );
  926. break;
  927. }
  928. }
  929. }
  930. zTreeHelper.createTreeDirectly(
  931. allTopTplNodes,
  932. setting,
  933. "rptTplTree",
  934. me
  935. );
  936. let topNodes = me.treeObj.getNodes();
  937. me.chkAndSetDupRefTplIds(topNodes, null);
  938. me.refreshNodes();
  939. let private_setup_checked = function (itemNode) {
  940. if (itemNode.nodeType === RT.NodeType.NODE) {
  941. me.treeObj.setChkDisabled(itemNode, true);
  942. } else if (itemNode.nodeType === RT.NodeType.TEMPLATE) {
  943. me.treeObj.checkNode(itemNode, !!itemNode.released);
  944. }
  945. if (itemNode.items && itemNode.items.length > 0) {
  946. for (let subItem of itemNode.items) {
  947. private_setup_checked(subItem);
  948. }
  949. }
  950. };
  951. me.treeObj.expandAll(true);
  952. for (let node of topNodes) {
  953. me.treeObj.setChkDisabled(node, true);
  954. if (node.items && node.items.length > 0) {
  955. for (let item of node.items) {
  956. me.treeObj.setChkDisabled(item, true);
  957. private_setup_checked(item);
  958. }
  959. }
  960. }
  961. // 同类表初始化
  962. associationOprObj.iniAssociateNodes(allTopTplNodes);
  963. });
  964. },
  965. null,
  966. null
  967. );
  968. },
  969. getNewNodeID: function (scope, callback) {
  970. let params = {};
  971. params.scope = scope;
  972. CommonAjax.postEx(
  973. "report_tpl_api/getNewNodeID",
  974. params,
  975. 5000,
  976. true,
  977. callback,
  978. null,
  979. null
  980. );
  981. },
  982. chkIfDupCompilationNode: function (rawNode, parentUserNode) {
  983. let rst = false;
  984. //在新的需求下,只需要检测编办与userId即可,无需工程id
  985. if (parentUserNode.items && parentUserNode.items.length > 0) {
  986. for (let node of parentUserNode.items) {
  987. if (
  988. node.compilationId === rawNode.compilationId &&
  989. node.userId === rawNode.userId
  990. ) {
  991. rst = true;
  992. break;
  993. }
  994. }
  995. }
  996. return rst;
  997. },
  998. createIniComilationNode: function () {
  999. //在新的需求下,无需工程id
  1000. let rst = {
  1001. compilationId: $("#compilations").get(0).selectedOptions[0].value,
  1002. userId: userAccount === "admin" ? "-100" : userID,
  1003. properties: [],
  1004. released: true,
  1005. isDeleted: false,
  1006. items: [],
  1007. name: $("#compilations").get(0).selectedOptions[0].innerText,
  1008. };
  1009. return rst;
  1010. },
  1011. onBeforeRemove: function (treeId, treeNode) {
  1012. let canRemove = false;
  1013. if (treeNode.level > NODE_LEVEL_USER) {
  1014. if (!treeNode.items || treeNode.items.length < 1) {
  1015. canRemove = confirm("请再确认您要删除!");
  1016. } else {
  1017. alert("含有子项,不能删除!");
  1018. }
  1019. } else {
  1020. alert("不能删除用户级别模板!");
  1021. }
  1022. return canRemove;
  1023. },
  1024. onRemove: function (e, treeId, treeNode) {
  1025. if (treeNode.level > NODE_LEVEL_USER) {
  1026. let me = zTreeOprObj,
  1027. topPNode = me.getParentNodeByNodeLevel(
  1028. treeNode,
  1029. NODE_LEVEL_COMPILATION_NEW
  1030. );
  1031. let rawNode = me.buildRootNodeDoc(topPNode, treeNode);
  1032. if (treeNode.level === NODE_LEVEL_COMPILATION_NEW) {
  1033. me.removeTreeRootNode(rawNode, true, function (rst) {
  1034. if (!rst) {
  1035. alert("删除请求失败!");
  1036. }
  1037. });
  1038. } else {
  1039. // me.updateTreeRootNode(rawNode, true, function(rst){
  1040. // if (!(rst)) {
  1041. // alert("删除请求失败!");
  1042. // }
  1043. // });
  1044. let pathArr = [];
  1045. let nodeArr = [];
  1046. let path = { operation_type: "delete", node_path: [] };
  1047. path.node_path = me.getNodePath(treeNode, true);
  1048. pathArr.push(path);
  1049. nodeArr.push("");
  1050. me.partialUpdateTreeNode(
  1051. topPNode,
  1052. pathArr,
  1053. nodeArr,
  1054. true,
  1055. function (rst) {
  1056. if (!rst) {
  1057. alert("删除模板失败!");
  1058. }
  1059. },
  1060. null
  1061. );
  1062. }
  1063. me.refreshNodes();
  1064. //*/
  1065. }
  1066. },
  1067. beforeEditName: function (treeId, treeNode) {
  1068. if (treeNode.level > NODE_LEVEL_COMPILATION_NEW) {
  1069. setTimeout(function () {
  1070. let ip = $("#" + treeNode.tId + IDMark_Input);
  1071. if (ip.length > 0) {
  1072. ip[0].className = "individualRename";
  1073. } else {
  1074. setTimeout(function () {
  1075. let ip = $("#" + treeNode.tId + IDMark_Input);
  1076. if (ip.length > 0) {
  1077. ip[0].className = "individualRename";
  1078. } else {
  1079. console.log("sorry!");
  1080. }
  1081. }, 50);
  1082. }
  1083. }, 50);
  1084. return true;
  1085. } else {
  1086. return false;
  1087. }
  1088. },
  1089. beforeRename: function (treeId, treeNode, newName, isCancel) {
  1090. if (newName.length === 0) {
  1091. return false;
  1092. }
  1093. return true;
  1094. },
  1095. onRename: function (e, treeId, treeNode, isCancel) {
  1096. if (!isCancel) {
  1097. let me = zTreeOprObj;
  1098. if (treeNode.level === 0) {
  1099. //因结构变化,已经不允许更改顶节点名字
  1100. } else {
  1101. let subTopNode = me.getParentNodeByNodeLevel(
  1102. treeNode,
  1103. NODE_LEVEL_COMPILATION_NEW + 1
  1104. );
  1105. let topPNode = subTopNode.getParentNode();
  1106. let rawNode = me.buildSubRootNodeDoc(subTopNode);
  1107. me.updateSubNode(topPNode, rawNode, true, function (rst) {
  1108. if (!rst) {
  1109. alert("修改名称请求失败!");
  1110. }
  1111. });
  1112. }
  1113. }
  1114. },
  1115. onChangeFlag: function (flagProp, flagDom) {
  1116. let me = zTreeOprObj;
  1117. if (me.currentNode && me.currentNode.nodeType === RT.NodeType.TEMPLATE) {
  1118. if (!me.currentNode.hasOwnProperty("flags")) {
  1119. me.currentNode.flags = {};
  1120. }
  1121. me.currentNode.flags[flagProp] =
  1122. flagDom.selectedOptions[0].value === "NA"
  1123. ? null
  1124. : flagDom.selectedOptions[0].value;
  1125. let subTopNode = me.getParentNodeByNodeLevel(
  1126. me.currentNode,
  1127. NODE_LEVEL_COMPILATION_NEW + 1
  1128. );
  1129. let topPNode = subTopNode.getParentNode();
  1130. let rawNode = me.buildSubRootNodeDoc(subTopNode);
  1131. me.updateSubNode(topPNode, rawNode, true, function (rst) {
  1132. if (!rst) {
  1133. alert("修改标记:[" + flagProp + "] 失败!");
  1134. }
  1135. });
  1136. }
  1137. },
  1138. onMutiChangeFlag: function (flagProp, flagDom) {
  1139. let me = zTreeOprObj;
  1140. if (me.currentNode && me.currentNode.nodeType === RT.NodeType.TEMPLATE) {
  1141. if (!me.currentNode.hasOwnProperty("flags")) {
  1142. me.currentNode.flags = {};
  1143. }
  1144. me.currentNode.flags[flagProp] = flagDom[0].value.split(",");
  1145. let subTopNode = me.getParentNodeByNodeLevel(
  1146. me.currentNode,
  1147. NODE_LEVEL_COMPILATION_NEW + 1
  1148. );
  1149. let topPNode = subTopNode.getParentNode();
  1150. let rawNode = me.buildSubRootNodeDoc(subTopNode);
  1151. me.updateSubNode(topPNode, rawNode, true, function (rst) {
  1152. if (!rst) {
  1153. alert("修改标记:[" + flagProp + "] 失败!");
  1154. }
  1155. });
  1156. }
  1157. },
  1158. createNewTpl: function () {
  1159. let me = zTreeOprObj,
  1160. params = {};
  1161. if (me.currentNode && me.currentNode.nodeType === RT.NodeType.TEMPLATE) {
  1162. params.treeNodeId = me.currentNode.ID;
  1163. let rptTypeId = common_rpt_type_ids.flow;
  1164. if ($("#crossTypeOpt")[0].checked) rptTypeId = common_rpt_type_ids.cross;
  1165. if ($("#billTypeOpt")[0].checked) rptTypeId = common_rpt_type_ids.bill;
  1166. params.rptDftTplId = rptTypeId;
  1167. params.rptName = me.currentNode.name;
  1168. params.grpKey = me.getFolderText(me.currentNode, "_");
  1169. me.currentNode.refId = me.currentNode.ID;
  1170. let subTopNode = me.getParentNodeByNodeLevel(
  1171. me.currentNode,
  1172. NODE_LEVEL_COMPILATION_NEW + 1
  1173. );
  1174. let topPNode = me.getParentNodeByNodeLevel(
  1175. subTopNode,
  1176. NODE_LEVEL_COMPILATION_NEW
  1177. );
  1178. let rawNode = me.buildSubRootNodeDoc(subTopNode);
  1179. params.compilationId = topPNode.compilationId;
  1180. params.engineerId = topPNode.engineerId;
  1181. params.userId = topPNode.userId;
  1182. params.subNode = rawNode;
  1183. CommonAjax.postEx(
  1184. "report_tpl_api/createDftRptTpl",
  1185. params,
  1186. 10000,
  1187. true,
  1188. function (result) {
  1189. if (result) {
  1190. me.currentNode.rptTpl = result;
  1191. me.chkAndRreshRefTpl();
  1192. } else {
  1193. alert("update error!");
  1194. }
  1195. },
  1196. null,
  1197. null
  1198. );
  1199. }
  1200. },
  1201. beforeClick: function (treeId, treeNode, clickFlag) {
  1202. let me = zTreeOprObj;
  1203. if (me.dupTplIds && me.dupTplIds.indexOf(treeNode.refId) >= 0) {
  1204. let topNodes = me.treeObj.getNodes();
  1205. me.chkAndSetDupRefTplIds(topNodes, treeNode.refId);
  1206. me.refreshNodes();
  1207. } else if (me.hasRefreshedDupRefIds) {
  1208. let topNodes = me.treeObj.getNodes();
  1209. me.chkAndSetDupRefTplIds(topNodes, null);
  1210. me.refreshNodes();
  1211. }
  1212. return true;
  1213. },
  1214. onClick: function (event, treeId, treeNode) {
  1215. let me = zTreeOprObj;
  1216. me.currentNode = treeNode;
  1217. bandTreeOprObj.currentNode = null;
  1218. if (treeNode.nodeType === RT.NodeType.NODE) {
  1219. $("#rpt_tpl_display_label")[0].innerText = "...";
  1220. } else if (treeNode.nodeType === RT.NodeType.TEMPLATE) {
  1221. let showText = me.getFolderText(me.currentNode, " > ");
  1222. $("#rpt_tpl_display_label")[0].innerText = showText;
  1223. if (treeNode.refId < 0) {
  1224. //创建新报表模板
  1225. $("#rptTypeSelectionModal").modal("show");
  1226. } else {
  1227. //显示报表模板
  1228. me.chkAndRreshRefTpl(true);
  1229. }
  1230. associationOprObj.refreshNodes(me.currentNode);
  1231. }
  1232. },
  1233. isFlowTpl: function () {
  1234. let rst = false;
  1235. let me = zTreeOprObj;
  1236. if (me.currentNode && me.currentNode.nodeType === RT.NodeType.TEMPLATE) {
  1237. rst = !!me.currentNode.rptTpl[JV.NODE_FLOW_INFO];
  1238. }
  1239. return rst;
  1240. },
  1241. isCrossTpl: function () {
  1242. let rst = false;
  1243. let me = zTreeOprObj;
  1244. if (me.currentNode && me.currentNode.nodeType === RT.NodeType.TEMPLATE) {
  1245. rst = !!me.currentNode.rptTpl[JV.NODE_CROSS_INFO];
  1246. }
  1247. return rst;
  1248. },
  1249. isBillTpl: function () {
  1250. let rst = false;
  1251. let me = zTreeOprObj;
  1252. if (me.currentNode && me.currentNode.nodeType === RT.NodeType.TEMPLATE) {
  1253. rst = !!me.currentNode.rptTpl[JV.NODE_BILL_INFO];
  1254. }
  1255. return rst;
  1256. },
  1257. getFolderText: function (treeNode, separator) {
  1258. let rst = "";
  1259. if (treeNode) {
  1260. rst = treeNode.name;
  1261. let parentNode = treeNode.getParentNode();
  1262. while (parentNode !== null) {
  1263. rst = parentNode.name + separator + rst;
  1264. parentNode = parentNode.getParentNode();
  1265. }
  1266. }
  1267. return rst;
  1268. },
  1269. chkAndRreshRefTpl: function (forceRefresh) {
  1270. let me = zTreeOprObj,
  1271. params = {};
  1272. const valuationTypes = [
  1273. "suggestion",
  1274. "feasibility",
  1275. "rough",
  1276. "bill",
  1277. "three_bill_budget",
  1278. "ration",
  1279. "changeBudget",
  1280. "settlement",
  1281. ];
  1282. if (
  1283. me.currentNode &&
  1284. me.currentNode.nodeType === RT.NodeType.TEMPLATE &&
  1285. me.currentNode.refId > 0
  1286. ) {
  1287. if (forceRefresh || !me.currentNode.rptTpl) {
  1288. params.rptTplId = me.currentNode.refId;
  1289. CommonAjax.postEx(
  1290. "report_tpl_api/getRefRptTpl",
  1291. params,
  1292. 20000,
  1293. true,
  1294. function (result) {
  1295. me.currentNode.rptTpl = result;
  1296. me.currentNode.rptTpl[JV.NODE_MAIN_INFO][
  1297. JV.NODE_MAIN_INFO_RPT_NAME
  1298. ] = me.currentNode.name;
  1299. if (me.currentNode.rptTpl["GROUP_KEY"]) {
  1300. let grp_keys = me.currentNode.rptTpl["GROUP_KEY"].split("_");
  1301. if (grp_keys.length > 0) {
  1302. grp_keys[1] = me.currentNode.name;
  1303. }
  1304. me.currentNode.rptTpl["GROUP_KEY"] = grp_keys.join("_");
  1305. }
  1306. tplHelper.refreshTplView(me.currentNode.rptTpl);
  1307. if (me.currentNode.hasOwnProperty("flags")) {
  1308. if (me.currentNode.flags.hasOwnProperty("taxType")) {
  1309. let val = parseInt(me.currentNode.flags["taxType"]);
  1310. $("#element_flags_select")[0].selectedIndex = val;
  1311. } else {
  1312. $("#element_flags_select")[0].selectedIndex = 0;
  1313. }
  1314. if (me.currentNode.flags.hasOwnProperty("constructSumType")) {
  1315. let val = me.currentNode.flags["constructSumType"];
  1316. if (val === "constructSum") {
  1317. $("#element_constructSumFlags_select")[0].selectedIndex = 1;
  1318. } else if (val === "singleSum") {
  1319. $("#element_constructSumFlags_select")[0].selectedIndex = 2;
  1320. } else {
  1321. $("#element_constructSumFlags_select")[0].selectedIndex = 0;
  1322. }
  1323. } else {
  1324. $("#element_constructSumFlags_select")[0].selectedIndex = 0;
  1325. }
  1326. if (me.currentNode.flags.hasOwnProperty("auditType")) {
  1327. let val = me.currentNode.flags["auditType"];
  1328. if (val === "audit_compare") {
  1329. $("#element_constructSumFlags_audit")[0].selectedIndex = 1;
  1330. } else if (val === "project_compare") {
  1331. $("#element_constructSumFlags_audit")[0].selectedIndex = 2;
  1332. } else {
  1333. $("#element_constructSumFlags_audit")[0].selectedIndex = 0;
  1334. }
  1335. } else {
  1336. $("#element_constructSumFlags_audit")[0].selectedIndex = 0;
  1337. }
  1338. if (me.currentNode.flags.hasOwnProperty("budgetType")) {
  1339. let val = me.currentNode.flags["budgetType"];
  1340. if (val === "1") {
  1341. $("#element_Flags_budgetType")[0].selectedIndex = 1;
  1342. } else if (val === "2") {
  1343. $("#element_Flags_budgetType")[0].selectedIndex = 2;
  1344. } else {
  1345. $("#element_Flags_budgetType")[0].selectedIndex = 0;
  1346. }
  1347. } else {
  1348. $("#element_Flags_budgetType")[0].selectedIndex = 0;
  1349. }
  1350. if (me.currentNode.flags.hasOwnProperty("budgetSumType")) {
  1351. let val = me.currentNode.flags["budgetSumType"];
  1352. if (val === "budget_construct") {
  1353. $("#element_Flags_budgetSummaryType")[0].selectedIndex = 1;
  1354. } else if (val === "budget_single") {
  1355. $("#element_Flags_budgetSummaryType")[0].selectedIndex = 2;
  1356. } else {
  1357. $("#element_Flags_budgetSummaryType")[0].selectedIndex = 0;
  1358. }
  1359. } else {
  1360. $("#element_Flags_budgetSummaryType")[0].selectedIndex = 0;
  1361. }
  1362. if (me.currentNode.flags.hasOwnProperty("budgetCalcType")) {
  1363. let val = me.currentNode.flags["budgetCalcType"];
  1364. if (val === "budget_cacl_type1") {
  1365. $("#element_Flags_budgetCalcType")[0].selectedIndex = 1;
  1366. } else {
  1367. $("#element_Flags_budgetCalcType")[0].selectedIndex = 0;
  1368. }
  1369. } else {
  1370. $("#element_Flags_budgetCalcType")[0].selectedIndex = 0;
  1371. }
  1372. $("#valuationSelector").hide();
  1373. if (me.currentNode.flags.hasOwnProperty("valuationType")) {
  1374. $(".mutiSelector").find("li").removeClass("checked");
  1375. let valuationTypeStr = "";
  1376. let valuationTypeStrList = [];
  1377. let vType = me.currentNode.flags["valuationType"];
  1378. if (vType instanceof Array) {
  1379. for (let i = 0; i < vType.length; i++) {
  1380. $("#valuationSelector_" + vType[i]).addClass("checked");
  1381. valuationTypeStrList.push(
  1382. valuationSelectorMap["valuationSelector_" + vType[i]]
  1383. );
  1384. }
  1385. valuationTypeStr = valuationTypeStrList.join(",");
  1386. } else if (vType) {
  1387. $("#valuationSelector_" + vType).addClass("checked");
  1388. valuationTypeStr =
  1389. valuationSelectorMap["valuationSelector_" + vType];
  1390. }
  1391. $("#element_prjFlags_select")[0].value = vType;
  1392. $("#element_prjFlags_selectStr")[0].value = valuationTypeStr;
  1393. } else {
  1394. $("#element_prjFlags_select")[0].value = "";
  1395. $("#element_prjFlags_selectStr")[0].value = "";
  1396. $("#valuationSelector .mutiSelector li").removeClass("checked");
  1397. }
  1398. if (me.currentNode.flags.hasOwnProperty("rptTplType")) {
  1399. let val = me.currentNode.flags["rptTplType"];
  1400. if (val === "construct") {
  1401. $("#element_Flags_tplType")[0].selectedIndex = 1;
  1402. } else if (val === "single") {
  1403. $("#element_Flags_tplType")[0].selectedIndex = 2;
  1404. } else if (val === "unit") {
  1405. $("#element_Flags_tplType")[0].selectedIndex = 3;
  1406. } else {
  1407. $("#element_Flags_tplType")[0].selectedIndex = 0;
  1408. }
  1409. } else {
  1410. $("#element_Flags_tplType")[0].selectedIndex = 0;
  1411. }
  1412. if (me.currentNode.flags.hasOwnProperty("sumLevelType")) {
  1413. let sumLvType = me.currentNode.flags["sumLevelType"];
  1414. if (sumLvType === "construct")
  1415. $("#element_sumLv_flags")[0].selectedIndex = 1;
  1416. else if (sumLvType === "Single")
  1417. $("#element_sumLv_flags")[0].selectedIndex = 2;
  1418. else if (sumLvType === "custom")
  1419. $("#element_sumLv_flags")[0].selectedIndex = 3;
  1420. else if (sumLvType === "unitPriceContrast")
  1421. $("#element_sumLv_flags")[0].selectedIndex = 4;
  1422. else if (sumLvType === "stageUnitContrast")
  1423. $("#element_sumLv_flags")[0].selectedIndex = 5;
  1424. else if (sumLvType === "stageUnitFontContrast")
  1425. $("#element_sumLv_flags")[0].selectedIndex = 6;
  1426. else if (sumLvType === "stageUnitBackContrast")
  1427. $("#element_sumLv_flags")[0].selectedIndex = 7;
  1428. else if (sumLvType === "stageContrast")
  1429. $("#element_sumLv_flags")[0].selectedIndex = 8;
  1430. else if (sumLvType === "stageGLJContrast")
  1431. $("#element_sumLv_flags")[0].selectedIndex = 9;
  1432. else if (sumLvType === "stageBackContrast")
  1433. $("#element_sumLv_flags")[0].selectedIndex = 10;
  1434. else if (sumLvType === "stageMultipleUnitContrast")
  1435. $("#element_sumLv_flags")[0].selectedIndex = 11;
  1436. else if (sumLvType === "complexUnit")
  1437. $("#element_sumLv_flags")[0].selectedIndex = 12;
  1438. else if (sumLvType === "complexConstruct")
  1439. $("#element_sumLv_flags")[0].selectedIndex = 13;
  1440. else if (sumLvType === "complexConstructMultiple")
  1441. $("#element_sumLv_flags")[0].selectedIndex = 14;
  1442. else if (sumLvType === "complexSelfConstructMultiple")
  1443. $("#element_sumLv_flags")[0].selectedIndex = 15;
  1444. else if (sumLvType === "businessSummary")
  1445. $("#element_sumLv_flags")[0].selectedIndex = 16;
  1446. else if (sumLvType === "changeProjectSummary")
  1447. $("#element_sumLv_flags")[0].selectedIndex = 17;
  1448. else if (sumLvType === "changeProjectGljSummary")
  1449. $("#element_sumLv_flags")[0].selectedIndex = 18;
  1450. else if (sumLvType === "compareConstruct")
  1451. $("#element_sumLv_flags")[0].selectedIndex = 19;
  1452. else {
  1453. $("#element_sumLv_flags")[0].selectedIndex = 0;
  1454. }
  1455. $("#outputDesignDataBar").show();
  1456. if (me.currentNode.flags.hasOwnProperty("outputDesignData")) {
  1457. if (me.currentNode.flags.outputDesignData) {
  1458. $("#outputDesignData").attr("checked", true);
  1459. } else {
  1460. $("#outputDesignData").attr("checked", false);
  1461. }
  1462. }
  1463. } else {
  1464. $("#element_sumLv_flags")[0].selectedIndex = 0;
  1465. }
  1466. } else {
  1467. $("#element_flags_select")[0].selectedIndex = 0;
  1468. $("#element_constructSumFlags_select")[0].selectedIndex = 0;
  1469. $("#element_constructSumFlags_audit")[0].selectedIndex = 0;
  1470. $("#element_Flags_budgetType")[0].selectedIndex = 0;
  1471. $("#element_Flags_budgetSummaryType")[0].selectedIndex = 0;
  1472. $("#element_Flags_budgetCalcType")[0].selectedIndex = 0;
  1473. $("#element_Flags_tplType")[0].selectedIndex = 0;
  1474. $("#element_prjFlags_select")[0].selectedIndex = 0;
  1475. // 清空工程类型
  1476. $("#valuationSelector").hide();
  1477. $("#element_prjFlags_select")[0].value = "";
  1478. $("#element_prjFlags_selectStr")[0].value = "";
  1479. $("#valuationSelector .mutiSelector li").removeClass("checked");
  1480. $("#element_sumLv_flags")[0].selectedIndex = 0;
  1481. }
  1482. if (
  1483. $("#rpt_tpl_visual_tab")[0].className === "nav-link p-1 active"
  1484. ) {
  1485. setTimeout(function () {
  1486. visualJumbo.iniSpreadJs();
  1487. visualJumbo.setupTpl();
  1488. }, 50);
  1489. }
  1490. },
  1491. null,
  1492. null
  1493. );
  1494. } else {
  1495. me.currentNode.rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MAIN_INFO_RPT_NAME] =
  1496. me.currentNode.name;
  1497. tplHelper.refreshTplView(me.currentNode.rptTpl);
  1498. if ($("#rpt_tpl_visual_tab")[0].className === "nav-link p-1 active") {
  1499. setTimeout(function () {
  1500. visualJumbo.iniSpreadJs();
  1501. visualJumbo.setupTpl();
  1502. }, 50);
  1503. }
  1504. }
  1505. }
  1506. },
  1507. getRefTpl: function () {
  1508. let me = zTreeOprObj,
  1509. rst = null;
  1510. if (
  1511. me.currentNode &&
  1512. me.currentNode.nodeType === RT.NodeType.TEMPLATE &&
  1513. me.currentNode.refId > 0
  1514. ) {
  1515. rst = me.currentNode.rptTpl;
  1516. }
  1517. return rst;
  1518. },
  1519. changeProperty: function (propStr, dom) {
  1520. let me = zTreeOprObj;
  1521. if (me.currentNode && me.currentNode.rptTpl) {
  1522. let props = propStr.split(".");
  1523. let lastProp = me.currentNode.rptTpl;
  1524. for (let idx = 1; idx < props.length; idx++) {
  1525. lastProp = lastProp[props[idx - 1]];
  1526. }
  1527. lastProp[props[props.length - 1]] = dom.value;
  1528. }
  1529. },
  1530. extractMainInfo: function (rptTpl) {
  1531. //模板信息
  1532. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MAIN_INFO_RPT_NAME] =
  1533. $("#rptTplName")[0].value;
  1534. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] =
  1535. JV.PAGES_SIZE_STR[$("#rptTplPageSize")[0].selectedIndex];
  1536. if ($("#rptTplPageOrientation")[0].selectedIndex === 1) {
  1537. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] =
  1538. JV.ORIENTATION_PORTRAIT;
  1539. } else {
  1540. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] =
  1541. JV.ORIENTATION_LANDSCAPE;
  1542. }
  1543. if (rptTpl[JV.NODE_FLOW_INFO]) {
  1544. rptTpl[JV.NODE_FLOW_INFO][JV.PROP_MULTI_COLUMN] = parseInt(
  1545. $("#rptTplMultiCols")[0].value
  1546. );
  1547. }
  1548. //考虑到页边距必然跟用户设置走,所以这里没必要特意去设置了,全部下架
  1549. },
  1550. getParentNodeByNodeLevel: function (currentNode, level) {
  1551. let rst = currentNode;
  1552. while (rst !== null) {
  1553. if (rst.level <= level) {
  1554. break;
  1555. } else {
  1556. rst = rst.getParentNode();
  1557. }
  1558. }
  1559. return rst;
  1560. },
  1561. };
  1562. let userListObj = {
  1563. foundedUserList: [],
  1564. UserIdList: [],
  1565. pushUser: function (user, newUsers) {
  1566. let me = userListObj;
  1567. if (me.UserIdList.indexOf(user._id) < 0) {
  1568. me.UserIdList.push(user._id);
  1569. let newUser = {
  1570. userId: user._id,
  1571. real_name: user.real_name,
  1572. username: user.username,
  1573. mobile: user.mobile,
  1574. };
  1575. me.foundedUserList.push(newUser);
  1576. if (newUsers) {
  1577. newUsers.push(newUser);
  1578. }
  1579. }
  1580. },
  1581. findUser: function () {
  1582. let key = $("#rpt_user_input1").get(0).value;
  1583. let newUsers = [];
  1584. $.ajax({
  1585. type: "GET",
  1586. url: "user/search?keyword=" + key,
  1587. cache: false,
  1588. timeout: 5000,
  1589. success: function (result) {
  1590. if (result.data && result.data.length > 0) {
  1591. for (let user of result.data) {
  1592. userListObj.pushUser(user, newUsers);
  1593. }
  1594. if (newUsers.length > 0) {
  1595. zTreeOprObj.addReportTemplate(newUsers);
  1596. }
  1597. }
  1598. },
  1599. error: function (jqXHR, textStatus, errorThrown) {},
  1600. });
  1601. },
  1602. findUsersByIds: function (userIds, cb) {
  1603. let params = {};
  1604. params.userIds = userIds;
  1605. CommonAjax.postEx(
  1606. "user/getUserList",
  1607. params,
  1608. 20000,
  1609. true,
  1610. function (result) {
  1611. for (let user of result) {
  1612. userListObj.pushUser(user, null);
  1613. }
  1614. if (cb) {
  1615. cb(result);
  1616. }
  1617. },
  1618. null,
  1619. null
  1620. );
  1621. },
  1622. };
  1623. function displayMessage(message, color, disappearTime, id) {
  1624. let domId = id;
  1625. if (!domId) domId = "id_after_saved_lbl";
  1626. $("#" + domId)[0].style.color = color;
  1627. $("#" + domId)[0].innerHTML = message;
  1628. setTimeout(function () {
  1629. $("#" + domId)[0].innerHTML = "";
  1630. }, disappearTime);
  1631. }
  1632. $("#element_prjFlags_selectStr").on("click", function () {
  1633. if ($("#valuationSelector").visible) {
  1634. $("#valuationSelector").hide();
  1635. } else {
  1636. $("#valuationSelector").show();
  1637. }
  1638. return false;
  1639. });
  1640. $("#rpttplinfo").on("click", function () {
  1641. $("#valuationSelector").hide();
  1642. });
  1643. $(".mutiSelector")
  1644. .find("li")
  1645. .on("click", function (e) {
  1646. const hasChecked = $(this).hasClass("checked");
  1647. if (hasChecked) {
  1648. $(this).removeClass("checked");
  1649. } else {
  1650. $(this).addClass("checked");
  1651. }
  1652. const resultIDList = [];
  1653. const resultList = [];
  1654. $(".mutiSelector .checked").each(function (index, value) {
  1655. resultList.push(valuationSelectorMap[$(value).attr("id")]);
  1656. resultIDList.push($(value).attr("value"));
  1657. });
  1658. const result = resultList.join(",");
  1659. $("#element_prjFlags_selectStr").val(result);
  1660. $("#element_prjFlags_select").val(resultIDList);
  1661. zTreeOprObj.onMutiChangeFlag(
  1662. "valuationType",
  1663. $("#element_prjFlags_select")
  1664. );
  1665. return false;
  1666. });