| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674 | 
							- /**
 
-  * Created by Mai on 2017/4/1.
 
-  */
 
- var quantity_detail = {
 
-     createNew: function (project) {
 
-         // 用户定义private方法
 
-         var tools = {};
 
-         // 所有通过this访问的属性,都不应在此单元外部进行写入操作
 
-         var quantity_detail = function (proj) {
 
-             this.gljTree = cacheTree.createNew(this);
 
-            // this.project = proj;
 
-             this.datas = [];
 
-             var sourceType = ModuleNames.quantity_detail;
 
-             this.getSourceType = function () {
 
-                 return sourceType;
 
-             }
 
-             proj.registerModule(ModuleNames.quantity_detail, this);
 
-             this.temList=[];
 
-         };
 
-         // prototype用于定义public方法
 
-         quantity_detail.prototype.loadData = function (datas) {
 
-             this.datas = datas;
 
-         };
 
-         // 提交数据后返回数据处理
 
-         quantity_detail.prototype.doAfterUpdate = function(err, data){
 
-             if(!err){
 
-                 if(data.updateTpye=='ut_update'){
 
-                     this.refreshAfterUpdate(data);
 
-                 }else if(data.updateTpye=='ut_delete'){
 
-                     this.refreshAfterDelete(data);
 
-                 } else {
 
-                     this.refreshAfterSave(data);
 
-                 }
 
-             }else {
 
-                 alert(err.message);
 
-                 this.refreshSheetData();
 
-             }
 
-         };
 
-         quantity_detail.prototype.refreshAfterSave=function(data){
 
-             var me = this;
 
-             if(data.hasOwnProperty('resort')){
 
-                 this.resortData(data.doc,1);
 
-                 _.forEach(data.update_task,function (item) {
 
-                     me.refreshEachItme(item.query,item.doc);
 
-                 })
 
-                 this.datas.push(data.doc);
 
-             }else {
 
-                 this.datas.push(data);
 
-             }
 
-             this.refreshSheetData();
 
-         };
 
-         quantity_detail.prototype.resortData=function(data,req){
 
-             for(var i =0;i<gljOprObj.detailData.length;i++){
 
-                 var item = gljOprObj.detailData[i];
 
-                 if(item.seq>=data.seq){
 
-                     item.seq=item.seq+req;
 
-                 }
 
-             }
 
-         };
 
-         quantity_detail.prototype.refreshAfterUpdate=function(data){
 
-             var me = this;
 
-             var filter_object;
 
-             if(data.hasOwnProperty('refreshList')){
 
-                 _.forEach(data.refreshList,function (item) {
 
-                     filter_object= me.refreshEachItme(item.query,item.doc);
 
-                 })
 
-             }else {
 
-                 filter_object = me.refreshEachItme(data.query,data.doc);
 
-             }
 
-             var showList = _.filter(this.datas,filter_object);
 
-             gljOprObj.detailData=showList;
 
-             gljOprObj.detailData=_.sortBy(gljOprObj.detailData,'seq');
 
-             this.refreshSheetData();
 
-         };
 
-         quantity_detail.prototype.refreshEachItme = function(query,doc){
 
-             var detail_list = this.datas;
 
-             var detail_index= _.findIndex(detail_list,function(detail){
 
-                 return detail.ID==query.ID;
 
-             })
 
-             _.forEach(doc, function(n, key) {
 
-                 detail_list[detail_index][key] = n;
 
-             });
 
-             var filter_object;
 
-             if(detail_list[detail_index].hasOwnProperty('rationID')){
 
-                 filter_object={'rationID':detail_list[detail_index].rationID};
 
-             }else {
 
-                 filter_object={'billID':detail_list[detail_index].billID};
 
-             }
 
-             return filter_object;
 
-         };
 
-         quantity_detail.prototype.refreshAfterDelete=function(data){
 
-             var me = this;
 
-             if(data.doc.seq != gljOprObj.detailData.length - 1){
 
-                 this.resortData(data.doc,-1);
 
-             }
 
-             _.forEach(data.update_task,function (item) {
 
-                 me.refreshEachItme(item.query,item.doc);
 
-             });
 
-             _.remove(this.datas,{ID:data.doc.ID});
 
-             this.refreshSheetData();
 
-         };
 
-         quantity_detail.prototype.refreshSheetData=function () {
 
-             gljOprObj.showQuantityDetailData();
 
-         };
 
-         quantity_detail.prototype.saveQuantityDetail=function (args,dataCode,selected) {
 
-             var me = this;
 
-             var doc={};
 
-             var selected = selected?selected:projectObj.project.mainTree.selected;
 
-             if(selected.sourceType==ModuleNames.ration){
 
-                 doc.rationID=selected.data.ID;
 
-             }
 
-             if(selected.sourceType==ModuleNames.bills){
 
-                 doc.billID=selected.data.ID;
 
-             }
 
-             doc.projectID = selected.data.projectID;
 
-             doc[dataCode]=args.editingText;
 
-             doc.seq=args.row;
 
-             if(dataCode=='regex'){
 
-                 if(!this.regexChecking(args.editingText)||!this.referenceChecking(args.editingText,args.row,doc)){
 
-                     gljOprObj.showQuantityDetailData();
 
-                     return;
 
-                 }
 
-                 doc.refreshQuantity=true;
 
-                 if(!selected.data.hasOwnProperty('isFromDetail')||selected.data.isFromDetail==0){
 
-                     var c = confirm("确定要使用工程量明细替换原工程量吗?");
 
-                     if(!c){
 
-                         doc.refreshQuantity=false;
 
-                     }
 
-                 }
 
-             }
 
-             var url="";
 
-             $.bootstrapLoading.start();
 
-             if(args.hasOwnProperty("insertRecode")){//右键插入或者是通过直接编辑保存
 
-                 url = "/quantity_detail/insertRecode";
 
-             }else{
 
-                 url = "/quantity_detail/save";
 
-             }
 
-             var callback = function (data) {
 
-                 if(doc.refreshQuantity==false){//清空数据
 
-                     me.cleanQuantityDetail();
 
-                 }else {
 
-                     data.newRecord?me.refreshAfterSave(data.newRecord):me.refreshAfterSave(data);
 
-                     if(data.node){
 
-                       me.refreshRationOrBillNodes(data.node);
 
-                     }
 
-                     //gljOprObj.detailSheet.setActiveCell(0,0);
 
-                     //gljOprObj.detailSheet.clearSelection();
 
-                 }
 
-                 $.bootstrapLoading.end();
 
-             }
 
-             CommonAjax.post(url,doc,callback,function () {
 
-                 $.bootstrapLoading.end();
 
-             });
 
-         };
 
-         quantity_detail.prototype.refreshRationOrBillNodes=function(node){//工程量明细更新后触发定额或清单工程量改变,进行相应的更新
 
-             var nodes = gljOprObj.refreshTreeNode(node);
 
-             if(nodes.length>0){//触发计算
 
-                 let newNode = nodes[0];
 
-                 if(newNode.sourceType === project.Bills.getSourceType()){
 
-                     console.log(newNode.data.quantity);
 
-                     this.updateBillQuantity(newNode.data.quantity,newNode,newNode.data.quantityEXP);
 
-                 }else {//更新定额所使用的值要用还没转换前的
 
-                     this.updateRationQuantity(node.data.r_quantity,newNode,newNode.data.quantityEXP);//to do 加上工程量表达式和含量更新
 
-                 }
 
-             }
 
-         };
 
-         quantity_detail.prototype.insertQuantityDetail = function (row) {
 
-             var args = {
 
-                 row:row,
 
-                 editingText:1
 
-             }
 
-             if(row < gljOprObj.detailData.length){
 
-                 args.insertRecode = true;
 
-             }
 
-             this.saveQuantityDetail(args,'isSummation');
 
-         };
 
-         quantity_detail.prototype.deleteQuantityDetail = function (row) {
 
-            var me = this;
 
-            var deleteable = this.checkReference(row);
 
-            if(deleteable){
 
-                var recode = gljOprObj.detailData[row];
 
-                $.bootstrapLoading.start();
 
-                var callback=function (result) {
 
-                    me.refreshAfterDelete(result.data);
 
-                    if(result.node){//触发计算
 
-                        me.refreshRationOrBillNodes(result.node);
 
-                    }
 
-                    $.bootstrapLoading.end();
 
-                }
 
-                CommonAjax.post("/quantity_detail/deleteRecode",recode,callback,function () {
 
-                    $.bootstrapLoading.end();
 
-                });
 
-            }else {
 
-                alert("当前行已被引用,不可删除。");
 
-            }
 
-         };
 
-         quantity_detail.prototype.checkReference = function (row) {
 
-             var deleteable = true;
 
-            for(var i =0;i<gljOprObj.detailData.length;i++){
 
-                 var item = gljOprObj.detailData[i];
 
-                 if(_.includes(item.referenceIndexs,row+1)){
 
-                     deleteable = false;
 
-                     break;
 
-                 }
 
-             }
 
-             return deleteable;
 
-         };
 
-         quantity_detail.prototype.moveDown = function (row) {
 
-             this.swapRow(row);
 
-         };
 
-         quantity_detail.prototype.moveUp = function (row) {
 
-             this.swapRow(row-1);
 
-         };
 
-         quantity_detail.prototype.swapRow = function (preRow) {
 
-             var me = this;
 
-             var update_task = [];
 
-             var a_row = gljOprObj.detailData[preRow];//
 
-             var b_row = gljOprObj.detailData[preRow +1];//
 
-             var temA = a_row.seq;
 
-             var temB = b_row.seq;
 
-             a_row.seq = temB;
 
-             update_task.push({query:{ID:a_row.ID,projectID:a_row.projectID},doc:{seq:a_row.seq}});
 
-             b_row.seq = temA;
 
-             update_task.push({query:{ID:b_row.ID,projectID:b_row.projectID},doc:{seq:b_row.seq}});
 
-             gljOprObj.detailData.forEach(function (item) {
 
-                 if(_.includes(item.referenceIndexs,temA+1)||_.includes(item.referenceIndexs,temB+1)){
 
-                     var regex = item.regex;
 
-                     for (var i=0;i<item.referenceIndexs.length;i++){
 
-                         if(item.referenceIndexs[i]==temA+1){
 
-                             regex = me.replaceAll('C'+item.referenceIndexs[i],'B'+(temB+1),regex);
 
-                             regex = me.replaceAll('c'+item.referenceIndexs[i],'b'+(temB+1),regex);
 
-                             item.referenceIndexs[i]=temB+1;
 
-                         }else if(item.referenceIndexs[i]==temB+1){
 
-                             regex = me.replaceAll('C'+item.referenceIndexs[i],'B'+(temA+1),regex);
 
-                             regex = me.replaceAll('c'+item.referenceIndexs[i],'b'+(temA+1),regex);
 
-                             item.referenceIndexs[i]=temA+1;
 
-                         }
 
-                     }
 
-                     regex =  me.replaceAll('B','C',regex);
 
-                     regex =  me.replaceAll('b','c',regex);
 
-                     update_task.push({query:{ID:item.ID,projectID:item.projectID},doc:{regex:regex,referenceIndexs:item.referenceIndexs}});
 
-                 }
 
-             })
 
-             me.commonUpdate("/quantity_detail/swapRow",update_task);
 
-         };
 
-         quantity_detail.prototype.replaceAll=function(FindText, RepText,str) {
 
-             let regExp = new RegExp(FindText, "g");
 
-             return str.replace(regExp, RepText);
 
-         };
 
-         quantity_detail.prototype.updateQuantityDetail=function (args,dataCode,recode,selected) {
 
-             var doc ={};
 
-             var query={
 
-                 ID:recode.ID,
 
-                 projectID:recode.projectID
 
-             };
 
-             var selected = selected?selected:projectObj.project.mainTree.selected;
 
-             doc[dataCode]=args.editingText;
 
-             if (dataCode == 'regex') {
 
-                 if(recode.hasOwnProperty('rationID')){
 
-                     query.rationID=recode.rationID;
 
-                 }else {
 
-                     query.billID = recode.billID
 
-                 }
 
-                 query.refreshQuantity=true;
 
-                 if(!selected.data.hasOwnProperty('isFromDetail')||selected.data.isFromDetail==0){
 
-                     var c = confirm("确定要使用工程量明细替换原工程量吗?");
 
-                     if(!c){
 
-                         //query.refreshQuantity=false;
 
-                         this.cleanQuantityDetail(selected,true);
 
-                         return;
 
-                     }
 
-                 }
 
-                 query.index = args.row;
 
-                 this.updateQuantityRegex(query,doc,args)
 
-             }else {
 
-                 this.normalUpdate(query,doc);
 
-             }
 
-         };
 
-         quantity_detail.prototype.updateQuantityRegex=function(query,doc,args){
 
-             var needupdate = false;
 
-             if(args.editingText==null){
 
-                 needupdate =true;
 
-             }else {
 
-                 args.editingText = _.trim(args.editingText,/\r\n/);
 
-                 if(this.regexChecking(args.editingText)&&this.referenceChecking(args.editingText,args.row,doc)){
 
-                     needupdate = true;
 
-                 }
 
-             }
 
-             if(needupdate){
 
-                 this.commonUpdate("/quantity_detail/updateRegex",{query:query,doc:doc});
 
-             }else {
 
-                 var sheet = subSpread.getActiveSheet();
 
-                 sheet.getCell(args.row,args.col).value(gljOprObj.detailData[args.row].regex);
 
-             }
 
-         };
 
-         quantity_detail.prototype.isSummationUpdate=function (args,detailList,newval) {
 
-             var query={
 
-                 ID:detailList[args.row].ID,
 
-                 projectID:detailList[args.row].projectID
 
-             };
 
-             var selected = projectObj.project.mainTree.selected;
 
-             query.refreshQuantity=true;
 
-             if(!selected.data.hasOwnProperty('isFromDetail')||selected.data.isFromDetail==0){
 
-                 var c = confirm("确定要使用工程量明细替换原工程量吗?");
 
-                 if(!c){
 
-                     query.refreshQuantity=false;
 
-                 }
 
-             }
 
-             if(detailList[args.row].hasOwnProperty('rationID')){
 
-                 query.rationID=detailList[args.row].rationID;
 
-             }else {
 
-                 query.billID = detailList[args.row].billID
 
-             }
 
-             var doc={
 
-                 isSummation:newval
 
-             };
 
-             this.normalUpdate(query,doc);
 
-         };
 
-         quantity_detail.prototype.commonUpdate = function (url,postData) {
 
-             var me = this;
 
-             $.bootstrapLoading.start();
 
-             var callback = function (data) {
 
-                 me.refreshAfterUpdate(data);
 
-                 if(data.node){
 
-                   me.refreshRationOrBillNodes(data.node);
 
-                 }
 
-                 $.bootstrapLoading.end();
 
-             }
 
-             CommonAjax.post(url,postData,callback,function () {
 
-                 $.bootstrapLoading.end();
 
-             });
 
-         };
 
-         quantity_detail.prototype.normalUpdate=function(query,doc){
 
-             var url = "/quantity_detail/update";
 
-             this.commonUpdate(url,{query:query,doc:doc});
 
-         };
 
-         quantity_detail.prototype.regexChecking=function(text){
 
-             var regex=/^[0-9Cc\+\-\*\^/\(\)\.]*$/g;
 
-             if(!regex.test(text)){
 
-                 alert("输入了非法字符,请重新输入!")
 
-                 return false;
 
-             }else {
 
-                 return true;
 
-             }
 
-         };
 
-         quantity_detail.prototype.referenceChecking=function (text,row,doc) {
 
-             text = text.toUpperCase();
 
-             //text= this.replaceSqr(text);
 
-             var me = this;
 
-             var refReg = /C\d+/g;
 
-             var self ='C'+(row+1);
 
-             var refList = text.match(refReg);
 
-             var invalidate = _.includes(refList,self);
 
-             var referenceIndexs = [];
 
-             var indexOut = false;
 
-             _.forEach(refList,function (item) {
 
-                 var ref_index = parseInt(item.substring(1));
 
-                 if(ref_index>gljOprObj.detailData.length){
 
-                     indexOut=true;
 
-                     return;
 
-                 }else {
 
-                     referenceIndexs.push(ref_index);
 
-                 }
 
-             });
 
-             if(indexOut){
 
-                 alert("引用有误,请重新输入!");
 
-                 return false;
 
-             }
 
-             referenceIndexs=_.uniq(referenceIndexs);
 
-             doc.referenceIndexs = referenceIndexs;
 
-             this.temList = referenceIndexs;
 
-             invalidate=this.getAllReferenceList((row+1),referenceIndexs);
 
-             if(invalidate){
 
-                 alert("计算式中产生了循环引用,请重新输入!");
 
-                 return false;
 
-             }
 
-             return true;
 
-         };
 
-         quantity_detail.prototype.getAllReferenceList=function(original,refList){
 
-             var me =this;
 
-             var invalidate=false;
 
-             _.forEach(refList,function (item) {
 
-                 if(me.getReferenceList(item,original)){
 
-                     invalidate=true;
 
-                 }
 
-             })
 
-             return invalidate;
 
-         };
 
-         quantity_detail.prototype.getReferenceList=function(item,original) {
 
-             var invalidate =false;
 
-             if(gljOprObj.detailData.length>=item){
 
-                 var recode = gljOprObj.detailData[item - 1];
 
-                 if (recode.referenceIndexs.length > 0) {
 
-                     if(_.includes(recode.referenceIndexs,original)){
 
-                         invalidate = true;
 
-                         return invalidate;
 
-                     }
 
-                     this.temList = this.temList.concat(recode.referenceIndexs);
 
-                     _.forEach(recode.referenceIndex, function (item) {
 
-                         if(this.getReferenceList(item,original)){
 
-                             invalidate = true;
 
-                         }
 
-                     })
 
-                 }
 
-             }
 
-             return invalidate;
 
-         }
 
-         quantity_detail.prototype.replaceSqr = function(text) {
 
-             var squarRegex = /\([^\^]+\)\^\d+/g;
 
-             var sqararr = text.match(squarRegex);
 
-             var squarRegex2 = /C[0-9]+\^\d+|[0-9]+([.]{1}[0-9]+){0,1}\^\d+/g; //匹配没有括号的
 
-             var sqararr2=text.match(squarRegex2);
 
-             if(sqararr){
 
-                 text=converSqrByArr(sqararr,text);
 
-             }
 
-             if(sqararr2){
 
-                 text=converSqrByArr(sqararr2,text);
 
-             }
 
-             return text;
 
-         };
 
-         quantity_detail.prototype.converSqrByArr = function (sqararr,text) {
 
-             var temp = text;
 
-             sqararr.forEach(function (item) {
 
-                 var arr = item.split('\^');
 
-                 var y = parseInt(arr[1]);
 
-                 var x_arr = [];
 
-                 for (var i = 0; i < y; i++) {
 
-                     x_arr.push(arr[0]);
 
-                 }
 
-                 var temStr = x_arr.join('*');
 
-                 temp = temp.replace(item, temStr);
 
-             });
 
-             return temp;
 
-         };
 
-         quantity_detail.prototype.deleteByRation = function(ration){
 
-             var detail_list = this.datas;
 
-             _.remove(detail_list,{'rationID':ration.ID});
 
-         };
 
-         quantity_detail.prototype.deleteByBills=function(deleteData){
 
-             var detail_list = this.datas;
 
-             var billIDList = [];
 
-             for(var i=0;i<deleteData.length;i++){
 
-                 if(deleteData[i].type=='delete'){
 
-                     billIDList.push(deleteData[i].data.ID);
 
-                 }
 
-             }
 
-             var newList =_.filter(detail_list,(d)=>{
 
-                 return !_.includes(billIDList,d.billID);
 
-             });
 
-             if(newList!=undefined){
 
-                 this.datas = newList;
 
-             }
 
-         };
 
-         quantity_detail.prototype.cleanQuantityDetail = function (node,needSave) {
 
-            node =node?node:projectObj.project.mainTree.selected;
 
-            var query={projectID:node.data.projectID};
 
-             if(node.sourceType === project.Bills.getSourceType()){
 
-                 query.billID = node.data.ID;
 
-                 this.deleteByBills([{type:'delete',data:node.data}]);
 
-             }else if(node.sourceType === project.Ration.getSourceType()){
 
-                 this.deleteByRation(node.data);
 
-                 query.rationID = node.data.ID;
 
-             }
 
-             if(needSave===true){
 
-                 query.refreshQuantity=false;
 
-                 CommonAjax.post("/quantity_detail/save",query);
 
-             }
 
-             gljOprObj.detailData=[];
 
-             sheetCommonObj.showData(gljOprObj.detailSheet,gljOprObj.detailSetting,[]);
 
-         };
 
-         quantity_detail.prototype.quantityEditChecking = function(value,node,fieldName){
 
-             var validate = true;
 
-             if(fieldName=='quantity'){
 
-                if(node.data.hasOwnProperty('isFromDetail')&&node.data.isFromDetail==1){
 
-                    var c = confirm('已有工程量明细,是否清空明细表,采用手工输入的表达式?')
 
-                     if(c){
 
-                         validate = true;
 
-                     }else {
 
-                         validate = false;
 
-                     }
 
-                }
 
-             }
 
-             return validate;
 
-         };
 
-         quantity_detail.prototype.autoTransformQuantity = function(value,node){//根据单位转换定额工程量
 
-             let data = node.data;
 
-             let option = optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS,'rationQuanACToRationUnit');
 
-             if(node.data.quantityEXP=='GCLMXHJ'||(option==true&&node.sourceType === project.Ration.getSourceType()&&data.unit)) {//还需加入判读是否转换,如果是来自工程量明细的话,默认都进行转换
 
-                 let times = parseInt(data.unit);
 
-                 if (isNaN(times)) {
 
-                     times = 1
 
-                 }
 
-                 value = value / times;
 
-             }
 
-             let EXPString=node.data.quantityEXP+"";
 
-             if(option==false&&node.sourceType === project.Ration.getSourceType()&&EXPString!='GCLMXHJ'&&EXPString.indexOf("QDL")==-1&&data.unit){//勾选不根据单位转换工程量,且定额是手输的,
 
-                 let times = parseInt(data.unit);
 
-                 if(!isNaN(times)){///如果定额单位可以做转换
 
-                     if(isNum(EXPString)){//如果表达式中只是数字
 
-                         node.data.quantityEXP = EXPString+" * "+times;
 
-                     }else {//如果表达式是一个计算式,则要加一个括号
 
-                         node.data.quantityEXP = "("+EXPString+") * "+times;
 
-                     }
 
-                     if(node.data.contain!=0){
 
-                        let billQuantity = scMathUtil.roundForObj(node.parent.data.quantity,getDecimal("quantity",node.parent));
 
-                        let temValue = scMathUtil.roundForObj(value*times,getDecimal("quantity",node));
 
-                         node.data.contain = scMathUtil.roundForObj(temValue/billQuantity,getDecimal("process"));
 
-                     }
 
-                 }
 
-             }
 
-             return value;
 
-         };
 
-         quantity_detail.prototype.reverseQuantity = function (value,node) {//根据单位反向运算出工程量
 
-             let data = node.data;
 
-             if(node.sourceType === project.Ration.getSourceType()&&data.unit){
 
-                 let times = parseInt(data.unit);
 
-                 if (isNaN(times)) {
 
-                     times = 1
 
-                 }
 
-                 value = value * times;
 
-             }
 
-             return value
 
-         };
 
-         quantity_detail.prototype.editMainTreeNodeQuantity=function (value,node,fieldName,editingText) {
 
-             var me = this;
 
-             if(isNaN(value)){
 
-                 alert("当前输入的数据类型不正确,请重新输入。");
 
-                 projectObj.mainController.refreshTreeNode([node]);
 
-             }else {
 
-                 value=value?value:0;
 
-                 setTimeout(function () {//spreadjs事件和提示窗口会有冲突,所以要用延时的方法
 
-                     if(project.quantity_detail.quantityEditChecking(value,node,fieldName)){
 
-                         node.data.isFromDetail=0;
 
-                         project.quantity_detail.cleanQuantityDetail(node,true);
 
-                         if(node.sourceType === project.Bills.getSourceType()){
 
-                             me.updateBillQuantity(value,node,null,editingText);
 
-                         }else {
 
-                             me.updateRationQuantity(value,node,null,editingText);
 
-                         }
 
-                     }else {
 
-                         projectObj.mainController.refreshTreeNode([node]);
 
-                     }
 
-                 },100);
 
-             }
 
-         };
 
-         quantity_detail.prototype.updateBillQuantity=function (value,node,quantityEXP,editingText) {
 
-             node.data.quantityEXP = quantityEXP?quantityEXP:editingText;
 
-             value = scMathUtil.roundForObj(value,getDecimal("quantity",node));
 
-             node.data.quantity = value+"";
 
-             console.log(value);
 
-             let needUpdateChildren = [];//需更新的子定额
 
-             let gljNodes=[];//当定额工程量改变时需刷新的子工料机
 
-             if(node.children.length>0){//如果有子项则
 
-                 for(let rationNode of node.children){
 
-                     let EXPString = rationNode.data.quantityEXP+"";
 
-                     if(EXPString.indexOf("QDL")!=-1){
 
-                         if(EXPString=="QDL"){//定额的工程量是直接通过清单量填进来的;
 
-                             let times = parseInt(rationNode.data.unit);
 
-                             if(isNaN(times)){
 
-                                 times = 1;
 
-                             }
 
-                             rationNode.data.quantity = scMathUtil.roundForObj(value / times,getDecimal("quantity",rationNode));
 
-                             rationNode.data.contain = scMathUtil.roundForObj(rationNode.data.quantity/value,getDecimal("process"));
 
-                         }else {//如果定额的工程量是通过计算出来的,则应该重新计算。
 
-                             let tem_contain = scMathUtil.roundForObj(rationNode.data.contain,getDecimal("process"));
 
-                             let tem_quantity = scMathUtil.roundForObj(value*tem_contain,getDecimal("quantity",rationNode)); //this.autoTransformQuantity(tem_quantity,rationNode);
 
-                             rationNode.data.quantity = tem_quantity;
 
-                         }
 
-                         rationNode.changed = true;
 
-                         needUpdateChildren.push(rationNode);
 
-                         if (rationNode.children.length>0){//如果有子工料机
 
-                             gljNodes = gljNodes.concat(rationNode.children);
 
-                         }
 
-                     }else {
 
-                         let tem_contain=0;
 
-                         if(value&&value!=0){
 
-                            let children_quantity = scMathUtil.roundForObj(rationNode.data.quantity,getDecimal("quantity"),rationNode);
 
-                             // children_quantity = scMathUtil.roundForObj(this.reverseQuantity(children_quantity,rationNode),getDecimal("quantity",rationNode));  原先是要反算的,现在改成不用反算了
 
-                             tem_contain =scMathUtil.roundForObj(children_quantity/value,getDecimal("process"));
 
-                         }
 
-                         rationNode.data.contain = tem_contain;
 
-                         rationNode.changed = true;
 
-                         needUpdateChildren.push(rationNode);
 
-                     }
 
-                 }
 
-             }
 
-             if(needUpdateChildren.length>0){//清单下的定额工程量发生了改变
 
-                 node.changed = true;//本身发生了改变,需要存储。
 
-                 /*project.calcProgram.calcRationsAndSave(needUpdateChildren, function () {
 
-                     project.projectGLJ.loadData();
 
-                 });*/
 
-                 project.calcProgram.calcRationsAndSave(needUpdateChildren, function () {
 
-                     if(project.Bills.isFBFX(node)) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
 
-                         project.installation_fee.calcInstallationFee(function (isChange) {
 
-                             if(isChange){
 
-                                 project.calcProgram.calcAllNodesAndSave();
 
-                             }
 
-                         });
 
-                     }else {
 
-                         project.projectGLJ.loadData();
 
-                     }
 
-                 });
 
-             }else {
 
-                 node.changed = true;
 
-                 project.calcProgram.calcAndSave(node, function () {
 
-                     project.projectGLJ.loadData();
 
-                 });
 
-             }
 
-             if(gljNodes.length>0){
 
-                 projectObj.mainController.refreshTreeNode(gljNodes);
 
-             }
 
-         };
 
