section_tree.js 54 KB

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