12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277 |
- /**
- * Created by Tony on 2017/4/27.
- */
- var pageOprObj = {
- rationLibName : null,
- rationLibId : null,
- initPage : function() {
- var me = this, rationLibId = getQueryString("repository"),//获取定额库参数
- rationLibName = storageUtil.getSessionCache("RationGrp","repositoryID_" + rationLibId);
- if (rationLibName) {
- var html = $("#rationname")[0].outerHTML;
- html = html.replace("XXX定额库", rationLibName);
- $("#rationname")[0].outerHTML = html;
- me.rationLibName = rationLibName;
- me.rationLibId = rationLibId;
- zTreeOprObj.getRationTree(rationLibId);
- //job
- jobContentOprObj.radiosChange(jobContentOprObj.radios, jobContentOprObj.tableAll, jobContentOprObj.tablePartial);
- $('#addConBtn').click(jobContentOprObj.bindAddConBtn());
- $('#updateConBtn').click(jobContentOprObj.bindUpdateConBtn());
- jobContentOprObj.bindAllEvents($('#txtareaAll'));
- //fz
- annotationOprObj.radiosChange(annotationOprObj.radios, annotationOprObj.fzTableAll, annotationOprObj.fzTablePartial);
- $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn());
- $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn());
- annotationOprObj.bindAllEvents($('#fzTxtareaAll'));
- }
- }
- }
- var zTreeOprObj = {
- treeObj: null,
- getRationTree: function(rationLibId){
- var me = this;
- $.ajax({
- type:"POST",
- url:"api/getRationTree",
- data:{"rationLibId": rationLibId},
- dataType:"json",
- cache:false,
- timeout:20000,
- success:function(result,textStatus,status){
- if(status.status == 200) {
- if (result.data.length > 0) {
- storageUtil.setSessionCache("RationGrp","repositoryID",result.data[0].rationRepId);
- }
- zTreeHelper.createTree(result.data, setting, "rationChapterTree", me);
- //初始化,初始节点点击
- let rootNode = me.treeObj.getNodes()[0];
- if(rootNode && rootNode.isFirstNode){
- me.treeObj.selectNode(rootNode);
- me.onClick(null, 'rationChapterTree', rootNode);
- }
- explanatoryOprObj.bindEvents($('#explanationShow'), $('#ruleTextShow'));
- }
- },
- error:function(err){
- alert(err.responseJSON.error);
- }
- })
- },
- addRootNode: function() {
- $('#addRootA').css("opacity", "0.2");
- $('#addRootA').addClass("disabled");
- var me = zTreeOprObj, rawNode = {ParentID: -1, NextSiblingID: -1, name: "新增节点"}, lastNodeId = -1;
- if (me.treeObj) {
- var rootNodes = me.treeObj.getNodes();
- if (rootNodes.length > 0) {
- lastNodeId = rootNodes[rootNodes.length - 1].ID;
- }
- }
- me.addNewNode(rawNode, lastNodeId, function(err, rst){
- if (!(err)) {
- if(rootNodes.length > 0){
- rootNodes[rootNodes.length - 1].NextSiblingID = rst.data.ID;
- }
- var newNodes = [], isSilent = false;
- newNodes.push({ rationRepId: rst.data.rationRepId, Previous_ID: lastNodeId, ID: rst.data.ID, ParentID:-1, NextSiblingID:-1, name:"新增节点",isParent:false, items:[]});
- if (me.treeObj) {
- me.treeObj.addNodes(null, -1, newNodes, isSilent);
- } else {
- me.treeObj = $.fn.zTree.init($("#rationChapterTree"), setting, newNodes);
- }
- $('#addRootA').css("opacity", "");
- $('#addRootA').removeClass("disabled");
- }
- });
- },
- addNewNode : function(rawNode, lastNodeId, callback){
- $.ajax({
- type:"POST",
- url:"api/createNewNode",
- data:{"rationLibId":pageOprObj.rationLibId,"lastNodeId": lastNodeId, "lastOpr": userAccount, "rawNodeData": JSON.stringify(rawNode)},
- dataType:"json",
- cache:false,
- timeout:1000,
- success: function(result,textStatus,status){
- callback(false, result);
- },
- error:function(err){
- callback(err);
- }
- })
- },
- beforeRename: function(treeId, treeNode, newName, isCancel) {
- if (newName.length == 0) {
- return false;
- }
- return true;
- },
- onRename : function(e, treeId, treeNode, isCancel) {
- var nodes = [];
- nodes.push(treeNode);
- zTreeOprObj.updateNodes(nodes);
- },
- onBeforeRemove: function(treeId, treeNode){
- var nodeIds = [], preNode = treeNode.getPreNode(), preNodeId = -1;
- if (preNode) {
- preNodeId = preNode.ID;
- }
- private_fetchAllSubItems = function(pItem){
- nodeIds.push(pItem.ID);
- if (pItem.items && pItem.items.length > 0) {
- for (var i = 0; i < pItem.items.length; i++) {
- private_fetchAllSubItems(pItem.items[i]);
- }
- }
- };
- nodeIds.push(treeNode.ID);
- for (var i = 0; i < treeNode.items.length; i++) {
- private_fetchAllSubItems(treeNode.items[i]);
- }
- $.ajax({
- type:"POST",
- url:"api/deleteNodes",
- data:{"repId": pageOprObj.rationLibId, "lastOpr": userAccount, "nodes": JSON.stringify(nodeIds), "preNodeId": preNodeId, "preNodeNextId": treeNode.NextSiblingID},
- dataType:"json",
- cache:false,
- timeout:5000,
- success:function(result,textStatus,status){
- var pNode = treeNode.getParentNode();
- if (pNode && pNode.items && pNode.items.length == 1) {
- pNode.isParent = false;
- }
- },
- error:function(){
- }
- });
- return true;
- },
- onRemove: function(e, treeId, treeNode){
- var me = zTreeOprObj, pNode = me.treeObj.getNodeByTId(treeNode.parentTId);
- if (pNode && pNode.items && pNode.items.length == 0) {
- pNode.isParent = false;
- me.treeObj.refresh();
- //me.treeObj.updateNode(pNode, false); //这方法有后遗症,多次操作后会造成节点新增子节点时,父节点icon显示不正确
- }
- },
- beforeDrop: function (treeId, treeNodes, targetNode, moveType) {
- let me = zTreeOprObj;
- if(moveType){
- me.treeObj.setting.edit.enable = false;
- let treeNode = treeNodes[0], updateNodes = [];
- //升级
- if(treeNode.level !== targetNode.level && moveType === 'prev'){
- if(treeNode.Previous_ID !== -1){
- treeNode.getPreNode().NextSiblingID = treeNode.NextSiblingID;
- updateNodes.push(treeNode.getPreNode());
- }
- if(treeNode.NextSiblingID !== -1){
- treeNode.getNextNode().Previous_ID = treeNode.Previous_ID;
- }
- if(targetNode.Previous_ID !== -1){
- targetNode.getPreNode().NextSiblingID = treeNode.ID;
- updateNodes.push(targetNode.getPreNode());
- }
- treeNode.ParentID = targetNode.getParentNode() ? targetNode.getParentNode().ID : -1;
- treeNode.NextSiblingID = targetNode.ID;
- treeNode.Previous_ID = targetNode.Previous_ID;
- targetNode.Previous_ID = treeNode.ID;
- updateNodes.push(treeNode);
- //updateNodes.push(targetNode);
- }
- //升级
- else if(treeNode.level !== targetNode.level && moveType === 'next'){
- if(treeNode.Previous_ID !== -1){
- treeNode.getPreNode().NextSiblingID = treeNode.NextSiblingID;
- updateNodes.push(treeNode.getPreNode());
- }
- if(treeNode.NextSiblingID !== -1){
- treeNode.getNextNode().Previous_ID = treeNode.Previous_ID;
- }
- if(targetNode.NextSiblingID !== -1){
- targetNode.getNextNode().Previous_ID = treeNode.ID;
- }
- treeNode.NextSiblingID = targetNode.NextSiblingID;
- treeNode.Previous_ID = targetNode.ID;
- treeNode.ParentID = targetNode.getParentNode() ? targetNode.getParentNode().ID : -1;
- targetNode.NextSiblingID = treeNode.ID;
- updateNodes.push(treeNode);
- updateNodes.push(targetNode);
- }
- //上移
- else if(treeNode.level === targetNode.level && moveType === 'prev'){
- if(targetNode.Previous_ID !== -1){
- let targetPrev = me.treeObj.getNodeByParam('ID', targetNode.Previous_ID, null);
- targetPrev.NextSiblingID = treeNode.ID;
- updateNodes.push(targetPrev);
- }
- targetNode.NextSiblingID = treeNode.NextSiblingID;
- treeNode.NextSiblingID = targetNode.ID;
- treeNode.Previous_ID = targetNode.Previous_ID;
- targetNode.Previous_ID = treeNode.ID;
- updateNodes.push(treeNode);
- updateNodes.push(targetNode);
- }
- //下移
- else if(treeNode.level === targetNode.level && moveType === 'next'){
- if(treeNode.Previous_ID !== -1){
- let treeNodePrev = me.treeObj.getNodeByParam('ID', treeNode.Previous_ID, null);
- treeNodePrev.NextSiblingID = targetNode.ID;
- updateNodes.push(treeNodePrev);
- }
- treeNode.Previous_ID = targetNode.ID;
- treeNode.NextSiblingID = targetNode.NextSiblingID;
- targetNode.Previous_ID = treeNode.Previous_ID;
- targetNode.NextSiblingID = treeNode.ID;
- updateNodes.push(treeNode);
- updateNodes.push(targetNode);
- }
- //
- else if(moveType === 'inner'){
- if( treeNode.Previous_ID !== -1){
- treeNode.getPreNode().NextSiblingID = treeNode.NextSiblingID;
- updateNodes.push(treeNode.getPreNode());
- }
- if(treeNode.NextSiblingID !== -1){
- treeNode.getNextNode().Previous_ID = treeNode.Previous_ID;
- }
- if(targetNode.items.length > 0){
- targetNode.items[targetNode.items.length -1].NextSiblingID = treeNode.ID;
- treeNode.Previous_ID = targetNode.items[targetNode.items.length -1].ID;
- updateNodes.push(targetNode.items[targetNode.items.length -1]);
- }
- else{
- treeNode.Previous_ID = -1;
- }
- treeNode.ParentID = targetNode.ID;
- treeNode.NextSiblingID = -1;
- updateNodes.push(treeNode);
- }
- if(updateNodes.length > 0){
- me.updateNodes(updateNodes, function () {
- me.treeObj.setting.edit.enable= true;
- });
- }
- }
- },
- onDrop: function (event, treeId, treeNodes, targetNode, moveType) {
- },
- updateNodes: function(nodes, callback){
- if (nodes && nodes.length > 0) {
- var reqData = []
- for (var i = 0; i < nodes.length; i++) {
- var node = {};
- node.rationRepId = nodes[i].rationRepId;
- node.ID = nodes[i].ID;
- node.ParentID = nodes[i].ParentID;
- node.NextSiblingID = nodes[i].NextSiblingID;
- node.name = nodes[i].name;
- if (nodes[i].__v != null) node.__v = nodes[i].__v + 1
- else node.__v = 0;
- reqData.push(node);
- }
- $.ajax({
- type:"POST",
- url:"api/updateNodes",
- data:{"repId": pageOprObj.rationLibId,"lastOpr": userAccount, "nodes": JSON.stringify(reqData)},
- dataType:"json",
- cache:false,
- timeout:5000,
- success:function(result,textStatus,status){
- if(callback){
- callback();
- }
- console.log(status + ' : ' + result);
- },
- error:function(){
- }
- })
- }
- },
- addHoverDom: function(treeId, treeNode) {
- if(typeof treeNode.doing !== 'undefined' && treeNode.doing){
- return false;
- }
- hoverOpr();
- function hoverOpr(){
- var me = zTreeOprObj, sObj = $("#" + treeNode.tId + "_span");
- if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
- var addStr = "<span class='button add' id='addBtn_" + treeNode.tId + "' title='新增子节点' onfocus='this.blur();'></span>";
- sObj.after(addStr);
- var btn = $("#addBtn_"+treeNode.tId);
- if (btn) btn.bind("click", function(){
- treeNode.doing = true;
- var rawNode = {ParentID: treeNode.ID, NextSiblingID: -1, name: "新增子节点"}, lastNodeId = -1, lastNode = null;
- if (treeNode.items.length > 0) {
- lastNodeId = treeNode.items[treeNode.items.length - 1].ID;
- lastNode = treeNode.items[treeNode.items.length - 1];
- }
- zTreeOprObj.addNewNode(rawNode, lastNodeId, function(err, rst){
- if (!(err)) {
- var newNodes = [], isSilent = false;
- if (lastNode) {
- lastNode.NextSiblingID = rst.ID;
- }
- newNodes.push({ rationRepId: rst.data.rationRepId, ID: rst.data.ID, Previous_ID: lastNodeId, ParentID: rst.data.ParentID, NextSiblingID:-1, name:"新增子节点",isParent:false, items:[]});
- treeNode.isParent = true;
- if (me.treeObj) {
- me.treeObj.addNodes(treeNode, -1, newNodes, isSilent);
- } else {
- me.treeObj = $.fn.zTree.init($("#rationChapterTree"), setting, newNodes);
- }
- }
- treeNode.doing = false;
- hoverOpr();
- });
- });
- }
- },
- removeHoverDom: function(treeId, treeNode) {
- $("#addBtn_"+treeNode.tId).unbind().remove();
- },
- onClick: function(event,treeId,treeNode) {
- explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : treeNode, treeNode, treeNode.explanation, treeNode.ruleText);
- explanatoryOprObj.clickUpdate($('#explanationShow'), $('#ruleTextShow'));
- explanatoryOprObj.showText($('#explanationShow'), $('#ruleTextShow'), treeNode.explanation, treeNode.ruleText);
- //job
- jobContentOprObj.currentSituation = typeof treeNode.jobContentSituation !== 'undefined'? treeNode.jobContentSituation : jobContentOprObj.situations.NONE;
- jobContentOprObj.setAttribute(jobContentOprObj.currentTreeNode ? jobContentOprObj.currentTreeNode : treeNode, treeNode);
- jobContentOprObj.clickUpdate($('#txtareaAll'));
- //fz
- annotationOprObj.currentSituation = typeof treeNode.annotationSituation !== 'undefined'? treeNode.annotationSituation : annotationOprObj.situations.NONE;
- annotationOprObj.clickUpdate($('#fzTxtareaAll'));
- var sectionID = treeNode.ID;
- if (!(treeNode.items) || treeNode.items.length == 0) {
- rationOprObj.canRations = true;
- rationOprObj.workBook.getSheet(0).clearSelection();
- rationOprObj.getRationItems(sectionID);
- } else {
- rationOprObj.canRations = false;
- rationOprObj.currentSectionId = sectionID;
- rationOprObj.workBook.getSheet(0).setRowCount(30);
- sheetCommonObj.setDynamicCombo(rationOprObj.workBook.getSheet(0), 0, 2, rationOprObj.workBook.getSheet(0).getRowCount(), rationUnits, 10, false);
- jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios);
- jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial'));
- annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);
- annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial'));
- sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1);
- }
- sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);
- rationGLJOprObj.sheet.getParent().focus(false);
- }
- };
- //定额章节节点说明、计算规则
- let explanatoryOprObj = {
- preTreeNode: null,
- currentTreeNode: null,//定额章节树节点
- currentExplanation: null,
- currentRuleText: null,
- setAttribute: function (preNode, currentNode, explanation, ruleText) {
- let me = explanatoryOprObj;
- me.preTreeNode = preNode;
- me.currentTreeNode = currentNode;
- me.currentExplanation = explanation;
- me.currentRuleText = ruleText;
- },
- clickUpdate: function (exarea, ruarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
- let me = explanatoryOprObj;
- if(exarea.is(':focus')){
- let explanation = exarea.val();
- if(explanation !== me.currentExplanation){
- me.preTreeNode.explanation = explanation;
- me.unbindEvents(exarea, ruarea);
- exarea.blur();
- me.updateExplanation(me.preTreeNode.rationRepId, me.preTreeNode.ID, explanation, function () {
- me.bindEvents(exarea, ruarea);
- });
- }
- }
- if(ruarea.is(':focus')){
- let ruleText = ruarea.val();
- if(ruleText !== me.currentRuleText){
- me.preTreeNode.ruleText = ruleText;
- me.unbindEvents(exarea, ruarea);
- ruarea.blur();
- me.updateRuleText(me.preTreeNode.rationRepId, me.preTreeNode.ID, ruleText, function () {
- me.bindEvents(exarea, ruarea);
- });
- }
- }
- },
- unbindEvents: function (exarea, ruarea) {
- exarea.unbind();
- ruarea.unbind();
- },
- bindEvents: function (exarea, ruarea) {
- let me = explanatoryOprObj;
- exarea.bind('change', function () {
- let explanation = exarea.val();
- let node = me.currentTreeNode;
- exarea.attr('disabled', true);
- me.updateExplanation(node.rationRepId, node.ID, explanation, function () {
- node.explanation = explanation;
- exarea.attr('disabled', false);
- });
- });
- ruarea.bind('change', function () {
- let ruleText = ruarea.val();
- let node = me.currentTreeNode;
- ruarea.attr('disabled', true);
- me.updateRuleText(node.rationRepId, node.ID, ruleText, function () {
- node.ruleText = ruleText;
- ruarea.attr('disabled', false);
- });
- });
- },
- showText: function (exarea, ruarea, explanation, ruleText) {
- exarea.val(explanation && explanation !== 'undefined' ? explanation : '');
- ruarea.val(ruleText && ruleText !== 'undefined' ? ruleText : '');
- },
- //更新说明
- updateExplanation: function (repId, nodeId, explanation, callback) {
- $.ajax({
- type: 'post',
- url: 'api/updateExplanation',
- data: {lastOpr: userAccount, repId: repId, nodeId: nodeId, explanation: explanation},
- dataType: 'json',
- success: function () {
- callback();
- }
- });
- },
- //更新计算规则
- updateRuleText: function (repId, nodeId, explanation, callback) {
- $.ajax({
- type: 'post',
- url: 'api/updateRuleText',
- data: {lastOpr: userAccount, repId: repId, nodeId: nodeId, explanation: explanation},
- dataType: 'json',
- success: function () {
- callback();
- }
- });
- }
- };
- //工作内容
- let jobContentOprObj = {
- situations: {ALL: 'ALL', PARTIAL: 'PARTIAL', NONE: 'NONE'},//所有ALL(包括未定义本项工作内容)、部分PARTIA,不可用NONE(无定额时)
- currentSituation: null,//本项适用情况
- currentTreeNode: null,
- preTreeNode: null,
- radios: $("input[name = 'optionsRadios']"),
- tableAll: $('#tableAll'),
- tablePartial: $('#tablePartial'),
- currentOprTr: null,
- currentJobContent: null,
- currentRationItems: null,
- addCon: $('#addCon'),//勾选编码模态框
- updateCon: $('#updateCon'),//编辑编码模态框
- setAttribute: function (preNode, currentNode) {
- let me = jobContentOprObj;
- me.preTreeNode = preNode;
- me.currentTreeNode = currentNode;
- },
- clickUpdate: function (txtarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
- let me = jobContentOprObj;
- if(txtarea.is(':focus')){
- let jobContent = txtarea.val();
- if(jobContent !== me.currentJobContent){
- me.preTreeNode.jobContent = jobContent;
- me.unbindEvents(txtarea);
- txtarea.blur();
- let updateCodes = [];
- for(let i = 0, len = me.currentRationItems.length; i < len; i++){
- updateCodes.push(me.currentRationItems[i].code);
- me.currentRationItems[i].jobContent = jobContent;
- }
- me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, jobContent), function () {
- me.bindAllEvents(txtarea);
- })
- }
- else {
- txtarea.blur();
- }
- }
- },
- getGroup: function (rationItems) {
- let rst = [];//rst = [{jobContent: String, items: Array}]
- for(let i = 0, len = rationItems.length; i < len; i++){
- if(typeof rationItems[i].jobContent !== 'undefined' && rationItems[i].jobContent.toString().trim().length > 0){
- let isExist = false;
- for(let j = 0, jLen = rst.length; j < jLen; j++){
- if(rst[j].jobContent === rationItems[i].jobContent){
- isExist = true;
- rst[j].items.push(rationItems[i].code);
- break;
- }
- }
- if(!isExist){
- rst.push({jobContent: rationItems[i].jobContent, items: [rationItems[i].code]});
- }
- }
- }
- return rst;
- },
- hideTable: function (tableAll, tablePartial) {
- if(tableAll){
- tableAll.hide();
- }
- if(tablePartial){
- tablePartial.hide();
- }
- },
- //建table
- buildTablePartial: function (table, group) {
- let me = jobContentOprObj;
- table.empty();
- let $thead = $("<thead><tr><th></th><th>编码</th><th>工作内容</th>/tr></thead>");
- let $tbody = $("<tbody></tbody>");
- let count = 1;
- for(let i = 0, len = group.length; i < len; i++){
- let $newTr = me.getNewTr($tbody, group[i].items, group[i].jobContent);
- $tbody.append($newTr);
- count++;
- }
- 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>");//勾选行
- $($trEnd.children().children()[0]).bind('click', function () {
- me.onclickFuncAdd($(this));
- me.currentOprTr = $trEnd;
- me.currentJobContent = $(me.currentOprTr.children()[2]).children().val();
- });
- $tbody.append($trEnd);
- table.append($thead);
- table.append($tbody);
- },
- //新增一行tr
- getNewTr: function (tbody, codes, jobContent) {
- let me = jobContentOprObj;
- let count = tbody.children().length > 0 ? tbody.children().length : 1;
- let $textTd = $("<td></td>");
- let $textarea = $("<textarea class='form-control'></textarea>");
- $textarea.val(jobContent);
- $textTd.append($textarea);
- let $tr = $("<tr><td>" + count + "</td><td><a href data-toggle='modal' data-target='#editBianmaQ' class='m-0'>编辑编码</a></td></tr>");
- $tr.children().children().bind('click', function () {
- me.currentOprTr = $tr;
- me.currentJobContent = $(me.currentOprTr.children()[2]).children().val();
- me.onclickFuncEdit($(this));
- });
- //文本变化;
- $textarea.bind('change', function () {
- let codes = me.getUpdateCodes($($(this).parent().parent().children()[1]).children());
- let jobContent = $(this).val();
- me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(codes, jobContent), function () {
- if(jobContent.trim().length === 0){
- me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
- }
- });
- });
- $tr.append($textTd);
- for(let i = 0, len = codes.length; i < len; i ++){
- let $p = $("<p class='m-0'>" + codes[i] + "</p>");
- $tr.children()[1].append($p[0]);
- }
- me.setTextareaHeight($textarea, codes.length + 1);
- return $tr[0];
- },
- onclickFuncAdd: function (obj) {
- let me = jobContentOprObj;
- let txtarea = $(obj.parent().parent().children().children()[1]);
- let jobContent = txtarea.val();
- if(jobContent.trim().length > 0){//工作内容不为空才可添加编码
- let codesObj = me.getAddCodes(me.currentRationItems);
- me.buildCheckCodesCon(me.addCon, codesObj.checkedCodes, codesObj.disabledCodes)
- obj.attr('data-target', '#editBianma');
- }
- else{
- obj.attr('data-target', '');
- alert("工作内容不能为空!");
- }
- },
- onclickFuncEdit: function (obj) {
- let me = jobContentOprObj;
- me.buildEditableCodesCon(me.currentRationItems, me.updateCon, me.getUpdateCodes(obj));
- },
- //获取编码td中的编码
- getUpdateCodes: function (jq) {
- let rst = [];
- let nodes = jq.parent().children();
- for(let i = 1, len = nodes.length; i < len; i++){
- rst.push(nodes[i].textContent);
- }
- return rst;
- },
- //建一个编码checkbox Div
- buildCodeOption: function (code, attr) {
- let $div = $("<div class='col'><label class='form-check-label'><input class='form-check-input' type='checkbox' value= "+ code +"> "+ code +"</label></div>");
- let $checkBox = $div.children().children();
- if(attr){
- $checkBox.attr(attr, true);
- }
- return $div;
- },
- //建修改编码弹窗
- buildEditableCodesCon: function (rationItems, container,codes) {
- let me = jobContentOprObj;
- let codeDivs = [];
- container.empty();
- for(let i = 0, len = codes.length; i < len; i++){
- codeDivs.push({code: codes[i], attr: 'checked'});
- }
- for(let i = 0, len = rationItems.length; i < len; i++){
- if(codes.indexOf(rationItems[i].code) === -1){
- if(typeof rationItems[i].jobContent !== 'undefined' && rationItems[i].jobContent.toString().trim().length > 0){
- codeDivs.push({code: rationItems[i].code, attr: 'disabled'});
- }
- else{
- codeDivs.push({code: rationItems[i].code, attr: ''});
- }
- }
- }
- //排序
- codeDivs.sort(function (a, b) {
- let rst = 0;
- if(a.code > b.code) rst = 1;
- else if(a.code < b.code) rst = -1;
- return rst;
- });
- for(let i = 0, len = codeDivs.length; i < len; i++){
- container.append(me.buildCodeOption(codeDivs[i].code, codeDivs[i].attr));
- }
- },
- //建勾选编码弹窗
- buildCheckCodesCon: function (container, checkedCodes, disabledCodes) {
- let me = jobContentOprObj;
- container.empty();
- for(let i = 0, len = checkedCodes.length; i < len; i++){
- let $codeDiv = me.buildCodeOption(checkedCodes[i], 'checked');
- container.append($codeDiv);
- }
- for(let i = 0, len = disabledCodes.length; i < len; i++){
- let $codeDiv = me.buildCodeOption(disabledCodes[i], 'disabled');
- container.append($codeDiv);
- }
- },
- getAddCodes: function (rationItems) {
- let me = jobContentOprObj;
- let rst = {checkedCodes: [], disabledCodes: []};
- for(let i = 0, len = rationItems.length; i < len; i++){
- if(typeof rationItems[i].jobContent !== 'undefined' && rationItems[i].jobContent.toString().trim().length > 0){
- rst.disabledCodes.push(rationItems[i].code);
- }
- else{
- rst.checkedCodes.push(rationItems[i].code);
- }
- }
- return rst;
- },
- //获取选择后的编码窗口的编码及状态
- getCodesAfterS: function (checkNodes) {
- let rst = {checked: [], unchecked: []};
- for(let i = 0, len = checkNodes.length; i < len; i++){
- if(checkNodes[i].checked){
- rst.checked.push(checkNodes[i].value);
- }
- else if(!checkNodes[i].checked && !checkNodes[i].disabled){
- rst.unchecked.push(checkNodes[i].value);
- }
- }
- return rst;
- },
- setRadiosChecked: function (situation, radios) {
- let me = jobContentOprObj;
- if(situation === me.situations.ALL){
- radios[0].checked = true;
- radios[1].checked = false;
- $('#txtareaAll').val(me.currentRationItems.length > 0 ? me.currentRationItems[0].jobContent : '');
- me.currentJobContent = me.currentRationItems.length > 0 ? me.currentRationItems[0].jobContent : '';
- me.tableAll.show();
- me.tablePartial.hide();
- }
- else if(situation === me.situations.PARTIAL){
- radios[0].checked = false;
- radios[1].checked = true;
- me.tableAll.hide();
- me.tablePartial.show();
- }
- else if(situation === me.situations.NONE){
- radios[0].checked = false;
- radios[1].checked = false;
- me.tableAll.hide();
- me.tablePartial.hide();
- }
- },
- //radios是否可用,只有在定额章节树的底层节点才可用
- setRadiosDisabled: function (val, radios) {
- let me =jobContentOprObj;
- if(val){
- radios[0].checked = false;
- radios[1].checked = false;
- me.currentSituation = me.situations.NONE;
- }
- radios.attr('disabled', val);
- },
- radiosChange: function (radios, tableAll, tablePartial) {
- let me = jobContentOprObj;
- radios.change(function () {
- let val = $("input[name = 'optionsRadios']:checked").val();
- let selectedNode = zTreeOprObj.treeObj.getSelectedNodes()[0];
- me.updateSituation(pageOprObj.rationLibId, selectedNode.ID, val, function () {
- selectedNode.jobContentSituation = val;
- me.currentSituation = val;
- if(val === me.situations.ALL){
- let updateCodes = [];
- for(let i = 0, len = me.currentRationItems.length; i < len; i++){
- updateCodes.push(me.currentRationItems[i].code);
- }
- me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, ''), function () {
- me.currentJobContent = '';
- $('#txtareaAll').val('');
- tableAll.show();
- tablePartial.hide();
- });
- }
- else{
- me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
- tableAll.hide();
- tablePartial.show();
- }
- });
- });
- },
- setTextareaHeight: function (textarea, nodesCount) {
- const perHeight = 21.6;
- textarea.height(nodesCount * 21.6);
- },
- bindEvents: function (txtarea) {
- let me = jobContentOprObj;
- txtarea.bind('change', function () {
- let jobContent = txtarea.val();
- let jqNodes = txtarea.parent().parent().children()[1].children;
- let updateCodes = me.getUpdateCodes(jqNodes);
- txtarea.attr('disabled', true);
- me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, jobContent), function () {
- txtarea.attr('disabled', false);
- });
- });
- },
- bindAllEvents: function (txtarea) {
- let me = jobContentOprObj;
- txtarea.bind('change', function () {
- let met = this;
- let jobContent = $(met).val();
- $(met).attr('disabled', true);
- let updateCodes = [];
- for(let i = 0, len = me.currentRationItems.length; i < len; i++){
- updateCodes.push(me.currentRationItems[i].code);
- me.currentRationItems[i].jobContent = jobContent;
- }
- me.currentJobContent = jobContent;
- me.updateJobContent(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, jobContent), function () {
- $(met).attr('disabled', false);
- });
- });
- },
- unbindEvents: function (txtarea) {
- txtarea.unbind();
- },
- //定额工作内容相关操作
- rationJobContentOpr: function (rationItems) {
- let me = jobContentOprObj;
- me.setRadiosDisabled(me.currentRationItems.length > 0 ? false : true, me.radios);
- me.setRadiosChecked(me.currentSituation, me.radios);
- me.buildTablePartial(me.tablePartial, me.getGroup(rationItems));
- },
- getUpdateArr: function (updateCodes, jobContent) {
- let rst = [];
- for(let i = 0, len = updateCodes.length; i < len; i++){
- rst.push({code: updateCodes[i], jobContent: jobContent});
- }
- return rst;
- },
- bindAddConBtn: function () {
- let me = jobContentOprObj;
- return function () {
- let codesObj = me.getCodesAfterS(me.addCon.children().children().children());
- let $tbody = $('#tablePartial tbody');
- let lastEle = $tbody[0].lastElementChild;
- let txtare = lastEle.lastElementChild.children[0];
- if(me.currentJobContent.trim().length > 0){//工作内容不为空才可添加编码
- let updateArr = me.getUpdateArr(codesObj.checked, me.currentJobContent);
- me.updateJobContent(pageOprObj.rationLibId, updateArr, function () {
- me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
- $(txtare).val('');
- });
- }
- else{
- alert("工作内容不能为空!");
- }
- }
- },
- bindUpdateConBtn: function () {
- let me = jobContentOprObj;
- return function () {
- let codesObj = me.getCodesAfterS(me.updateCon.children().children().children());
- let updateC = me.getUpdateArr(codesObj.checked, me.currentJobContent),
- updateUnC = me.getUpdateArr(codesObj.unchecked, ''),
- updateArr = updateC.concat(updateUnC);
- me.updateJobContent(pageOprObj.rationLibId, updateArr, function () {
- me.buildTablePartial(me.tablePartial, me.getGroup(me.currentRationItems));
- });
- }
- },
- //更新缓存的定额
- updateRationItem: function (rationItems, updateArr) {
- for(let i = 0, len = rationItems.length; i < len; i++){
- for(let j = 0, jLen = updateArr.length; j < jLen; j++){
- if(rationItems[i].code === updateArr[j].code){
- rationItems[i].jobContent = updateArr[j].jobContent;
- break;
- }
- }
- }
- },
- updateJobContent: function (repId, updateArr, callback){
- let me = jobContentOprObj;
- $.ajax({
- type: 'post',
- url: 'api/updateJobContent',
- data: {lastOpr: userAccount, repId: repId, updateArr: JSON.stringify(updateArr)},
- dataType: 'json',
- success: function (result) {
- if(!result.error){
- me.updateRationItem(jobContentOprObj.currentRationItems, updateArr);
- callback();
- }
- }
- });
- },
- updateSituation: function (repId, nodeId, situation, callback) {
- let me = jobContentOprObj;
- $.ajax({
- type: 'post',
- url: 'api/updateSituation',
- data: {lastOpr: userAccount, repId: repId, nodeId: nodeId, situation: situation},
- dataType: 'json',
- success: function (result) {
- if(!result.error){
- if(callback){
- callback();
- }
- }
- }
- })
- }
- };
- let annotationOprObj = {
- situations: {ALL: 'ALL', PARTIAL: 'PARTIAL', NONE: 'NONE'},
- currentSituation: null,//本项适用情况
- radios: $("input[name = 'fzRadios']"),
- fzTableAll: $('#fzTableAll'),
- fzTablePartial: $('#fzTablePartial'),
- currentOprTr: null,
- currentAnnotation: null,
- addCon: $('#fzAddCon'),//勾选编码模态框
- updateCon: $('#fzUpdateCon'),//编辑编码模态框
- clickUpdate: function (txtarea) {//解决编辑完后在未失去焦点的时候直接定额章节树
- let me = annotationOprObj;
- if(txtarea.is(':focus')){
- let annotation = txtarea.val();
- if(annotation !== me.currentAnnotation){
- jobContentOprObj.preTreeNode.annotation = annotation;
- me.unbindEvents(txtarea);
- txtarea.blur();
- let updateCodes = [];
- for(let i = 0, len = jobContentOprObj.currentRationItems.length; i < len; i++){
- updateCodes.push(jobContentOprObj.currentRationItems[i].code);
- jobContentOprObj.currentRationItems[i].annotation = annotation;
- }
- me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, annotation), function () {
- me.bindAllEvents(txtarea);
- });
- }
- else {
- txtarea.blur();
- }
- }
- },
- getGroup: function (rationItems) {
- let rst = [];//rst = [{jobContent: String, items: Array}]
- for(let i = 0, len = rationItems.length; i < len; i++){
- if(typeof rationItems[i].annotation !== 'undefined' && rationItems[i].annotation.toString().trim().length > 0){
- let isExist = false;
- for(let j = 0, jLen = rst.length; j < jLen; j++){
- if(rst[j].annotation === rationItems[i].annotation){
- isExist = true;
- rst[j].items.push(rationItems[i].code);
- break;
- }
- }
- if(!isExist){
- rst.push({annotation: rationItems[i].annotation, items: [rationItems[i].code]});
- }
- }
- }
- return rst;
- },
- hideTable: function (tableAll, tablePartial) {
- if(tableAll){
- tableAll.hide();
- }
- if(tablePartial){
- tablePartial.hide();
- }
- },
- //建table
- buildTablePartial: function (table, group) {
- let me = annotationOprObj;
- table.empty();
- let $thead = $("<thead><tr><th></th><th>编码</th><th>附注</th>/tr></thead>");
- let $tbody = $("<tbody></tbody>");
- let count = 1;
- for(let i = 0, len = group.length; i < len; i++){
- let $newTr = me.getNewTr($tbody, group[i].items, group[i].annotation);
- $tbody.append($newTr);
- count++;
- }
- 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>");//勾选行
- $($trEnd.children().children()[0]).bind('click', function () {
- me.onclickFuncAdd($(this));
- me.currentOprTr = $trEnd;
- me.currentAnnotation = $(me.currentOprTr.children()[2]).children().val();
- });
- $tbody.append($trEnd);
- table.append($thead);
- table.append($tbody);
- },
- //新增一行tr
- getNewTr: function (tbody, codes, jobContent) {
- let me = annotationOprObj;
- let count = tbody.children().length > 0 ? tbody.children().length : 1;
- let $textTd = $("<td></td>");
- let $textarea = $("<textarea class='form-control'></textarea>");
- $textarea.val(jobContent);
- $textTd.append($textarea);
- let $tr = $("<tr><td>" + count + "</td><td><a href data-toggle='modal' data-target='#fzEditBianmaQ' class='m-0'>编辑编码</a></td></tr>");
- $tr.children().children().bind('click', function () {
- me.currentOprTr = $tr;
- me.currentAnnotation = $(me.currentOprTr.children()[2]).children().val();
- me.onclickFuncEdit($(this));
- });
- //文本变化;
- $textarea.bind('change', function () {
- let codes = me.getUpdateCodes($($(this).parent().parent().children()[1]).children());
- let annotation = $(this).val();
- me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(codes, annotation), function () {
- if(annotation.trim().length === 0){
- me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
- }
- });
- });
- $tr.append($textTd);
- for(let i = 0, len = codes.length; i < len; i ++){
- let $p = $("<p class='m-0'>" + codes[i] + "</p>");
- $tr.children()[1].append($p[0]);
- }
- me.setTextareaHeight($textarea, codes.length + 1);
- return $tr[0];
- },
- onclickFuncAdd: function (obj) {
- let me = annotationOprObj;
- let txtarea = $(obj.parent().parent().children().children()[1]);
- let annotation = txtarea.val();
- if(annotation.trim().length > 0){
- let codesObj = me.getAddCodes(jobContentOprObj.currentRationItems);
- me.buildCheckCodesCon(me.addCon, codesObj.checkedCodes, codesObj.disabledCodes)
- obj.attr('data-target', '#fzEditBianma');
- }
- else{
- obj.attr('data-target', '');
- alert("附注不能为空!");
- }
- },
- onclickFuncEdit: function (obj) {
- let me = annotationOprObj;
- me.buildEditableCodesCon(jobContentOprObj.currentRationItems, me.updateCon, me.getUpdateCodes(obj));
- },
- //获取编码td中的编码
- getUpdateCodes: function (jq) {
- let rst = [];
- let nodes = jq.parent().children();
- for(let i = 1, len = nodes.length; i < len; i++){
- rst.push(nodes[i].textContent);
- }
- return rst;
- },
- //建一个编码checkbox Div
- buildCodeOption: function (code, attr) {
- let $div = $("<div class='col'><label class='form-check-label'><input class='form-check-input' type='checkbox' value= "+ code +"> "+ code +"</label></div>");
- let $checkBox = $div.children().children();
- if(attr){
- $checkBox.attr(attr, true);
- }
- return $div;
- },
- //建修改编码弹窗
- buildEditableCodesCon: function (rationItems, container, codes) {
- let me = annotationOprObj;
- let codeDivs = [];
- container.empty();
- for(let i = 0, len = codes.length; i < len; i++){
- codeDivs.push({code: codes[i], attr: 'checked'});
- }
- for(let i = 0, len = rationItems.length; i < len; i++){
- if(codes.indexOf(rationItems[i].code) === -1){
- if(typeof rationItems[i].annotation !== 'undefined' && rationItems[i].annotation.toString().trim().length > 0){
- codeDivs.push({code: rationItems[i].code, attr: 'disabled'});
- }
- else{
- codeDivs.push({code: rationItems[i].code, attr: ''});
- }
- }
- }
- //排序
- codeDivs.sort(function (a, b) {
- let rst = 0;
- if(a.code > b.code) rst = 1;
- else if(a.code < b.code) rst = -1;
- return rst;
- });
- for(let i = 0, len = codeDivs.length; i < len; i++){
- container.append(me.buildCodeOption(codeDivs[i].code, codeDivs[i].attr));
- }
- },
- //建勾选编码弹窗
- buildCheckCodesCon: function (container, checkedCodes, disabledCodes) {
- let me = annotationOprObj;
- container.empty();
- for(let i = 0, len = checkedCodes.length; i < len; i++){
- let $codeDiv = me.buildCodeOption(checkedCodes[i], 'checked');
- container.append($codeDiv);
- }
- for(let i = 0, len = disabledCodes.length; i < len; i++){
- let $codeDiv = me.buildCodeOption(disabledCodes[i], 'disabled');
- container.append($codeDiv);
- }
- },
- getAddCodes: function (rationItems) {
- let me = annotationOprObj;
- let rst = {checkedCodes: [], disabledCodes: []};
- for(let i = 0, len = rationItems.length; i < len; i++){
- if(typeof rationItems[i].annotation !== 'undefined' && rationItems[i].annotation.toString().trim().length > 0){
- rst.disabledCodes.push(rationItems[i].code);
- }
- else{
- rst.checkedCodes.push(rationItems[i].code);
- }
- }
- return rst;
- },
- //获取选择后的编码窗口的编码及状态
- getCodesAfterS: function (checkNodes) {
- let rst = {checked: [], unchecked: []};
- for(let i = 0, len = checkNodes.length; i < len; i++){
- if(checkNodes[i].checked){
- rst.checked.push(checkNodes[i].value);
- }
- else if(!checkNodes[i].checked && !checkNodes[i].disabled){
- rst.unchecked.push(checkNodes[i].value);
- }
- }
- return rst;
- },
- setRadiosChecked: function (situation, radios) {
- let me = annotationOprObj;
- if(situation === me.situations.ALL){
- radios[0].checked = true;
- radios[1].checked = false;
- $('#fzTxtareaAll').val(jobContentOprObj.currentRationItems.length > 0 ? jobContentOprObj.currentRationItems[0].annotation : '');
- me.currentAnnotation = jobContentOprObj.currentRationItems.length > 0 ? jobContentOprObj.currentRationItems[0].annotation : '';
- me.fzTableAll.show();
- me.fzTablePartial.hide();
- }
- else if(situation === me.situations.PARTIAL){
- radios[0].checked = false;
- radios[1].checked = true;
- me.fzTableAll.hide();
- me.fzTablePartial.show();
- }
- else if(situation === me.situations.NONE){
- radios[0].checked = false;
- radios[1].checked = false;
- me.fzTableAll.hide();
- me.fzTablePartial.hide();
- }
- },
- //radios是否可用,只有在定额章节树的底层节点才可用
- setRadiosDisabled: function (val, radios) {
- let me =annotationOprObj;
- if(val){
- radios[0].checked = false;
- radios[1].checked = false;
- me.currentSituation = me.situations.NONE;
- }
- radios.attr('disabled', val);
- },
- radiosChange: function (radios, tableAll, tablePartial) {
- let me = annotationOprObj;
- radios.change(function () {
- let val = $("input[name = 'fzRadios']:checked").val();
- let selectedNode = zTreeOprObj.treeObj.getSelectedNodes()[0];
- me.updateAnnoSituation(pageOprObj.rationLibId, selectedNode.ID, val, function () {
- selectedNode.annotationSituation = val;
- me.currentSituation = val;
- if(val === me.situations.ALL){
- let updateCodes = [];
- for(let i = 0, len = jobContentOprObj.currentRationItems.length; i < len; i++){
- updateCodes.push(jobContentOprObj.currentRationItems[i].code);
- }
- me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, ''), function () {
- me.currentAnnotation = '';
- $('#fzTxtareaAll').val('');
- tableAll.show();
- tablePartial.hide();
- });
- }
- else{
- me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
- tableAll.hide();
- tablePartial.show();
- }
- });
- });
- },
- setTextareaHeight: function (textarea, nodesCount) {
- const perHeight = 21.6;
- textarea.height(nodesCount * 21.6);
- },
- bindEvents: function (txtarea) {
- let me = annotationOprObj;
- txtarea.bind('change', function () {
- let annotation = txtarea.val();
- let jqNodes = txtarea.parent().parent().children()[1].children;
- let updateCodes = me.getUpdateCodes(jqNodes);
- txtarea.attr('disabled', true);
- me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, annotation), function () {
- txtarea.attr('disabled', false);
- });
- });
- },
- bindAllEvents: function (txtarea) {
- let me = annotationOprObj;
- txtarea.bind('change', function () {
- let met = this;
- let annotation = $(met).val();
- $(met).attr('disabled', true);
- let updateCodes = [];
- for(let i = 0, len = jobContentOprObj.currentRationItems.length; i < len; i++){
- updateCodes.push(jobContentOprObj.currentRationItems[i].code);
- jobContentOprObj.currentRationItems[i].annotation = annotation;
- }
- me.currentAnnotation = annotation;
- me.updateAnnotation(pageOprObj.rationLibId, me.getUpdateArr(updateCodes, annotation), function () {
- $(met).attr('disabled', false);
- });
- });
- },
- unbindEvents: function (txtarea) {
- txtarea.unbind();
- },
- //定额工作内容相关操作
- rationAnnotationOpr: function (rationItems) {
- let me = annotationOprObj;
- me.setRadiosDisabled(rationItems.length > 0 ? false : true, me.radios);
- me.setRadiosChecked(me.currentSituation, me.radios);
- me.buildTablePartial(me.fzTablePartial, me.getGroup(rationItems));
- },
- getUpdateArr: function (updateCodes, annotation) {
- let rst = [];
- for(let i = 0, len = updateCodes.length; i < len; i++){
- rst.push({code: updateCodes[i], annotation: annotation});
- }
- return rst;
- },
- bindAddConBtn: function () {
- let me = annotationOprObj;
- return function () {
- let codesObj = me.getCodesAfterS(me.addCon.children().children().children());
- let $tbody = $('#fzTablePartial tbody');
- let lastEle = $tbody[0].lastElementChild;
- let txtare = lastEle.lastElementChild.children[0];
- if(me.currentAnnotation.trim().length > 0){//工作内容不为空才可添加编码
- let updateArr = me.getUpdateArr(codesObj.checked, me.currentAnnotation);
- me.updateAnnotation(pageOprObj.rationLibId, updateArr, function () {
- me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
- $(txtare).val('');
- });
- }
- else{
- alert("附注不能为空!");
- }
- }
- },
- bindUpdateConBtn: function () {
- let me = annotationOprObj;
- return function () {
- let codesObj = me.getCodesAfterS(me.updateCon.children().children().children());
- let updateC = me.getUpdateArr(codesObj.checked, me.currentAnnotation),
- updateUnC = me.getUpdateArr(codesObj.unchecked, ''),
- updateArr = updateC.concat(updateUnC);
- me.updateAnnotation(pageOprObj.rationLibId, updateArr, function () {
- me.buildTablePartial(me.fzTablePartial, me.getGroup(jobContentOprObj.currentRationItems));
- });
- }
- },
- //更新缓存的定额
- updateRationItem: function (rationItems, updateArr) {
- for(let i = 0, len = rationItems.length; i < len; i++){
- for(let j = 0, jLen = updateArr.length; j < jLen; j++){
- if(rationItems[i].code === updateArr[j].code){
- rationItems[i].annotation = updateArr[j].annotation;
- break;
- }
- }
- }
- },
- updateAnnotation: function (repId, updateArr, callback){
- let me = annotationOprObj;
- $.ajax({
- type: 'post',
- url: 'api/updateAnnotation',
- data: {lastOpr: userAccount, repId: repId, updateArr: JSON.stringify(updateArr)},
- dataType: 'json',
- success: function (result) {
- if(!result.error){
- me.updateRationItem(jobContentOprObj.currentRationItems, updateArr);
- callback();
- }
- }
- });
- },
- updateAnnoSituation: function (repId, nodeId, situation, callback) {
- let me = annotationOprObj;
- $.ajax({
- type: 'post',
- url: 'api/updateAnnoSituation',
- data: {lastOpr: userAccount, repId: repId, nodeId: nodeId, situation: situation},
- dataType: 'json',
- success: function (result) {
- if(!result.error){
- if(callback){
- callback();
- }
- }
- }
- })
- }
- };
|