-         quantity_detail.prototype.updateRationQuantity=function(value,node,quantityEXP,editingText){
 
-             node.data.quantityEXP = quantityEXP?quantityEXP:editingText;
 
-             value = scMathUtil.roundForObj(value,getDecimal("ration.quantity"));
 
-             value = project.quantity_detail.autoTransformQuantity(value,node);
 
-             value = scMathUtil.roundForObj(value,decimalObj.decimal("quantity",node))
 
-             node.data.quantity=value;
 
-             if(node.parent.data.quantity&&node.parent.data.quantity!=0&&node.parent.data.quantity!=""){
 
-                 var billQuantity = scMathUtil.roundForObj(node.parent.data.quantity,getDecimal("quantity",node.parent));
 
-                 node.data.contain = scMathUtil.roundForObj(value/billQuantity,getDecimal("process"));
 
-             }else {
 
-                 node.data.contain=0;
 
-             }
 
-             node.changed = true;
 
-             project.calcProgram.calcAndSave(node, function () {
 
-                 if(project.Bills.isFBFX(node)) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
 
-                     project.installation_fee.calcInstallationFee(function (isChange) {
 
-                         if(isChange){
 
-                             project.calcProgram.calcAllNodesAndSave();
 
-                         }
 
-                     });
 
-                 }else {
 
-                     project.projectGLJ.loadData();
 
-                 }
 
-             });
 
-             projectObj.mainController.refreshTreeNode(node.children);//刷新子工料机总消耗量
 
-             gljOprObj.showRationGLJSheetData();
 
-         };
 
-         quantity_detail.prototype.getDecimal=function (node) {
 
-             var decimal = 3;
 
-             if(node.sourceType === project.Bills.getSourceType()){
 
-                 decimal = billsQuanDecimal.decimal(node.data.unit);
 
-             }else {
 
-                 decimal = decimalObj.ration.quantity
 
-             }
 
-             return;
 
-         };
 
-         return new quantity_detail(project);
 
-     }
 
- };
 
 
  |