section_tree.js 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  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.workBook.getSheet(0).clearSelection();
  347. rationOprObj.getRationItems(sectionID);
  348. } else {
  349. jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios);
  350. jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial'));
  351. annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);
  352. annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial'));
  353. sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1);
  354. sheetCommonObj.shieldAllCells(rationOprObj.workBook.getSheet(0));
  355. }
  356. sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
  357. sheetCommonObj.shieldAllCells(rationGLJOprObj.sheet);
  358. rationGLJOprObj.sheet.getParent().focus(false);
  359. }
  360. };
  361. //定额章节节点说明、计算规则
  362. let explanatoryOprObj = {
  363. preTreeNode: null,
  364. currentTreeNode: null,//定额章节树节点
  365. currentExplanation: null,
  366. currentRuleText: null,
  367. setAttribute: function (preNode, currentNode, explanation, ruleText) {
  368. let me = explanatoryOprObj;
  369. me.preTreeNode = preNode;
  370. me.currentTreeNode = currentNode;
  371. me.currentExplanation = explanation;
  372. me.currentRuleText = ruleText;
  373. },
  374. clickUpdate: function (exarea, ruarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
  375. let me = explanatoryOprObj;
  376. if(exarea.is(':focus')){
  377. let explanation = exarea.val();
  378. if(explanation !== me.currentExplanation){
  379. me.preTreeNode.explanation = explanation;
  380. me.unbindEvents(exarea, ruarea);
  381. exarea.blur();
  382. me.updateExplanation(me.preTreeNode.rationRepId, me.preTreeNode.ID, explanation, function () {
  383. me.bindEvents(exarea, ruarea);
  384. });
  385. }
  386. }
  387. if(ruarea.is(':focus')){
  388. let ruleText = ruarea.val();
  389. if(ruleText !== me.currentRuleText){
  390. me.preTreeNode.ruleText = ruleText;
  391. me.unbindEvents(exarea, ruarea);
  392. ruarea.blur();
  393. me.updateRuleText(me.preTreeNode.rationRepId, me.preTreeNode.ID, ruleText, function () {
  394. me.bindEvents(exarea, ruarea);
  395. });
  396. }
  397. }
  398. },
  399. unbindEvents: function (exarea, ruarea) {
  400. exarea.unbind();
  401. ruarea.unbind();
  402. },
  403. bindEvents: function (exarea, ruarea) {
  404. let me = explanatoryOprObj;
  405. exarea.bind('change', function () {
  406. let explanation = exarea.val();
  407. let node = me.currentTreeNode;
  408. exarea.attr('disabled', true);
  409. me.updateExplanation(node.rationRepId, node.ID, explanation, function () {
  410. node.explanation = explanation;
  411. exarea.attr('disabled', false);
  412. });
  413. });
  414. ruarea.bind('change', function () {
  415. let ruleText = ruarea.val();
  416. let node = me.currentTreeNode;
  417. ruarea.attr('disabled', true);
  418. me.updateRuleText(node.rationRepId, node.ID, ruleText, function () {
  419. node.ruleText = ruleText;
  420. ruarea.attr('disabled', false);
  421. });
  422. });
  423. },
  424. showText: function (exarea, ruarea, explanation, ruleText) {
  425. exarea.val(explanation && explanation !== 'undefined' ? explanation : '');
  426. ruarea.val(ruleText && ruleText !== 'undefined' ? ruleText : '');
  427. },
  428. //更新说明
  429. updateExplanation: function (repId, nodeId, explanation, callback) {
  430. $.ajax({
  431. type: 'post',
  432. url: 'api/updateExplanation',
  433. data: {lastOpr: userAccount, repId: repId, nodeId: nodeId, explanation: explanation},
  434. dataType: 'json',
  435. success: function () {
  436. callback();
  437. }
  438. });
  439. },
  440. //更新计算规则
  441. updateRuleText: function (repId, nodeId, explanation, callback) {
  442. $.ajax({
  443. type: 'post',
  444. url: 'api/updateRuleText',
  445. data: {lastOpr: userAccount, repId: repId, nodeId: nodeId, explanation: explanation},
  446. dataType: 'json',
  447. success: function () {
  448. callback();
  449. }
  450. });
  451. }
  452. };
  453. //工作内容
  454. let jobContentOprObj = {
  455. situations: {ALL: 'ALL', PARTIAL: 'PARTIAL', NONE: 'NONE'},//所有ALL(包括未定义本项工作内容)、部分PARTIA,不可用NONE(无定额时)
  456. currentSituation: null,//本项适用情况
  457. currentTreeNode: null,
  458. preTreeNode: null,
  459. radios: $("input[name = 'optionsRadios']"),
  460. tableAll: $('#tableAll'),
  461. tablePartial: $('#tablePartial'),
  462. currentOprTr: null,
  463. currentJobContent: null,
  464. currentRationItems: null,
  465. addCon: $('#addCon'),//勾选编码模态框
  466. updateCon: $('#updateCon'),//编辑编码模态框
  467. setAttribute: function (preNode, currentNode) {
  468. let me = jobContentOprObj;
  469. me.preTreeNode = preNode;
  470. me.currentTreeNode = currentNode;
  471. },
  472. clickUpdate: function (txtarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
  473. let me = jobContentOprObj;
  474. if(txtarea.is(':focus')){
  475. let jobContent = txtarea.val();
  476. if(jobContent !== me.currentJobContent){
  477. me.preTreeNode.jobContent = jobContent;
  478. me.unbindEvents(txtarea);
  479. txtarea.blur();
  480. let updateCodes = [];
  481. for(let i = 0, len = me.currentRationItems.length; i < len; i++){
  482. updateCodes.push(me.currentRationItems[i].code);
  483. me.currentRationItems[i].jobContent = jobContent;
  484. }
  485. me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, jobContent), function () {
  486. me.bindAllEvents(txtarea);
  487. })
  488. }
  489. else {
  490. txtarea.blur();
  491. }
  492. }
  493. },
  494. getGroup: function (rationItems) {
  495. let rst = [];//rst = [{jobContent: String, items: Array}]
  496. for(let i = 0, len = rationItems.length; i < len; i++){
  497. if(typeof rationItems[i].jobContent !== 'undefined' && rationItems[i].jobContent.toString().trim().length > 0){
  498. let isExist = false;
  499. for(let j = 0, jLen = rst.length; j < jLen; j++){
  500. if(rst[j].jobContent === rationItems[i].jobContent){
  501. isExist = true;
  502. rst[j].items.push(rationItems[i].code);
  503. break;
  504. }
  505. }
  506. if(!isExist){
  507. rst.push({jobContent: rationItems[i].jobContent, items: [rationItems[i].code]});
  508. }
  509. }
  510. }
  511. return rst;
  512. },
  513. hideTable: function (tableAll, tablePartial) {
  514. if(tableAll){
  515. tableAll.hide();
  516. }
  517. if(tablePartial){
  518. tablePartial.hide();
  519. }
  520. },
  521. //建table
  522. buildTablePartial: function (table, group) {
  523. let me = jobContentOprObj;
  524. table.empty();
  525. let $thead = $("<thead><tr><th></th><th>编码</th><th>工作内容</th>/tr></thead>");
  526. let $tbody = $("<tbody></tbody>");
  527. let count = 1;
  528. for(let i = 0, len = group.length; i < len; i++){
  529. let $newTr = me.getNewTr($tbody, group[i].items, group[i].jobContent);
  530. $tbody.append($newTr);
  531. count++;
  532. }
  533. 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>");//勾选行
  534. $($trEnd.children().children()[0]).bind('click', function () {
  535. me.onclickFuncAdd($(this));
  536. me.currentOprTr = $trEnd;
  537. me.currentJobContent = $(me.currentOprTr.children()[2]).children().val();
  538. });
  539. $tbody.append($trEnd);
  540. table.append($thead);
  541. table.append($tbody);
  542. },
  543. //新增一行tr
  544. getNewTr: function (tbody, codes, jobContent) {
  545. let me = jobContentOprObj;
  546. let count = tbody.children().length > 0 ? tbody.children().length : 1;
  547. let $textTd = $("<td></td>");
  548. let $textarea = $("<textarea class='form-control'></textarea>");
  549. $textarea.val(jobContent);
  550. $textTd.append($textarea);
  551. let $tr = $("<tr><td>" + count + "</td><td><a href data-toggle='modal' data-target='#editBianmaQ' class='m-0'>编辑编码</a></td></tr>");
  552. $tr.children().children().bind('click', function () {
  553. me.currentOprTr = $tr;
  554. me.currentJobContent = $(me.currentOprTr.children()[2]).children().val();
  555. me.onclickFuncEdit($(this));
  556. });
  557. //文本变化;
  558. $textarea.bind('change', function () {
  559. let codes = me.getUpdateCodes($($(this).parent().parent().children()[1]).children());
  560. let jobContent = $(this).val();
  561. me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(codes, jobContent), function () {
  562. if(jobContent.trim().length === 0){
  563. me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
  564. }
  565. });
  566. });
  567. $tr.append($textTd);
  568. for(let i = 0, len = codes.length; i < len; i ++){
  569. let $p = $("<p class='m-0'>" + codes[i] + "</p>");
  570. $tr.children()[1].append($p[0]);
  571. }
  572. me.setTextareaHeight($textarea, codes.length + 1);
  573. return $tr[0];
  574. },
  575. onclickFuncAdd: function (obj) {
  576. let me = jobContentOprObj;
  577. let txtarea = $(obj.parent().parent().children().children()[1]);
  578. let jobContent = txtarea.val();
  579. if(jobContent.trim().length > 0){//工作内容不为空才可添加编码
  580. let codesObj = me.getAddCodes(me.currentRationItems);
  581. me.buildCheckCodesCon(me.addCon, codesObj.checkedCodes, codesObj.disabledCodes)
  582. obj.attr('data-target', '#editBianma');
  583. }
  584. else{
  585. obj.attr('data-target', '');
  586. alert("工作内容不能为空!");
  587. }
  588. },
  589. onclickFuncEdit: function (obj) {
  590. let me = jobContentOprObj;
  591. me.buildEditableCodesCon(me.currentRationItems, me.updateCon, me.getUpdateCodes(obj));
  592. },
  593. //获取编码td中的编码
  594. getUpdateCodes: function (jq) {
  595. let rst = [];
  596. let nodes = jq.parent().children();
  597. for(let i = 1, len = nodes.length; i < len; i++){
  598. rst.push(nodes[i].textContent);
  599. }
  600. return rst;
  601. },
  602. //建一个编码checkbox Div
  603. buildCodeOption: function (code, attr) {
  604. let $div = $("<div class='col'><label class='form-check-label'><input class='form-check-input' type='checkbox' value= "+ code +"> "+ code +"</label></div>");
  605. let $checkBox = $div.children().children();
  606. if(attr){
  607. $checkBox.attr(attr, true);
  608. }
  609. return $div;
  610. },
  611. //建修改编码弹窗
  612. buildEditableCodesCon: function (rationItems, container,codes) {
  613. let me = jobContentOprObj;
  614. let codeDivs = [];
  615. container.empty();
  616. for(let i = 0, len = codes.length; i < len; i++){
  617. codeDivs.push({code: codes[i], attr: 'checked'});
  618. }
  619. for(let i = 0, len = rationItems.length; i < len; i++){
  620. if(codes.indexOf(rationItems[i].code) === -1){
  621. if(typeof rationItems[i].jobContent !== 'undefined' && rationItems[i].jobContent.toString().trim().length > 0){
  622. codeDivs.push({code: rationItems[i].code, attr: 'disabled'});
  623. }
  624. else{
  625. codeDivs.push({code: rationItems[i].code, attr: ''});
  626. }
  627. }
  628. }
  629. //排序
  630. codeDivs.sort(function (a, b) {
  631. let rst = 0;
  632. if(a.code > b.code) rst = 1;
  633. else if(a.code < b.code) rst = -1;
  634. return rst;
  635. });
  636. for(let i = 0, len = codeDivs.length; i < len; i++){
  637. container.append(me.buildCodeOption(codeDivs[i].code, codeDivs[i].attr));
  638. }
  639. },
  640. //建勾选编码弹窗
  641. buildCheckCodesCon: function (container, checkedCodes, disabledCodes) {
  642. let me = jobContentOprObj;
  643. container.empty();
  644. for(let i = 0, len = checkedCodes.length; i < len; i++){
  645. let $codeDiv = me.buildCodeOption(checkedCodes[i], 'checked');
  646. container.append($codeDiv);
  647. }
  648. for(let i = 0, len = disabledCodes.length; i < len; i++){
  649. let $codeDiv = me.buildCodeOption(disabledCodes[i], 'disabled');
  650. container.append($codeDiv);
  651. }
  652. },
  653. getAddCodes: function (rationItems) {
  654. let me = jobContentOprObj;
  655. let rst = {checkedCodes: [], disabledCodes: []};
  656. for(let i = 0, len = rationItems.length; i < len; i++){
  657. if(typeof rationItems[i].jobContent !== 'undefined' && rationItems[i].jobContent.toString().trim().length > 0){
  658. rst.disabledCodes.push(rationItems[i].code);
  659. }
  660. else{
  661. rst.checkedCodes.push(rationItems[i].code);
  662. }
  663. }
  664. return rst;
  665. },
  666. //获取选择后的编码窗口的编码及状态
  667. getCodesAfterS: function (checkNodes) {
  668. let rst = {checked: [], unchecked: []};
  669. for(let i = 0, len = checkNodes.length; i < len; i++){
  670. if(checkNodes[i].checked){
  671. rst.checked.push(checkNodes[i].value);
  672. }
  673. else if(!checkNodes[i].checked && !checkNodes[i].disabled){
  674. rst.unchecked.push(checkNodes[i].value);
  675. }
  676. }
  677. return rst;
  678. },
  679. setRadiosChecked: function (situation, radios) {
  680. let me = jobContentOprObj;
  681. if(situation === me.situations.ALL){
  682. radios[0].checked = true;
  683. radios[1].checked = false;
  684. $('#txtareaAll').val(me.currentRationItems.length > 0 ? me.currentRationItems[0].jobContent : '');
  685. me.currentJobContent = me.currentRationItems.length > 0 ? me.currentRationItems[0].jobContent : '';
  686. me.tableAll.show();
  687. me.tablePartial.hide();
  688. }
  689. else if(situation === me.situations.PARTIAL){
  690. radios[0].checked = false;
  691. radios[1].checked = true;
  692. me.tableAll.hide();
  693. me.tablePartial.show();
  694. }
  695. else if(situation === me.situations.NONE){
  696. radios[0].checked = false;
  697. radios[1].checked = false;
  698. me.tableAll.hide();
  699. me.tablePartial.hide();
  700. }
  701. },
  702. //radios是否可用,只有在定额章节树的底层节点才可用
  703. setRadiosDisabled: function (val, radios) {
  704. let me =jobContentOprObj;
  705. if(val){
  706. radios[0].checked = false;
  707. radios[1].checked = false;
  708. me.currentSituation = me.situations.NONE;
  709. }
  710. radios.attr('disabled', val);
  711. },
  712. radiosChange: function (radios, tableAll, tablePartial) {
  713. let me = jobContentOprObj;
  714. radios.change(function () {
  715. let val = $("input[name = 'optionsRadios']:checked").val();
  716. let selectedNode = zTreeOprObj.treeObj.getSelectedNodes()[0];
  717. me.updateSituation(pageOprObj.rationLibId, selectedNode.ID, val, function () {
  718. selectedNode.jobContentSituation = val;
  719. me.currentSituation = val;
  720. if(val === me.situations.ALL){
  721. let updateCodes = [];
  722. for(let i = 0, len = me.currentRationItems.length; i < len; i++){
  723. updateCodes.push(me.currentRationItems[i].code);
  724. }
  725. me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, ''), function () {
  726. me.currentJobContent = '';
  727. $('#txtareaAll').val('');
  728. tableAll.show();
  729. tablePartial.hide();
  730. });
  731. }
  732. else{
  733. me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
  734. tableAll.hide();
  735. tablePartial.show();
  736. }
  737. });
  738. });
  739. },
  740. setTextareaHeight: function (textarea, nodesCount) {
  741. const perHeight = 21.6;
  742. textarea.height(nodesCount * 21.6);
  743. },
  744. bindEvents: function (txtarea) {
  745. let me = jobContentOprObj;
  746. txtarea.bind('change', function () {
  747. let jobContent = txtarea.val();
  748. let jqNodes = txtarea.parent().parent().children()[1].children;
  749. let updateCodes = me.getUpdateCodes(jqNodes);
  750. txtarea.attr('disabled', true);
  751. me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, jobContent), function () {
  752. txtarea.attr('disabled', false);
  753. });
  754. });
  755. },
  756. bindAllEvents: function (txtarea) {
  757. let me = jobContentOprObj;
  758. txtarea.bind('change', function () {
  759. let met = this;
  760. let jobContent = $(met).val();
  761. $(met).attr('disabled', true);
  762. let updateCodes = [];
  763. for(let i = 0, len = me.currentRationItems.length; i < len; i++){
  764. updateCodes.push(me.currentRationItems[i].code);
  765. me.currentRationItems[i].jobContent = jobContent;
  766. }
  767. me.currentJobContent = jobContent;
  768. me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, jobContent), function () {
  769. $(met).attr('disabled', false);
  770. });
  771. });
  772. },
  773. unbindEvents: function (txtarea) {
  774. txtarea.unbind();
  775. },
  776. //定额工作内容相关操作
  777. rationJobContentOpr: function (rationItems) {
  778. let me = jobContentOprObj;
  779. me.setRadiosDisabled(me.currentRationItems.length > 0 ? false : true, me.radios);
  780. me.setRadiosChecked(me.currentSituation, me.radios);
  781. me.buildTablePartial(me.tablePartial, me.getGroup(rationItems));
  782. },
  783. getUpdateArr: function (updateCodes, jobContent) {
  784. let rst = [];
  785. for(let i = 0, len = updateCodes.length; i < len; i++){
  786. rst.push({code: updateCodes[i], jobContent: jobContent});
  787. }
  788. return rst;
  789. },
  790. bindAddConBtn: function () {
  791. let me = jobContentOprObj;
  792. return function () {
  793. let codesObj = me.getCodesAfterS(me.addCon.children().children().children());
  794. let $tbody = $('#tablePartial tbody');
  795. let lastEle = $tbody[0].lastElementChild;
  796. let txtare = lastEle.lastElementChild.children[0];
  797. if(me.currentJobContent.trim().length > 0){//工作内容不为空才可添加编码
  798. let updateArr = me.getUpdateArr(codesObj.checked, me.currentJobContent);
  799. me.updateJobContent(pageOprObj.rationLibId, updateArr, function () {
  800. me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
  801. $(txtare).val('');
  802. });
  803. }
  804. else{
  805. alert("工作内容不能为空!");
  806. }
  807. }
  808. },
  809. bindUpdateConBtn: function () {
  810. let me = jobContentOprObj;
  811. return function () {
  812. let codesObj = me.getCodesAfterS(me.updateCon.children().children().children());
  813. let updateC = me.getUpdateArr(codesObj.checked, me.currentJobContent),
  814. updateUnC = me.getUpdateArr(codesObj.unchecked, ''),
  815. updateArr = updateC.concat(updateUnC);
  816. me.updateJobContent(pageOprObj.rationLibId, updateArr, function () {
  817. me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
  818. });
  819. }
  820. },
  821. //更新缓存的定额
  822. updateRationItem: function (rationItems, updateArr) {
  823. for(let i = 0, len = rationItems.length; i < len; i++){
  824. for(let j = 0, jLen = updateArr.length; j < jLen; j++){
  825. if(rationItems[i].code === updateArr[j].code){
  826. rationItems[i].jobContent = updateArr[j].jobContent;
  827. break;
  828. }
  829. }
  830. }
  831. },
  832. updateJobContent: function (repId, updateArr, callback){
  833. let me = jobContentOprObj;
  834. $.ajax({
  835. type: 'post',
  836. url: 'api/updateJobContent',
  837. data: {lastOpr: userAccount, repId: repId, updateArr: JSON.stringify(updateArr)},
  838. dataType: 'json',
  839. success: function (result) {
  840. if(!result.error){
  841. me.updateRationItem(jobContentOprObj.currentRationItems, updateArr);
  842. callback();
  843. }
  844. }
  845. });
  846. },
  847. updateSituation: function (repId, nodeId, situation, callback) {
  848. let me = jobContentOprObj;
  849. $.ajax({
  850. type: 'post',
  851. url: 'api/updateSituation',
  852. data: {lastOpr: userAccount, repId: repId, nodeId: nodeId, situation: situation},
  853. dataType: 'json',
  854. success: function (result) {
  855. if(!result.error){
  856. if(callback){
  857. callback();
  858. }
  859. }
  860. }
  861. })
  862. }
  863. };
  864. let annotationOprObj = {
  865. situations: {ALL: 'ALL', PARTIAL: 'PARTIAL', NONE: 'NONE'},
  866. currentSituation: null,//本项适用情况
  867. radios: $("input[name = 'fzRadios']"),
  868. fzTableAll: $('#fzTableAll'),
  869. fzTablePartial: $('#fzTablePartial'),
  870. currentOprTr: null,
  871. currentAnnotation: null,
  872. addCon: $('#fzAddCon'),//勾选编码模态框
  873. updateCon: $('#fzUpdateCon'),//编辑编码模态框
  874. clickUpdate: function (txtarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
  875. let me = annotationOprObj;
  876. if(txtarea.is(':focus')){
  877. let annotation = txtarea.val();
  878. if(annotation !== me.currentAnnotation){
  879. jobContentOprObj.preTreeNode.annotation = annotation;
  880. me.unbindEvents(txtarea);
  881. txtarea.blur();
  882. let updateCodes = [];
  883. for(let i = 0, len = jobContentOprObj.currentRationItems.length; i < len; i++){
  884. updateCodes.push(jobContentOprObj.currentRationItems[i].code);
  885. jobContentOprObj.currentRationItems[i].annotation = annotation;
  886. }
  887. me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, annotation), function () {
  888. me.bindAllEvents(txtarea);
  889. });
  890. }
  891. else {
  892. txtarea.blur();
  893. }
  894. }
  895. },
  896. getGroup: function (rationItems) {
  897. let rst = [];//rst = [{jobContent: String, items: Array}]
  898. for(let i = 0, len = rationItems.length; i < len; i++){
  899. if(typeof rationItems[i].annotation !== 'undefined' && rationItems[i].annotation.toString().trim().length > 0){
  900. let isExist = false;
  901. for(let j = 0, jLen = rst.length; j < jLen; j++){
  902. if(rst[j].annotation === rationItems[i].annotation){
  903. isExist = true;
  904. rst[j].items.push(rationItems[i].code);
  905. break;
  906. }
  907. }
  908. if(!isExist){
  909. rst.push({annotation: rationItems[i].annotation, items: [rationItems[i].code]});
  910. }
  911. }
  912. }
  913. return rst;
  914. },
  915. hideTable: function (tableAll, tablePartial) {
  916. if(tableAll){
  917. tableAll.hide();
  918. }
  919. if(tablePartial){
  920. tablePartial.hide();
  921. }
  922. },
  923. //建table
  924. buildTablePartial: function (table, group) {
  925. let me = annotationOprObj;
  926. table.empty();
  927. let $thead = $("<thead><tr><th></th><th>编码</th><th>附注</th>/tr></thead>");
  928. let $tbody = $("<tbody></tbody>");
  929. let count = 1;
  930. for(let i = 0, len = group.length; i < len; i++){
  931. let $newTr = me.getNewTr($tbody, group[i].items, group[i].annotation);
  932. $tbody.append($newTr);
  933. count++;
  934. }
  935. 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>");//勾选行
  936. $($trEnd.children().children()[0]).bind('click', function () {
  937. me.onclickFuncAdd($(this));
  938. me.currentOprTr = $trEnd;
  939. me.currentAnnotation = $(me.currentOprTr.children()[2]).children().val();
  940. });
  941. $tbody.append($trEnd);
  942. table.append($thead);
  943. table.append($tbody);
  944. },
  945. //新增一行tr
  946. getNewTr: function (tbody, codes, jobContent) {
  947. let me = annotationOprObj;
  948. let count = tbody.children().length > 0 ? tbody.children().length : 1;
  949. let $textTd = $("<td></td>");
  950. let $textarea = $("<textarea class='form-control'></textarea>");
  951. $textarea.val(jobContent);
  952. $textTd.append($textarea);
  953. let $tr = $("<tr><td>" + count + "</td><td><a href data-toggle='modal' data-target='#fzEditBianmaQ' class='m-0'>编辑编码</a></td></tr>");
  954. $tr.children().children().bind('click', function () {
  955. me.currentOprTr = $tr;
  956. me.currentAnnotation = $(me.currentOprTr.children()[2]).children().val();
  957. me.onclickFuncEdit($(this));
  958. });
  959. //文本变化;
  960. $textarea.bind('change', function () {
  961. let codes = me.getUpdateCodes($($(this).parent().parent().children()[1]).children());
  962. let annotation = $(this).val();
  963. me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(codes, annotation), function () {
  964. if(annotation.trim().length === 0){
  965. me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
  966. }
  967. });
  968. });
  969. $tr.append($textTd);
  970. for(let i = 0, len = codes.length; i < len; i ++){
  971. let $p = $("<p class='m-0'>" + codes[i] + "</p>");
  972. $tr.children()[1].append($p[0]);
  973. }
  974. me.setTextareaHeight($textarea, codes.length + 1);
  975. return $tr[0];
  976. },
  977. onclickFuncAdd: function (obj) {
  978. let me = annotationOprObj;
  979. let txtarea = $(obj.parent().parent().children().children()[1]);
  980. let annotation = txtarea.val();
  981. if(annotation.trim().length > 0){
  982. let codesObj = me.getAddCodes(jobContentOprObj.currentRationItems);
  983. me.buildCheckCodesCon(me.addCon, codesObj.checkedCodes, codesObj.disabledCodes)
  984. obj.attr('data-target', '#fzEditBianma');
  985. }
  986. else{
  987. obj.attr('data-target', '');
  988. alert("附注不能为空!");
  989. }
  990. },
  991. onclickFuncEdit: function (obj) {
  992. let me = annotationOprObj;
  993. me.buildEditableCodesCon(jobContentOprObj.currentRationItems, me.updateCon, me.getUpdateCodes(obj));
  994. },
  995. //获取编码td中的编码
  996. getUpdateCodes: function (jq) {
  997. let rst = [];
  998. let nodes = jq.parent().children();
  999. for(let i = 1, len = nodes.length; i < len; i++){
  1000. rst.push(nodes[i].textContent);
  1001. }
  1002. return rst;
  1003. },
  1004. //建一个编码checkbox Div
  1005. buildCodeOption: function (code, attr) {
  1006. let $div = $("<div class='col'><label class='form-check-label'><input class='form-check-input' type='checkbox' value= "+ code +"> "+ code +"</label></div>");
  1007. let $checkBox = $div.children().children();
  1008. if(attr){
  1009. $checkBox.attr(attr, true);
  1010. }
  1011. return $div;
  1012. },
  1013. //建修改编码弹窗
  1014. buildEditableCodesCon: function (rationItems, container, codes) {
  1015. let me = annotationOprObj;
  1016. let codeDivs = [];
  1017. container.empty();
  1018. for(let i = 0, len = codes.length; i < len; i++){
  1019. codeDivs.push({code: codes[i], attr: 'checked'});
  1020. }
  1021. for(let i = 0, len = rationItems.length; i < len; i++){
  1022. if(codes.indexOf(rationItems[i].code) === -1){
  1023. if(typeof rationItems[i].annotation !== 'undefined' && rationItems[i].annotation.toString().trim().length > 0){
  1024. codeDivs.push({code: rationItems[i].code, attr: 'disabled'});
  1025. }
  1026. else{
  1027. codeDivs.push({code: rationItems[i].code, attr: ''});
  1028. }
  1029. }
  1030. }
  1031. //排序
  1032. codeDivs.sort(function (a, b) {
  1033. let rst = 0;
  1034. if(a.code > b.code) rst = 1;
  1035. else if(a.code < b.code) rst = -1;
  1036. return rst;
  1037. });
  1038. for(let i = 0, len = codeDivs.length; i < len; i++){
  1039. container.append(me.buildCodeOption(codeDivs[i].code, codeDivs[i].attr));
  1040. }
  1041. },
  1042. //建勾选编码弹窗
  1043. buildCheckCodesCon: function (container, checkedCodes, disabledCodes) {
  1044. let me = annotationOprObj;
  1045. container.empty();
  1046. for(let i = 0, len = checkedCodes.length; i < len; i++){
  1047. let $codeDiv = me.buildCodeOption(checkedCodes[i], 'checked');
  1048. container.append($codeDiv);
  1049. }
  1050. for(let i = 0, len = disabledCodes.length; i < len; i++){
  1051. let $codeDiv = me.buildCodeOption(disabledCodes[i], 'disabled');
  1052. container.append($codeDiv);
  1053. }
  1054. },
  1055. getAddCodes: function (rationItems) {
  1056. let me = annotationOprObj;
  1057. let rst = {checkedCodes: [], disabledCodes: []};
  1058. for(let i = 0, len = rationItems.length; i < len; i++){
  1059. if(typeof rationItems[i].annotation !== 'undefined' && rationItems[i].annotation.toString().trim().length > 0){
  1060. rst.disabledCodes.push(rationItems[i].code);
  1061. }
  1062. else{
  1063. rst.checkedCodes.push(rationItems[i].code);
  1064. }
  1065. }
  1066. return rst;
  1067. },
  1068. //获取选择后的编码窗口的编码及状态
  1069. getCodesAfterS: function (checkNodes) {
  1070. let rst = {checked: [], unchecked: []};
  1071. for(let i = 0, len = checkNodes.length; i < len; i++){
  1072. if(checkNodes[i].checked){
  1073. rst.checked.push(checkNodes[i].value);
  1074. }
  1075. else if(!checkNodes[i].checked && !checkNodes[i].disabled){
  1076. rst.unchecked.push(checkNodes[i].value);
  1077. }
  1078. }
  1079. return rst;
  1080. },
  1081. setRadiosChecked: function (situation, radios) {
  1082. let me = annotationOprObj;
  1083. if(situation === me.situations.ALL){
  1084. radios[0].checked = true;
  1085. radios[1].checked = false;
  1086. $('#fzTxtareaAll').val(jobContentOprObj.currentRationItems.length > 0 ? jobContentOprObj.currentRationItems[0].annotation : '');
  1087. me.currentAnnotation = jobContentOprObj.currentRationItems.length > 0 ? jobContentOprObj.currentRationItems[0].annotation : '';
  1088. me.fzTableAll.show();
  1089. me.fzTablePartial.hide();
  1090. }
  1091. else if(situation === me.situations.PARTIAL){
  1092. radios[0].checked = false;
  1093. radios[1].checked = true;
  1094. me.fzTableAll.hide();
  1095. me.fzTablePartial.show();
  1096. }
  1097. else if(situation === me.situations.NONE){
  1098. radios[0].checked = false;
  1099. radios[1].checked = false;
  1100. me.fzTableAll.hide();
  1101. me.fzTablePartial.hide();
  1102. }
  1103. },
  1104. //radios是否可用,只有在定额章节树的底层节点才可用
  1105. setRadiosDisabled: function (val, radios) {
  1106. let me =annotationOprObj;
  1107. if(val){
  1108. radios[0].checked = false;
  1109. radios[1].checked = false;
  1110. me.currentSituation = me.situations.NONE;
  1111. }
  1112. radios.attr('disabled', val);
  1113. },
  1114. radiosChange: function (radios, tableAll, tablePartial) {
  1115. let me = annotationOprObj;
  1116. radios.change(function () {
  1117. let val = $("input[name = 'fzRadios']:checked").val();
  1118. let selectedNode = zTreeOprObj.treeObj.getSelectedNodes()[0];
  1119. me.updateAnnoSituation(pageOprObj.rationLibId, selectedNode.ID, val, function () {
  1120. selectedNode.annotationSituation = val;
  1121. me.currentSituation = val;
  1122. if(val === me.situations.ALL){
  1123. let updateCodes = [];
  1124. for(let i = 0, len = jobContentOprObj.currentRationItems.length; i < len; i++){
  1125. updateCodes.push(jobContentOprObj.currentRationItems[i].code);
  1126. }
  1127. me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, ''), function () {
  1128. me.currentAnnotation = '';
  1129. $('#fzTxtareaAll').val('');
  1130. tableAll.show();
  1131. tablePartial.hide();
  1132. });
  1133. }
  1134. else{
  1135. me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
  1136. tableAll.hide();
  1137. tablePartial.show();
  1138. }
  1139. });
  1140. });
  1141. },
  1142. setTextareaHeight: function (textarea, nodesCount) {
  1143. const perHeight = 21.6;
  1144. textarea.height(nodesCount * 21.6);
  1145. },
  1146. bindEvents: function (txtarea) {
  1147. let me = annotationOprObj;
  1148. txtarea.bind('change', function () {
  1149. let annotation = txtarea.val();
  1150. let jqNodes = txtarea.parent().parent().children()[1].children;
  1151. let updateCodes = me.getUpdateCodes(jqNodes);
  1152. txtarea.attr('disabled', true);
  1153. me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, annotation), function () {
  1154. txtarea.attr('disabled', false);
  1155. });
  1156. });
  1157. },
  1158. bindAllEvents: function (txtarea) {
  1159. let me = annotationOprObj;
  1160. txtarea.bind('change', function () {
  1161. let met = this;
  1162. let annotation = $(met).val();
  1163. $(met).attr('disabled', true);
  1164. let updateCodes = [];
  1165. for(let i = 0, len = jobContentOprObj.currentRationItems.length; i < len; i++){
  1166. updateCodes.push(jobContentOprObj.currentRationItems[i].code);
  1167. jobContentOprObj.currentRationItems[i].annotation = annotation;
  1168. }
  1169. me.currentAnnotation = annotation;
  1170. me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, annotation), function () {
  1171. $(met).attr('disabled', false);
  1172. });
  1173. });
  1174. },
  1175. unbindEvents: function (txtarea) {
  1176. txtarea.unbind();
  1177. },
  1178. //定额工作内容相关操作
  1179. rationAnnotationOpr: function (rationItems) {
  1180. let me = annotationOprObj;
  1181. me.setRadiosDisabled(rationItems.length > 0 ? false : true, me.radios);
  1182. me.setRadiosChecked(me.currentSituation, me.radios);
  1183. me.buildTablePartial(me.fzTablePartial, me.getGroup(rationItems));
  1184. },
  1185. getUpdateArr: function (updateCodes, annotation) {
  1186. let rst = [];
  1187. for(let i = 0, len = updateCodes.length; i < len; i++){
  1188. rst.push({code: updateCodes[i], annotation: annotation});
  1189. }
  1190. return rst;
  1191. },
  1192. bindAddConBtn: function () {
  1193. let me = annotationOprObj;
  1194. return function () {
  1195. let codesObj = me.getCodesAfterS(me.addCon.children().children().children());
  1196. let $tbody = $('#fzTablePartial tbody');
  1197. let lastEle = $tbody[0].lastElementChild;
  1198. let txtare = lastEle.lastElementChild.children[0];
  1199. if(me.currentAnnotation.trim().length > 0){//工作内容不为空才可添加编码
  1200. let updateArr = me.getUpdateArr(codesObj.checked, me.currentAnnotation);
  1201. me.updateAnnotation(pageOprObj.rationLibId, updateArr, function () {
  1202. me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
  1203. $(txtare).val('');
  1204. });
  1205. }
  1206. else{
  1207. alert("附注不能为空!");
  1208. }
  1209. }
  1210. },
  1211. bindUpdateConBtn: function () {
  1212. let me = annotationOprObj;
  1213. return function () {
  1214. let codesObj = me.getCodesAfterS(me.updateCon.children().children().children());
  1215. let updateC = me.getUpdateArr(codesObj.checked, me.currentAnnotation),
  1216. updateUnC = me.getUpdateArr(codesObj.unchecked, ''),
  1217. updateArr = updateC.concat(updateUnC);
  1218. me.updateAnnotation(pageOprObj.rationLibId, updateArr, function () {
  1219. me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
  1220. });
  1221. }
  1222. },
  1223. //更新缓存的定额
  1224. updateRationItem: function (rationItems, updateArr) {
  1225. for(let i = 0, len = rationItems.length; i < len; i++){
  1226. for(let j = 0, jLen = updateArr.length; j < jLen; j++){
  1227. if(rationItems[i].code === updateArr[j].code){
  1228. rationItems[i].annotation = updateArr[j].annotation;
  1229. break;
  1230. }
  1231. }
  1232. }
  1233. },
  1234. updateAnnotation: function (repId, updateArr, callback){
  1235. let me = annotationOprObj;
  1236. $.ajax({
  1237. type: 'post',
  1238. url: 'api/updateAnnotation',
  1239. data: {lastOpr: userAccount, repId: repId, updateArr: JSON.stringify(updateArr)},
  1240. dataType: 'json',
  1241. success: function (result) {
  1242. if(!result.error){
  1243. me.updateRationItem(jobContentOprObj.currentRationItems, updateArr);
  1244. callback();
  1245. }
  1246. }
  1247. });
  1248. },
  1249. updateAnnoSituation: function (repId, nodeId, situation, callback) {
  1250. let me = annotationOprObj;
  1251. $.ajax({
  1252. type: 'post',
  1253. url: 'api/updateAnnoSituation',
  1254. data: {lastOpr: userAccount, repId: repId, nodeId: nodeId, situation: situation},
  1255. dataType: 'json',
  1256. success: function (result) {
  1257. if(!result.error){
  1258. if(callback){
  1259. callback();
  1260. }
  1261. }
  1262. }
  1263. })
  1264. }
  1265. };