section_tree.js 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. /**
  2. * Created by Tony on 2017/4/27.
  3. */
  4. var pageOprObj = {
  5. rationLibName : null,
  6. rationLibId : null,
  7. initPage : function() {
  8. var me = this, rationLibId = getQueryString("repository"),//获取定额库参数
  9. rationLibName = storageUtil.getSessionCache("RationGrp","repositoryID_" + rationLibId);
  10. if (rationLibName) {
  11. var html = $("#rationname")[0].outerHTML;
  12. html = html.replace("XXX定额库", rationLibName);
  13. $("#rationname")[0].outerHTML = html;
  14. me.rationLibName = rationLibName;
  15. me.rationLibId = rationLibId;
  16. zTreeOprObj.getRationTree(rationLibId);
  17. //job
  18. jobContentOprObj.radiosChange(jobContentOprObj.radios, jobContentOprObj.tableAll, jobContentOprObj.tablePartial);
  19. $('#addConBtn').click(jobContentOprObj.bindAddConBtn());
  20. $('#updateConBtn').click(jobContentOprObj.bindUpdateConBtn());
  21. jobContentOprObj.bindAllEvents($('#txtareaAll'));
  22. //fz
  23. annotationOprObj.radiosChange(annotationOprObj.radios, annotationOprObj.fzTableAll, annotationOprObj.fzTablePartial);
  24. $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn());
  25. $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn());
  26. annotationOprObj.bindAllEvents($('#fzTxtareaAll'));
  27. }
  28. }
  29. }
  30. var zTreeOprObj = {
  31. treeObj: null,
  32. getRationTree: function(rationLibId){
  33. var me = this;
  34. $.ajax({
  35. type:"POST",
  36. url:"api/getRationTree",
  37. data:{"rationLibId": rationLibId},
  38. dataType:"json",
  39. cache:false,
  40. timeout:20000,
  41. success:function(result,textStatus,status){
  42. if(status.status == 200) {
  43. if (result.data.length > 0) {
  44. storageUtil.setSessionCache("RationGrp","repositoryID",result.data[0].rationRepId);
  45. }
  46. zTreeHelper.createTree(result.data, setting, "rationChapterTree", me);
  47. //初始化,初始节点点击
  48. let rootNode = me.treeObj.getNodes()[0];
  49. if(rootNode && rootNode.isFirstNode){
  50. me.treeObj.selectNode(rootNode);
  51. me.onClick(null, 'rationChapterTree', rootNode);
  52. }
  53. explanatoryOprObj.bindEvents($('#explanationShow'), $('#ruleTextShow'));
  54. }
  55. },
  56. error:function(err){
  57. alert(err.responseJSON.error);
  58. }
  59. })
  60. },
  61. addRootNode: function() {
  62. $('#addRootA').css("opacity", "0.2");
  63. $('#addRootA').addClass("disabled");
  64. var me = zTreeOprObj, rawNode = {ParentID: -1, NextSiblingID: -1, name: "新增节点"}, lastNodeId = -1;
  65. if (me.treeObj) {
  66. var rootNodes = me.treeObj.getNodes();
  67. if (rootNodes.length > 0) {
  68. lastNodeId = rootNodes[rootNodes.length - 1].ID;
  69. }
  70. }
  71. me.addNewNode(rawNode, lastNodeId, function(err, rst){
  72. if (!(err)) {
  73. if(rootNodes.length > 0){
  74. rootNodes[rootNodes.length - 1].NextSiblingID = rst.data.ID;
  75. }
  76. var newNodes = [], isSilent = false;
  77. newNodes.push({ rationRepId: rst.data.rationRepId, Previous_ID: lastNodeId, ID: rst.data.ID, ParentID:-1, NextSiblingID:-1, name:"新增节点",isParent:false, items:[]});
  78. if (me.treeObj) {
  79. me.treeObj.addNodes(null, -1, newNodes, isSilent);
  80. } else {
  81. me.treeObj = $.fn.zTree.init($("#rationChapterTree"), setting, newNodes);
  82. }
  83. $('#addRootA').css("opacity", "");
  84. $('#addRootA').removeClass("disabled");
  85. }
  86. });
  87. },
  88. addNewNode : function(rawNode, lastNodeId, callback){
  89. $.ajax({
  90. type:"POST",
  91. url:"api/createNewNode",
  92. data:{"rationLibId":pageOprObj.rationLibId,"lastNodeId": lastNodeId, "lastOpr": userAccount, "rawNodeData": JSON.stringify(rawNode)},
  93. dataType:"json",
  94. cache:false,
  95. timeout:1000,
  96. success: function(result,textStatus,status){
  97. callback(false, result);
  98. },
  99. error:function(err){
  100. callback(err);
  101. }
  102. })
  103. },
  104. beforeRename: function(treeId, treeNode, newName, isCancel) {
  105. if (newName.length == 0) {
  106. return false;
  107. }
  108. return true;
  109. },
  110. onRename : function(e, treeId, treeNode, isCancel) {
  111. var nodes = [];
  112. nodes.push(treeNode);
  113. zTreeOprObj.updateNodes(nodes);
  114. },
  115. onBeforeRemove: function(treeId, treeNode){
  116. var nodeIds = [], preNode = treeNode.getPreNode(), preNodeId = -1;
  117. if (preNode) {
  118. preNodeId = preNode.ID;
  119. }
  120. private_fetchAllSubItems = function(pItem){
  121. nodeIds.push(pItem.ID);
  122. if (pItem.items && pItem.items.length > 0) {
  123. for (var i = 0; i < pItem.items.length; i++) {
  124. private_fetchAllSubItems(pItem.items[i]);
  125. }
  126. }
  127. };
  128. nodeIds.push(treeNode.ID);
  129. for (var i = 0; i < treeNode.items.length; i++) {
  130. private_fetchAllSubItems(treeNode.items[i]);
  131. }
  132. $.ajax({
  133. type:"POST",
  134. url:"api/deleteNodes",
  135. data:{"repId": pageOprObj.rationLibId, "lastOpr": userAccount, "nodes": JSON.stringify(nodeIds), "preNodeId": preNodeId, "preNodeNextId": treeNode.NextSiblingID},
  136. dataType:"json",
  137. cache:false,
  138. timeout:5000,
  139. success:function(result,textStatus,status){
  140. var pNode = treeNode.getParentNode();
  141. if (pNode && pNode.items && pNode.items.length == 1) {
  142. pNode.isParent = false;
  143. }
  144. },
  145. error:function(){
  146. }
  147. });
  148. return true;
  149. },
  150. onRemove: function(e, treeId, treeNode){
  151. var me = zTreeOprObj, pNode = me.treeObj.getNodeByTId(treeNode.parentTId);
  152. if (pNode && pNode.items && pNode.items.length == 0) {
  153. pNode.isParent = false;
  154. me.treeObj.refresh();
  155. //me.treeObj.updateNode(pNode, false); //这方法有后遗症,多次操作后会造成节点新增子节点时,父节点icon显示不正确
  156. }
  157. },
  158. beforeDrop: function (treeId, treeNodes, targetNode, moveType) {
  159. let me = zTreeOprObj;
  160. if(moveType){
  161. me.treeObj.setting.edit.enable = false;
  162. let treeNode = treeNodes[0], updateNodes = [];
  163. //升级
  164. if(treeNode.level !== targetNode.level && moveType === 'prev'){
  165. if(treeNode.Previous_ID !== -1){
  166. treeNode.getPreNode().NextSiblingID = treeNode.NextSiblingID;
  167. updateNodes.push(treeNode.getPreNode());
  168. }
  169. if(treeNode.NextSiblingID !== -1){
  170. treeNode.getNextNode().Previous_ID = treeNode.Previous_ID;
  171. }
  172. if(targetNode.Previous_ID !== -1){
  173. targetNode.getPreNode().NextSiblingID = treeNode.ID;
  174. updateNodes.push(targetNode.getPreNode());
  175. }
  176. treeNode.ParentID = targetNode.getParentNode() ? targetNode.getParentNode().ID : -1;
  177. treeNode.NextSiblingID = targetNode.ID;
  178. treeNode.Previous_ID = targetNode.Previous_ID;
  179. targetNode.Previous_ID = treeNode.ID;
  180. updateNodes.push(treeNode);
  181. //updateNodes.push(targetNode);
  182. }
  183. //升级
  184. else if(treeNode.level !== targetNode.level && moveType === 'next'){
  185. if(treeNode.Previous_ID !== -1){
  186. treeNode.getPreNode().NextSiblingID = treeNode.NextSiblingID;
  187. updateNodes.push(treeNode.getPreNode());
  188. }
  189. if(treeNode.NextSiblingID !== -1){
  190. treeNode.getNextNode().Previous_ID = treeNode.Previous_ID;
  191. }
  192. if(targetNode.NextSiblingID !== -1){
  193. targetNode.getNextNode().Previous_ID = treeNode.ID;
  194. }
  195. treeNode.NextSiblingID = targetNode.NextSiblingID;
  196. treeNode.Previous_ID = targetNode.ID;
  197. treeNode.ParentID = targetNode.getParentNode() ? targetNode.getParentNode().ID : -1;
  198. targetNode.NextSiblingID = treeNode.ID;
  199. updateNodes.push(treeNode);
  200. updateNodes.push(targetNode);
  201. }
  202. //上移
  203. else if(treeNode.level === targetNode.level && moveType === 'prev'){
  204. if(targetNode.Previous_ID !== -1){
  205. let targetPrev = me.treeObj.getNodeByParam('ID', targetNode.Previous_ID, null);
  206. targetPrev.NextSiblingID = treeNode.ID;
  207. updateNodes.push(targetPrev);
  208. }
  209. targetNode.NextSiblingID = treeNode.NextSiblingID;
  210. treeNode.NextSiblingID = targetNode.ID;
  211. treeNode.Previous_ID = targetNode.Previous_ID;
  212. targetNode.Previous_ID = treeNode.ID;
  213. updateNodes.push(treeNode);
  214. updateNodes.push(targetNode);
  215. }
  216. //下移
  217. else if(treeNode.level === targetNode.level && moveType === 'next'){
  218. if(treeNode.Previous_ID !== -1){
  219. let treeNodePrev = me.treeObj.getNodeByParam('ID', treeNode.Previous_ID, null);
  220. treeNodePrev.NextSiblingID = targetNode.ID;
  221. updateNodes.push(treeNodePrev);
  222. }
  223. treeNode.Previous_ID = targetNode.ID;
  224. treeNode.NextSiblingID = targetNode.NextSiblingID;
  225. targetNode.Previous_ID = treeNode.Previous_ID;
  226. targetNode.NextSiblingID = treeNode.ID;
  227. updateNodes.push(treeNode);
  228. updateNodes.push(targetNode);
  229. }
  230. //
  231. else if(moveType === 'inner'){
  232. if( treeNode.Previous_ID !== -1){
  233. treeNode.getPreNode().NextSiblingID = treeNode.NextSiblingID;
  234. updateNodes.push(treeNode.getPreNode());
  235. }
  236. if(treeNode.NextSiblingID !== -1){
  237. treeNode.getNextNode().Previous_ID = treeNode.Previous_ID;
  238. }
  239. if(targetNode.items.length > 0){
  240. targetNode.items[targetNode.items.length -1].NextSiblingID = treeNode.ID;
  241. treeNode.Previous_ID = targetNode.items[targetNode.items.length -1].ID;
  242. updateNodes.push(targetNode.items[targetNode.items.length -1]);
  243. }
  244. else{
  245. treeNode.Previous_ID = -1;
  246. }
  247. treeNode.ParentID = targetNode.ID;
  248. treeNode.NextSiblingID = -1;
  249. updateNodes.push(treeNode);
  250. }
  251. if(updateNodes.length > 0){
  252. me.updateNodes(updateNodes, function () {
  253. me.treeObj.setting.edit.enable= true;
  254. });
  255. }
  256. }
  257. },
  258. onDrop: function (event, treeId, treeNodes, targetNode, moveType) {
  259. },
  260. updateNodes: function(nodes, callback){
  261. if (nodes && nodes.length > 0) {
  262. var reqData = []
  263. for (var i = 0; i < nodes.length; i++) {
  264. var node = {};
  265. node.rationRepId = nodes[i].rationRepId;
  266. node.ID = nodes[i].ID;
  267. node.ParentID = nodes[i].ParentID;
  268. node.NextSiblingID = nodes[i].NextSiblingID;
  269. node.name = nodes[i].name;
  270. if (nodes[i].__v != null) node.__v = nodes[i].__v + 1
  271. else node.__v = 0;
  272. reqData.push(node);
  273. }
  274. $.ajax({
  275. type:"POST",
  276. url:"api/updateNodes",
  277. data:{"repId": pageOprObj.rationLibId,"lastOpr": userAccount, "nodes": JSON.stringify(reqData)},
  278. dataType:"json",
  279. cache:false,
  280. timeout:5000,
  281. success:function(result,textStatus,status){
  282. if(callback){
  283. callback();
  284. }
  285. console.log(status + ' : ' + result);
  286. },
  287. error:function(){
  288. }
  289. })
  290. }
  291. },
  292. addHoverDom: function(treeId, treeNode) {
  293. if(typeof treeNode.doing !== 'undefined' && treeNode.doing){
  294. return false;
  295. }
  296. hoverOpr();
  297. function hoverOpr(){
  298. var me = zTreeOprObj, sObj = $("#" + treeNode.tId + "_span");
  299. if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
  300. var addStr = "<span class='button add' id='addBtn_" + treeNode.tId + "' title='新增子节点' onfocus='this.blur();'></span>";
  301. sObj.after(addStr);
  302. var btn = $("#addBtn_"+treeNode.tId);
  303. if (btn) btn.bind("click", function(){
  304. treeNode.doing = true;
  305. var rawNode = {ParentID: treeNode.ID, NextSiblingID: -1, name: "新增子节点"}, lastNodeId = -1, lastNode = null;
  306. if (treeNode.items.length > 0) {
  307. lastNodeId = treeNode.items[treeNode.items.length - 1].ID;
  308. lastNode = treeNode.items[treeNode.items.length - 1];
  309. }
  310. zTreeOprObj.addNewNode(rawNode, lastNodeId, function(err, rst){
  311. if (!(err)) {
  312. var newNodes = [], isSilent = false;
  313. if (lastNode) {
  314. lastNode.NextSiblingID = rst.ID;
  315. }
  316. newNodes.push({ rationRepId: rst.data.rationRepId, ID: rst.data.ID, Previous_ID: lastNodeId, ParentID: rst.data.ParentID, NextSiblingID:-1, name:"新增子节点",isParent:false, items:[]});
  317. treeNode.isParent = true;
  318. if (me.treeObj) {
  319. me.treeObj.addNodes(treeNode, -1, newNodes, isSilent);
  320. } else {
  321. me.treeObj = $.fn.zTree.init($("#rationChapterTree"), setting, newNodes);
  322. }
  323. }
  324. treeNode.doing = false;
  325. hoverOpr();
  326. });
  327. });
  328. }
  329. },
  330. removeHoverDom: function(treeId, treeNode) {
  331. $("#addBtn_"+treeNode.tId).unbind().remove();
  332. },
  333. onClick: function(event,treeId,treeNode) {
  334. explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : treeNode, treeNode, treeNode.explanation, treeNode.ruleText);
  335. explanatoryOprObj.clickUpdate($('#explanationShow'), $('#ruleTextShow'));
  336. explanatoryOprObj.showText($('#explanationShow'), $('#ruleTextShow'), treeNode.explanation, treeNode.ruleText);
  337. //job
  338. jobContentOprObj.currentSituation = typeof treeNode.jobContentSituation !== 'undefined'? treeNode.jobContentSituation : jobContentOprObj.situations.NONE;
  339. jobContentOprObj.setAttribute(jobContentOprObj.currentTreeNode ? jobContentOprObj.currentTreeNode : treeNode, treeNode);
  340. jobContentOprObj.clickUpdate($('#txtareaAll'));
  341. //fz
  342. annotationOprObj.currentSituation = typeof treeNode.annotationSituation !== 'undefined'? treeNode.annotationSituation : annotationOprObj.situations.NONE;
  343. annotationOprObj.clickUpdate($('#fzTxtareaAll'));
  344. var sectionID = treeNode.ID;
  345. if (!(treeNode.items) || treeNode.items.length == 0) {
  346. rationOprObj.canRations = true;
  347. rationOprObj.workBook.getSheet(0).clearSelection();
  348. rationOprObj.getRationItems(sectionID);
  349. } else {
  350. rationOprObj.canRations = false;
  351. rationOprObj.currentSectionId = sectionID;
  352. sheetCommonObj.unsetCombo(rationOprObj.workBook.getActiveSheet(), 0, 2, rationOprObj.workBook.getActiveSheet().getRowCount());
  353. jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios);
  354. jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial'));
  355. annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);
  356. annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial'));
  357. sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1);
  358. sheetCommonObj.shieldAllCells(rationOprObj.workBook.getSheet(0));
  359. }
  360. sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
  361. sheetCommonObj.shieldAllCells(rationGLJOprObj.sheet);
  362. rationGLJOprObj.sheet.getParent().focus(false);
  363. }
  364. };
  365. //定额章节节点说明、计算规则
  366. let explanatoryOprObj = {
  367. preTreeNode: null,
  368. currentTreeNode: null,//定额章节树节点
  369. currentExplanation: null,
  370. currentRuleText: null,
  371. setAttribute: function (preNode, currentNode, explanation, ruleText) {
  372. let me = explanatoryOprObj;
  373. me.preTreeNode = preNode;
  374. me.currentTreeNode = currentNode;
  375. me.currentExplanation = explanation;
  376. me.currentRuleText = ruleText;
  377. },
  378. clickUpdate: function (exarea, ruarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
  379. let me = explanatoryOprObj;
  380. if(exarea.is(':focus')){
  381. let explanation = exarea.val();
  382. if(explanation !== me.currentExplanation){
  383. me.preTreeNode.explanation = explanation;
  384. me.unbindEvents(exarea, ruarea);
  385. exarea.blur();
  386. me.updateExplanation(me.preTreeNode.rationRepId, me.preTreeNode.ID, explanation, function () {
  387. me.bindEvents(exarea, ruarea);
  388. });
  389. }
  390. }
  391. if(ruarea.is(':focus')){
  392. let ruleText = ruarea.val();
  393. if(ruleText !== me.currentRuleText){
  394. me.preTreeNode.ruleText = ruleText;
  395. me.unbindEvents(exarea, ruarea);
  396. ruarea.blur();
  397. me.updateRuleText(me.preTreeNode.rationRepId, me.preTreeNode.ID, ruleText, function () {
  398. me.bindEvents(exarea, ruarea);
  399. });
  400. }
  401. }
  402. },
  403. unbindEvents: function (exarea, ruarea) {
  404. exarea.unbind();
  405. ruarea.unbind();
  406. },
  407. bindEvents: function (exarea, ruarea) {
  408. let me = explanatoryOprObj;
  409. exarea.bind('change', function () {
  410. let explanation = exarea.val();
  411. let node = me.currentTreeNode;
  412. exarea.attr('disabled', true);
  413. me.updateExplanation(node.rationRepId, node.ID, explanation, function () {
  414. node.explanation = explanation;
  415. exarea.attr('disabled', false);
  416. });
  417. });
  418. ruarea.bind('change', function () {
  419. let ruleText = ruarea.val();
  420. let node = me.currentTreeNode;
  421. ruarea.attr('disabled', true);
  422. me.updateRuleText(node.rationRepId, node.ID, ruleText, function () {
  423. node.ruleText = ruleText;
  424. ruarea.attr('disabled', false);
  425. });
  426. });
  427. },
  428. showText: function (exarea, ruarea, explanation, ruleText) {
  429. exarea.val(explanation && explanation !== 'undefined' ? explanation : '');
  430. ruarea.val(ruleText && ruleText !== 'undefined' ? ruleText : '');
  431. },
  432. //更新说明
  433. updateExplanation: function (repId, nodeId, explanation, callback) {
  434. $.ajax({
  435. type: 'post',
  436. url: 'api/updateExplanation',
  437. data: {lastOpr: userAccount, repId: repId, nodeId: nodeId, explanation: explanation},
  438. dataType: 'json',
  439. success: function () {
  440. callback();
  441. }
  442. });
  443. },
  444. //更新计算规则
  445. updateRuleText: function (repId, nodeId, explanation, callback) {
  446. $.ajax({
  447. type: 'post',
  448. url: 'api/updateRuleText',
  449. data: {lastOpr: userAccount, repId: repId, nodeId: nodeId, explanation: explanation},
  450. dataType: 'json',
  451. success: function () {
  452. callback();
  453. }
  454. });
  455. }
  456. };
  457. //工作内容
  458. let jobContentOprObj = {
  459. situations: {ALL: 'ALL', PARTIAL: 'PARTIAL', NONE: 'NONE'},//所有ALL(包括未定义本项工作内容)、部分PARTIA,不可用NONE(无定额时)
  460. currentSituation: null,//本项适用情况
  461. currentTreeNode: null,
  462. preTreeNode: null,
  463. radios: $("input[name = 'optionsRadios']"),
  464. tableAll: $('#tableAll'),
  465. tablePartial: $('#tablePartial'),
  466. currentOprTr: null,
  467. currentJobContent: null,
  468. currentRationItems: null,
  469. addCon: $('#addCon'),//勾选编码模态框
  470. updateCon: $('#updateCon'),//编辑编码模态框
  471. setAttribute: function (preNode, currentNode) {
  472. let me = jobContentOprObj;
  473. me.preTreeNode = preNode;
  474. me.currentTreeNode = currentNode;
  475. },
  476. clickUpdate: function (txtarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
  477. let me = jobContentOprObj;
  478. if(txtarea.is(':focus')){
  479. let jobContent = txtarea.val();
  480. if(jobContent !== me.currentJobContent){
  481. me.preTreeNode.jobContent = jobContent;
  482. me.unbindEvents(txtarea);
  483. txtarea.blur();
  484. let updateCodes = [];
  485. for(let i = 0, len = me.currentRationItems.length; i < len; i++){
  486. updateCodes.push(me.currentRationItems[i].code);
  487. me.currentRationItems[i].jobContent = jobContent;
  488. }
  489. me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, jobContent), function () {
  490. me.bindAllEvents(txtarea);
  491. })
  492. }
  493. else {
  494. txtarea.blur();
  495. }
  496. }
  497. },
  498. getGroup: function (rationItems) {
  499. let rst = [];//rst = [{jobContent: String, items: Array}]
  500. for(let i = 0, len = rationItems.length; i < len; i++){
  501. if(typeof rationItems[i].jobContent !== 'undefined' && rationItems[i].jobContent.toString().trim().length > 0){
  502. let isExist = false;
  503. for(let j = 0, jLen = rst.length; j < jLen; j++){
  504. if(rst[j].jobContent === rationItems[i].jobContent){
  505. isExist = true;
  506. rst[j].items.push(rationItems[i].code);
  507. break;
  508. }
  509. }
  510. if(!isExist){
  511. rst.push({jobContent: rationItems[i].jobContent, items: [rationItems[i].code]});
  512. }
  513. }
  514. }
  515. return rst;
  516. },
  517. hideTable: function (tableAll, tablePartial) {
  518. if(tableAll){
  519. tableAll.hide();
  520. }
  521. if(tablePartial){
  522. tablePartial.hide();
  523. }
  524. },
  525. //建table
  526. buildTablePartial: function (table, group) {
  527. let me = jobContentOprObj;
  528. table.empty();
  529. let $thead = $("<thead><tr><th></th><th>编码</th><th>工作内容</th>/tr></thead>");
  530. let $tbody = $("<tbody></tbody>");
  531. let count = 1;
  532. for(let i = 0, len = group.length; i < len; i++){
  533. let $newTr = me.getNewTr($tbody, group[i].items, group[i].jobContent);
  534. $tbody.append($newTr);
  535. count++;
  536. }
  537. let $trEnd = $("<tr><td>"+ count +"</td><td><a href data-toggle='modal' data-target='#editBianma' class='m-0'>点击勾选编码</a></td><td><textarea class='form-control'></textarea></td></tr>");//勾选行
  538. $($trEnd.children().children()[0]).bind('click', function () {
  539. me.onclickFuncAdd($(this));
  540. me.currentOprTr = $trEnd;
  541. me.currentJobContent = $(me.currentOprTr.children()[2]).children().val();
  542. });
  543. $tbody.append($trEnd);
  544. table.append($thead);
  545. table.append($tbody);
  546. },
  547. //新增一行tr
  548. getNewTr: function (tbody, codes, jobContent) {
  549. let me = jobContentOprObj;
  550. let count = tbody.children().length > 0 ? tbody.children().length : 1;
  551. let $textTd = $("<td></td>");
  552. let $textarea = $("<textarea class='form-control'></textarea>");
  553. $textarea.val(jobContent);
  554. $textTd.append($textarea);
  555. let $tr = $("<tr><td>" + count + "</td><td><a href data-toggle='modal' data-target='#editBianmaQ' class='m-0'>编辑编码</a></td></tr>");
  556. $tr.children().children().bind('click', function () {
  557. me.currentOprTr = $tr;
  558. me.currentJobContent = $(me.currentOprTr.children()[2]).children().val();
  559. me.onclickFuncEdit($(this));
  560. });
  561. //文本变化;
  562. $textarea.bind('change', function () {
  563. let codes = me.getUpdateCodes($($(this).parent().parent().children()[1]).children());
  564. let jobContent = $(this).val();
  565. me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(codes, jobContent), function () {
  566. if(jobContent.trim().length === 0){
  567. me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
  568. }
  569. });
  570. });
  571. $tr.append($textTd);
  572. for(let i = 0, len = codes.length; i < len; i ++){
  573. let $p = $("<p class='m-0'>" + codes[i] + "</p>");
  574. $tr.children()[1].append($p[0]);
  575. }
  576. me.setTextareaHeight($textarea, codes.length + 1);
  577. return $tr[0];
  578. },
  579. onclickFuncAdd: function (obj) {
  580. let me = jobContentOprObj;
  581. let txtarea = $(obj.parent().parent().children().children()[1]);
  582. let jobContent = txtarea.val();
  583. if(jobContent.trim().length > 0){//工作内容不为空才可添加编码
  584. let codesObj = me.getAddCodes(me.currentRationItems);
  585. me.buildCheckCodesCon(me.addCon, codesObj.checkedCodes, codesObj.disabledCodes)
  586. obj.attr('data-target', '#editBianma');
  587. }
  588. else{
  589. obj.attr('data-target', '');
  590. alert("工作内容不能为空!");
  591. }
  592. },
  593. onclickFuncEdit: function (obj) {
  594. let me = jobContentOprObj;
  595. me.buildEditableCodesCon(me.currentRationItems, me.updateCon, me.getUpdateCodes(obj));
  596. },
  597. //获取编码td中的编码
  598. getUpdateCodes: function (jq) {
  599. let rst = [];
  600. let nodes = jq.parent().children();
  601. for(let i = 1, len = nodes.length; i < len; i++){
  602. rst.push(nodes[i].textContent);
  603. }
  604. return rst;
  605. },
  606. //建一个编码checkbox Div
  607. buildCodeOption: function (code, attr) {
  608. let $div = $("<div class='col'><label class='form-check-label'><input class='form-check-input' type='checkbox' value= "+ code +"> "+ code +"</label></div>");
  609. let $checkBox = $div.children().children();
  610. if(attr){
  611. $checkBox.attr(attr, true);
  612. }
  613. return $div;
  614. },
  615. //建修改编码弹窗
  616. buildEditableCodesCon: function (rationItems, container,codes) {
  617. let me = jobContentOprObj;
  618. let codeDivs = [];
  619. container.empty();
  620. for(let i = 0, len = codes.length; i < len; i++){
  621. codeDivs.push({code: codes[i], attr: 'checked'});
  622. }
  623. for(let i = 0, len = rationItems.length; i < len; i++){
  624. if(codes.indexOf(rationItems[i].code) === -1){
  625. if(typeof rationItems[i].jobContent !== 'undefined' && rationItems[i].jobContent.toString().trim().length > 0){
  626. codeDivs.push({code: rationItems[i].code, attr: 'disabled'});
  627. }
  628. else{
  629. codeDivs.push({code: rationItems[i].code, attr: ''});
  630. }
  631. }
  632. }
  633. //排序
  634. codeDivs.sort(function (a, b) {
  635. let rst = 0;
  636. if(a.code > b.code) rst = 1;
  637. else if(a.code < b.code) rst = -1;
  638. return rst;
  639. });
  640. for(let i = 0, len = codeDivs.length; i < len; i++){
  641. container.append(me.buildCodeOption(codeDivs[i].code, codeDivs[i].attr));
  642. }
  643. },
  644. //建勾选编码弹窗
  645. buildCheckCodesCon: function (container, checkedCodes, disabledCodes) {
  646. let me = jobContentOprObj;
  647. container.empty();
  648. for(let i = 0, len = checkedCodes.length; i < len; i++){
  649. let $codeDiv = me.buildCodeOption(checkedCodes[i], 'checked');
  650. container.append($codeDiv);
  651. }
  652. for(let i = 0, len = disabledCodes.length; i < len; i++){
  653. let $codeDiv = me.buildCodeOption(disabledCodes[i], 'disabled');
  654. container.append($codeDiv);
  655. }
  656. },
  657. getAddCodes: function (rationItems) {
  658. let me = jobContentOprObj;
  659. let rst = {checkedCodes: [], disabledCodes: []};
  660. for(let i = 0, len = rationItems.length; i < len; i++){
  661. if(typeof rationItems[i].jobContent !== 'undefined' && rationItems[i].jobContent.toString().trim().length > 0){
  662. rst.disabledCodes.push(rationItems[i].code);
  663. }
  664. else{
  665. rst.checkedCodes.push(rationItems[i].code);
  666. }
  667. }
  668. return rst;
  669. },
  670. //获取选择后的编码窗口的编码及状态
  671. getCodesAfterS: function (checkNodes) {
  672. let rst = {checked: [], unchecked: []};
  673. for(let i = 0, len = checkNodes.length; i < len; i++){
  674. if(checkNodes[i].checked){
  675. rst.checked.push(checkNodes[i].value);
  676. }
  677. else if(!checkNodes[i].checked && !checkNodes[i].disabled){
  678. rst.unchecked.push(checkNodes[i].value);
  679. }
  680. }
  681. return rst;
  682. },
  683. setRadiosChecked: function (situation, radios) {
  684. let me = jobContentOprObj;
  685. if(situation === me.situations.ALL){
  686. radios[0].checked = true;
  687. radios[1].checked = false;
  688. $('#txtareaAll').val(me.currentRationItems.length > 0 ? me.currentRationItems[0].jobContent : '');
  689. me.currentJobContent = me.currentRationItems.length > 0 ? me.currentRationItems[0].jobContent : '';
  690. me.tableAll.show();
  691. me.tablePartial.hide();
  692. }
  693. else if(situation === me.situations.PARTIAL){
  694. radios[0].checked = false;
  695. radios[1].checked = true;
  696. me.tableAll.hide();
  697. me.tablePartial.show();
  698. }
  699. else if(situation === me.situations.NONE){
  700. radios[0].checked = false;
  701. radios[1].checked = false;
  702. me.tableAll.hide();
  703. me.tablePartial.hide();
  704. }
  705. },
  706. //radios是否可用,只有在定额章节树的底层节点才可用
  707. setRadiosDisabled: function (val, radios) {
  708. let me =jobContentOprObj;
  709. if(val){
  710. radios[0].checked = false;
  711. radios[1].checked = false;
  712. me.currentSituation = me.situations.NONE;
  713. }
  714. radios.attr('disabled', val);
  715. },
  716. radiosChange: function (radios, tableAll, tablePartial) {
  717. let me = jobContentOprObj;
  718. radios.change(function () {
  719. let val = $("input[name = 'optionsRadios']:checked").val();
  720. let selectedNode = zTreeOprObj.treeObj.getSelectedNodes()[0];
  721. me.updateSituation(pageOprObj.rationLibId, selectedNode.ID, val, function () {
  722. selectedNode.jobContentSituation = val;
  723. me.currentSituation = val;
  724. if(val === me.situations.ALL){
  725. let updateCodes = [];
  726. for(let i = 0, len = me.currentRationItems.length; i < len; i++){
  727. updateCodes.push(me.currentRationItems[i].code);
  728. }
  729. me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, ''), function () {
  730. me.currentJobContent = '';
  731. $('#txtareaAll').val('');
  732. tableAll.show();
  733. tablePartial.hide();
  734. });
  735. }
  736. else{
  737. me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
  738. tableAll.hide();
  739. tablePartial.show();
  740. }
  741. });
  742. });
  743. },
  744. setTextareaHeight: function (textarea, nodesCount) {
  745. const perHeight = 21.6;
  746. textarea.height(nodesCount * 21.6);
  747. },
  748. bindEvents: function (txtarea) {
  749. let me = jobContentOprObj;
  750. txtarea.bind('change', function () {
  751. let jobContent = txtarea.val();
  752. let jqNodes = txtarea.parent().parent().children()[1].children;
  753. let updateCodes = me.getUpdateCodes(jqNodes);
  754. txtarea.attr('disabled', true);
  755. me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, jobContent), function () {
  756. txtarea.attr('disabled', false);
  757. });
  758. });
  759. },
  760. bindAllEvents: function (txtarea) {
  761. let me = jobContentOprObj;
  762. txtarea.bind('change', function () {
  763. let met = this;
  764. let jobContent = $(met).val();
  765. $(met).attr('disabled', true);
  766. let updateCodes = [];
  767. for(let i = 0, len = me.currentRationItems.length; i < len; i++){
  768. updateCodes.push(me.currentRationItems[i].code);
  769. me.currentRationItems[i].jobContent = jobContent;
  770. }
  771. me.currentJobContent = jobContent;
  772. me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, jobContent), function () {
  773. $(met).attr('disabled', false);
  774. });
  775. });
  776. },
  777. unbindEvents: function (txtarea) {
  778. txtarea.unbind();
  779. },
  780. //定额工作内容相关操作
  781. rationJobContentOpr: function (rationItems) {
  782. let me = jobContentOprObj;
  783. me.setRadiosDisabled(me.currentRationItems.length > 0 ? false : true, me.radios);
  784. me.setRadiosChecked(me.currentSituation, me.radios);
  785. me.buildTablePartial(me.tablePartial, me.getGroup(rationItems));
  786. },
  787. getUpdateArr: function (updateCodes, jobContent) {
  788. let rst = [];
  789. for(let i = 0, len = updateCodes.length; i < len; i++){
  790. rst.push({code: updateCodes[i], jobContent: jobContent});
  791. }
  792. return rst;
  793. },
  794. bindAddConBtn: function () {
  795. let me = jobContentOprObj;
  796. return function () {
  797. let codesObj = me.getCodesAfterS(me.addCon.children().children().children());
  798. let $tbody = $('#tablePartial tbody');
  799. let lastEle = $tbody[0].lastElementChild;
  800. let txtare = lastEle.lastElementChild.children[0];
  801. if(me.currentJobContent.trim().length > 0){//工作内容不为空才可添加编码
  802. let updateArr = me.getUpdateArr(codesObj.checked, me.currentJobContent);
  803. me.updateJobContent(pageOprObj.rationLibId, updateArr, function () {
  804. me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
  805. $(txtare).val('');
  806. });
  807. }
  808. else{
  809. alert("工作内容不能为空!");
  810. }
  811. }
  812. },
  813. bindUpdateConBtn: function () {
  814. let me = jobContentOprObj;
  815. return function () {
  816. let codesObj = me.getCodesAfterS(me.updateCon.children().children().children());
  817. let updateC = me.getUpdateArr(codesObj.checked, me.currentJobContent),
  818. updateUnC = me.getUpdateArr(codesObj.unchecked, ''),
  819. updateArr = updateC.concat(updateUnC);
  820. me.updateJobContent(pageOprObj.rationLibId, updateArr, function () {
  821. me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
  822. });
  823. }
  824. },
  825. //更新缓存的定额
  826. updateRationItem: function (rationItems, updateArr) {
  827. for(let i = 0, len = rationItems.length; i < len; i++){
  828. for(let j = 0, jLen = updateArr.length; j < jLen; j++){
  829. if(rationItems[i].code === updateArr[j].code){
  830. rationItems[i].jobContent = updateArr[j].jobContent;
  831. break;
  832. }
  833. }
  834. }
  835. },
  836. updateJobContent: function (repId, updateArr, callback){
  837. let me = jobContentOprObj;
  838. $.ajax({
  839. type: 'post',
  840. url: 'api/updateJobContent',
  841. data: {lastOpr: userAccount, repId: repId, updateArr: JSON.stringify(updateArr)},
  842. dataType: 'json',
  843. success: function (result) {
  844. if(!result.error){
  845. me.updateRationItem(jobContentOprObj.currentRationItems, updateArr);
  846. callback();
  847. }
  848. }
  849. });
  850. },
  851. updateSituation: function (repId, nodeId, situation, callback) {
  852. let me = jobContentOprObj;
  853. $.ajax({
  854. type: 'post',
  855. url: 'api/updateSituation',
  856. data: {lastOpr: userAccount, repId: repId, nodeId: nodeId, situation: situation},
  857. dataType: 'json',
  858. success: function (result) {
  859. if(!result.error){
  860. if(callback){
  861. callback();
  862. }
  863. }
  864. }
  865. })
  866. }
  867. };
  868. let annotationOprObj = {
  869. situations: {ALL: 'ALL', PARTIAL: 'PARTIAL', NONE: 'NONE'},
  870. currentSituation: null,//本项适用情况
  871. radios: $("input[name = 'fzRadios']"),
  872. fzTableAll: $('#fzTableAll'),
  873. fzTablePartial: $('#fzTablePartial'),
  874. currentOprTr: null,
  875. currentAnnotation: null,
  876. addCon: $('#fzAddCon'),//勾选编码模态框
  877. updateCon: $('#fzUpdateCon'),//编辑编码模态框
  878. clickUpdate: function (txtarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
  879. let me = annotationOprObj;
  880. if(txtarea.is(':focus')){
  881. let annotation = txtarea.val();
  882. if(annotation !== me.currentAnnotation){
  883. jobContentOprObj.preTreeNode.annotation = annotation;
  884. me.unbindEvents(txtarea);
  885. txtarea.blur();
  886. let updateCodes = [];
  887. for(let i = 0, len = jobContentOprObj.currentRationItems.length; i < len; i++){
  888. updateCodes.push(jobContentOprObj.currentRationItems[i].code);
  889. jobContentOprObj.currentRationItems[i].annotation = annotation;
  890. }
  891. me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, annotation), function () {
  892. me.bindAllEvents(txtarea);
  893. });
  894. }
  895. else {
  896. txtarea.blur();
  897. }
  898. }
  899. },
  900. getGroup: function (rationItems) {
  901. let rst = [];//rst = [{jobContent: String, items: Array}]
  902. for(let i = 0, len = rationItems.length; i < len; i++){
  903. if(typeof rationItems[i].annotation !== 'undefined' && rationItems[i].annotation.toString().trim().length > 0){
  904. let isExist = false;
  905. for(let j = 0, jLen = rst.length; j < jLen; j++){
  906. if(rst[j].annotation === rationItems[i].annotation){
  907. isExist = true;
  908. rst[j].items.push(rationItems[i].code);
  909. break;
  910. }
  911. }
  912. if(!isExist){
  913. rst.push({annotation: rationItems[i].annotation, items: [rationItems[i].code]});
  914. }
  915. }
  916. }
  917. return rst;
  918. },
  919. hideTable: function (tableAll, tablePartial) {
  920. if(tableAll){
  921. tableAll.hide();
  922. }
  923. if(tablePartial){
  924. tablePartial.hide();
  925. }
  926. },
  927. //建table
  928. buildTablePartial: function (table, group) {
  929. let me = annotationOprObj;
  930. table.empty();
  931. let $thead = $("<thead><tr><th></th><th>编码</th><th>附注</th>/tr></thead>");
  932. let $tbody = $("<tbody></tbody>");
  933. let count = 1;
  934. for(let i = 0, len = group.length; i < len; i++){
  935. let $newTr = me.getNewTr($tbody, group[i].items, group[i].annotation);
  936. $tbody.append($newTr);
  937. count++;
  938. }
  939. let $trEnd = $("<tr><td>"+ count +"</td><td><a href data-toggle='modal' data-target='#fzEditBianma' class='m-0'>点击勾选编码</a></td><td><textarea class='form-control'></textarea></td></tr>");//勾选行
  940. $($trEnd.children().children()[0]).bind('click', function () {
  941. me.onclickFuncAdd($(this));
  942. me.currentOprTr = $trEnd;
  943. me.currentAnnotation = $(me.currentOprTr.children()[2]).children().val();
  944. });
  945. $tbody.append($trEnd);
  946. table.append($thead);
  947. table.append($tbody);
  948. },
  949. //新增一行tr
  950. getNewTr: function (tbody, codes, jobContent) {
  951. let me = annotationOprObj;
  952. let count = tbody.children().length > 0 ? tbody.children().length : 1;
  953. let $textTd = $("<td></td>");
  954. let $textarea = $("<textarea class='form-control'></textarea>");
  955. $textarea.val(jobContent);
  956. $textTd.append($textarea);
  957. let $tr = $("<tr><td>" + count + "</td><td><a href data-toggle='modal' data-target='#fzEditBianmaQ' class='m-0'>编辑编码</a></td></tr>");
  958. $tr.children().children().bind('click', function () {
  959. me.currentOprTr = $tr;
  960. me.currentAnnotation = $(me.currentOprTr.children()[2]).children().val();
  961. me.onclickFuncEdit($(this));
  962. });
  963. //文本变化;
  964. $textarea.bind('change', function () {
  965. let codes = me.getUpdateCodes($($(this).parent().parent().children()[1]).children());
  966. let annotation = $(this).val();
  967. me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(codes, annotation), function () {
  968. if(annotation.trim().length === 0){
  969. me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
  970. }
  971. });
  972. });
  973. $tr.append($textTd);
  974. for(let i = 0, len = codes.length; i < len; i ++){
  975. let $p = $("<p class='m-0'>" + codes[i] + "</p>");
  976. $tr.children()[1].append($p[0]);
  977. }
  978. me.setTextareaHeight($textarea, codes.length + 1);
  979. return $tr[0];
  980. },
  981. onclickFuncAdd: function (obj) {
  982. let me = annotationOprObj;
  983. let txtarea = $(obj.parent().parent().children().children()[1]);
  984. let annotation = txtarea.val();
  985. if(annotation.trim().length > 0){
  986. let codesObj = me.getAddCodes(jobContentOprObj.currentRationItems);
  987. me.buildCheckCodesCon(me.addCon, codesObj.checkedCodes, codesObj.disabledCodes)
  988. obj.attr('data-target', '#fzEditBianma');
  989. }
  990. else{
  991. obj.attr('data-target', '');
  992. alert("附注不能为空!");
  993. }
  994. },
  995. onclickFuncEdit: function (obj) {
  996. let me = annotationOprObj;
  997. me.buildEditableCodesCon(jobContentOprObj.currentRationItems, me.updateCon, me.getUpdateCodes(obj));
  998. },
  999. //获取编码td中的编码
  1000. getUpdateCodes: function (jq) {
  1001. let rst = [];
  1002. let nodes = jq.parent().children();
  1003. for(let i = 1, len = nodes.length; i < len; i++){
  1004. rst.push(nodes[i].textContent);
  1005. }
  1006. return rst;
  1007. },
  1008. //建一个编码checkbox Div
  1009. buildCodeOption: function (code, attr) {
  1010. let $div = $("<div class='col'><label class='form-check-label'><input class='form-check-input' type='checkbox' value= "+ code +"> "+ code +"</label></div>");
  1011. let $checkBox = $div.children().children();
  1012. if(attr){
  1013. $checkBox.attr(attr, true);
  1014. }
  1015. return $div;
  1016. },
  1017. //建修改编码弹窗
  1018. buildEditableCodesCon: function (rationItems, container, codes) {
  1019. let me = annotationOprObj;
  1020. let codeDivs = [];
  1021. container.empty();
  1022. for(let i = 0, len = codes.length; i < len; i++){
  1023. codeDivs.push({code: codes[i], attr: 'checked'});
  1024. }
  1025. for(let i = 0, len = rationItems.length; i < len; i++){
  1026. if(codes.indexOf(rationItems[i].code) === -1){
  1027. if(typeof rationItems[i].annotation !== 'undefined' && rationItems[i].annotation.toString().trim().length > 0){
  1028. codeDivs.push({code: rationItems[i].code, attr: 'disabled'});
  1029. }
  1030. else{
  1031. codeDivs.push({code: rationItems[i].code, attr: ''});
  1032. }
  1033. }
  1034. }
  1035. //排序
  1036. codeDivs.sort(function (a, b) {
  1037. let rst = 0;
  1038. if(a.code > b.code) rst = 1;
  1039. else if(a.code < b.code) rst = -1;
  1040. return rst;
  1041. });
  1042. for(let i = 0, len = codeDivs.length; i < len; i++){
  1043. container.append(me.buildCodeOption(codeDivs[i].code, codeDivs[i].attr));
  1044. }
  1045. },
  1046. //建勾选编码弹窗
  1047. buildCheckCodesCon: function (container, checkedCodes, disabledCodes) {
  1048. let me = annotationOprObj;
  1049. container.empty();
  1050. for(let i = 0, len = checkedCodes.length; i < len; i++){
  1051. let $codeDiv = me.buildCodeOption(checkedCodes[i], 'checked');
  1052. container.append($codeDiv);
  1053. }
  1054. for(let i = 0, len = disabledCodes.length; i < len; i++){
  1055. let $codeDiv = me.buildCodeOption(disabledCodes[i], 'disabled');
  1056. container.append($codeDiv);
  1057. }
  1058. },
  1059. getAddCodes: function (rationItems) {
  1060. let me = annotationOprObj;
  1061. let rst = {checkedCodes: [], disabledCodes: []};
  1062. for(let i = 0, len = rationItems.length; i < len; i++){
  1063. if(typeof rationItems[i].annotation !== 'undefined' && rationItems[i].annotation.toString().trim().length > 0){
  1064. rst.disabledCodes.push(rationItems[i].code);
  1065. }
  1066. else{
  1067. rst.checkedCodes.push(rationItems[i].code);
  1068. }
  1069. }
  1070. return rst;
  1071. },
  1072. //获取选择后的编码窗口的编码及状态
  1073. getCodesAfterS: function (checkNodes) {
  1074. let rst = {checked: [], unchecked: []};
  1075. for(let i = 0, len = checkNodes.length; i < len; i++){
  1076. if(checkNodes[i].checked){
  1077. rst.checked.push(checkNodes[i].value);
  1078. }
  1079. else if(!checkNodes[i].checked && !checkNodes[i].disabled){
  1080. rst.unchecked.push(checkNodes[i].value);
  1081. }
  1082. }
  1083. return rst;
  1084. },
  1085. setRadiosChecked: function (situation, radios) {
  1086. let me = annotationOprObj;
  1087. if(situation === me.situations.ALL){
  1088. radios[0].checked = true;
  1089. radios[1].checked = false;
  1090. $('#fzTxtareaAll').val(jobContentOprObj.currentRationItems.length > 0 ? jobContentOprObj.currentRationItems[0].annotation : '');
  1091. me.currentAnnotation = jobContentOprObj.currentRationItems.length > 0 ? jobContentOprObj.currentRationItems[0].annotation : '';
  1092. me.fzTableAll.show();
  1093. me.fzTablePartial.hide();
  1094. }
  1095. else if(situation === me.situations.PARTIAL){
  1096. radios[0].checked = false;
  1097. radios[1].checked = true;
  1098. me.fzTableAll.hide();
  1099. me.fzTablePartial.show();
  1100. }
  1101. else if(situation === me.situations.NONE){
  1102. radios[0].checked = false;
  1103. radios[1].checked = false;
  1104. me.fzTableAll.hide();
  1105. me.fzTablePartial.hide();
  1106. }
  1107. },
  1108. //radios是否可用,只有在定额章节树的底层节点才可用
  1109. setRadiosDisabled: function (val, radios) {
  1110. let me =annotationOprObj;
  1111. if(val){
  1112. radios[0].checked = false;
  1113. radios[1].checked = false;
  1114. me.currentSituation = me.situations.NONE;
  1115. }
  1116. radios.attr('disabled', val);
  1117. },
  1118. radiosChange: function (radios, tableAll, tablePartial) {
  1119. let me = annotationOprObj;
  1120. radios.change(function () {
  1121. let val = $("input[name = 'fzRadios']:checked").val();
  1122. let selectedNode = zTreeOprObj.treeObj.getSelectedNodes()[0];
  1123. me.updateAnnoSituation(pageOprObj.rationLibId, selectedNode.ID, val, function () {
  1124. selectedNode.annotationSituation = val;
  1125. me.currentSituation = val;
  1126. if(val === me.situations.ALL){
  1127. let updateCodes = [];
  1128. for(let i = 0, len = jobContentOprObj.currentRationItems.length; i < len; i++){
  1129. updateCodes.push(jobContentOprObj.currentRationItems[i].code);
  1130. }
  1131. me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, ''), function () {
  1132. me.currentAnnotation = '';
  1133. $('#fzTxtareaAll').val('');
  1134. tableAll.show();
  1135. tablePartial.hide();
  1136. });
  1137. }
  1138. else{
  1139. me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
  1140. tableAll.hide();
  1141. tablePartial.show();
  1142. }
  1143. });
  1144. });
  1145. },
  1146. setTextareaHeight: function (textarea, nodesCount) {
  1147. const perHeight = 21.6;
  1148. textarea.height(nodesCount * 21.6);
  1149. },
  1150. bindEvents: function (txtarea) {
  1151. let me = annotationOprObj;
  1152. txtarea.bind('change', function () {
  1153. let annotation = txtarea.val();
  1154. let jqNodes = txtarea.parent().parent().children()[1].children;
  1155. let updateCodes = me.getUpdateCodes(jqNodes);
  1156. txtarea.attr('disabled', true);
  1157. me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, annotation), function () {
  1158. txtarea.attr('disabled', false);
  1159. });
  1160. });
  1161. },
  1162. bindAllEvents: function (txtarea) {
  1163. let me = annotationOprObj;
  1164. txtarea.bind('change', function () {
  1165. let met = this;
  1166. let annotation = $(met).val();
  1167. $(met).attr('disabled', true);
  1168. let updateCodes = [];
  1169. for(let i = 0, len = jobContentOprObj.currentRationItems.length; i < len; i++){
  1170. updateCodes.push(jobContentOprObj.currentRationItems[i].code);
  1171. jobContentOprObj.currentRationItems[i].annotation = annotation;
  1172. }
  1173. me.currentAnnotation = annotation;
  1174. me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, annotation), function () {
  1175. $(met).attr('disabled', false);
  1176. });
  1177. });
  1178. },
  1179. unbindEvents: function (txtarea) {
  1180. txtarea.unbind();
  1181. },
  1182. //定额工作内容相关操作
  1183. rationAnnotationOpr: function (rationItems) {
  1184. let me = annotationOprObj;
  1185. me.setRadiosDisabled(rationItems.length > 0 ? false : true, me.radios);
  1186. me.setRadiosChecked(me.currentSituation, me.radios);
  1187. me.buildTablePartial(me.fzTablePartial, me.getGroup(rationItems));
  1188. },
  1189. getUpdateArr: function (updateCodes, annotation) {
  1190. let rst = [];
  1191. for(let i = 0, len = updateCodes.length; i < len; i++){
  1192. rst.push({code: updateCodes[i], annotation: annotation});
  1193. }
  1194. return rst;
  1195. },
  1196. bindAddConBtn: function () {
  1197. let me = annotationOprObj;
  1198. return function () {
  1199. let codesObj = me.getCodesAfterS(me.addCon.children().children().children());
  1200. let $tbody = $('#fzTablePartial tbody');
  1201. let lastEle = $tbody[0].lastElementChild;
  1202. let txtare = lastEle.lastElementChild.children[0];
  1203. if(me.currentAnnotation.trim().length > 0){//工作内容不为空才可添加编码
  1204. let updateArr = me.getUpdateArr(codesObj.checked, me.currentAnnotation);
  1205. me.updateAnnotation(pageOprObj.rationLibId, updateArr, function () {
  1206. me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
  1207. $(txtare).val('');
  1208. });
  1209. }
  1210. else{
  1211. alert("附注不能为空!");
  1212. }
  1213. }
  1214. },
  1215. bindUpdateConBtn: function () {
  1216. let me = annotationOprObj;
  1217. return function () {
  1218. let codesObj = me.getCodesAfterS(me.updateCon.children().children().children());
  1219. let updateC = me.getUpdateArr(codesObj.checked, me.currentAnnotation),
  1220. updateUnC = me.getUpdateArr(codesObj.unchecked, ''),
  1221. updateArr = updateC.concat(updateUnC);
  1222. me.updateAnnotation(pageOprObj.rationLibId, updateArr, function () {
  1223. me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
  1224. });
  1225. }
  1226. },
  1227. //更新缓存的定额
  1228. updateRationItem: function (rationItems, updateArr) {
  1229. for(let i = 0, len = rationItems.length; i < len; i++){
  1230. for(let j = 0, jLen = updateArr.length; j < jLen; j++){
  1231. if(rationItems[i].code === updateArr[j].code){
  1232. rationItems[i].annotation = updateArr[j].annotation;
  1233. break;
  1234. }
  1235. }
  1236. }
  1237. },
  1238. updateAnnotation: function (repId, updateArr, callback){
  1239. let me = annotationOprObj;
  1240. $.ajax({
  1241. type: 'post',
  1242. url: 'api/updateAnnotation',
  1243. data: {lastOpr: userAccount, repId: repId, updateArr: JSON.stringify(updateArr)},
  1244. dataType: 'json',
  1245. success: function (result) {
  1246. if(!result.error){
  1247. me.updateRationItem(jobContentOprObj.currentRationItems, updateArr);
  1248. callback();
  1249. }
  1250. }
  1251. });
  1252. },
  1253. updateAnnoSituation: function (repId, nodeId, situation, callback) {
  1254. let me = annotationOprObj;
  1255. $.ajax({
  1256. type: 'post',
  1257. url: 'api/updateAnnoSituation',
  1258. data: {lastOpr: userAccount, repId: repId, nodeId: nodeId, situation: situation},
  1259. dataType: 'json',
  1260. success: function (result) {
  1261. if(!result.error){
  1262. if(callback){
  1263. callback();
  1264. }
  1265. }
  1266. }
  1267. })
  1268. }
  1269. };