|
@@ -25,6 +25,14 @@ var quantity_detail = {
|
|
|
this.datas = datas;
|
|
|
};
|
|
|
|
|
|
+ quantity_detail.prototype.getListByID = function (ID,field) {
|
|
|
+ let condition={};
|
|
|
+ condition[field] = ID;
|
|
|
+ let details = _.filter(this.datas, condition);
|
|
|
+ details = _.sortBy(details, 'seq');
|
|
|
+ return details;
|
|
|
+ };
|
|
|
+
|
|
|
// 提交数据后返回数据处理
|
|
|
quantity_detail.prototype.doAfterUpdate = function(err, data){
|
|
|
if(!err){
|
|
@@ -82,7 +90,6 @@ var quantity_detail = {
|
|
|
var showList = _.filter(this.datas,filter_object);
|
|
|
gljOprObj.detailData=showList;
|
|
|
gljOprObj.detailData=_.sortBy(gljOprObj.detailData,'seq');
|
|
|
- console.log(batchCallback);
|
|
|
if(batchCallback == undefined){
|
|
|
this.refreshSheetData();
|
|
|
}
|
|
@@ -131,8 +138,8 @@ var quantity_detail = {
|
|
|
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)){
|
|
|
+ if(dataCode=='regex'){// if(this.checkAndCalcResult(args.editingText,args.row,doc) === false){
|
|
|
+ if(this.checkAndCalcResult(args.editingText,args.row,doc) === false){
|
|
|
gljOprObj.showQuantityDetailData();
|
|
|
return;
|
|
|
}
|
|
@@ -168,7 +175,7 @@ var quantity_detail = {
|
|
|
}else {
|
|
|
data.newRecord?me.refreshAfterSave(data.newRecord,batchCallback):me.refreshAfterSave(data,batchCallback);
|
|
|
if(batchCallback){
|
|
|
- batchCallback(args)
|
|
|
+ batchCallback(args);
|
|
|
}else if(data.node){
|
|
|
me.refreshRationOrBillNodes(data.node);
|
|
|
}
|
|
@@ -183,14 +190,13 @@ var quantity_detail = {
|
|
|
|
|
|
|
|
|
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);
|
|
|
+ let treeNode = gljOprObj.updateDataNodeProperty(node.ID,node.data);
|
|
|
+ if(treeNode){//触发计算
|
|
|
+ if(treeNode.sourceType === project.Bills.getSourceType()){
|
|
|
+ console.log(treeNode.data.quantity);
|
|
|
+ this.updateBillQuantity(treeNode.data.quantity,treeNode,treeNode.data.quantityEXP);
|
|
|
}else {//更新定额所使用的值要用还没转换前的
|
|
|
- node.data? this.updateRationQuantity(node.data.r_quantity,newNode,newNode.data.quantityEXP):"";
|
|
|
+ node.data? this.updateRationQuantity(node.data.r_quantity,treeNode,treeNode.data.quantityEXP):"";
|
|
|
}
|
|
|
}
|
|
|
};
|
|
@@ -199,7 +205,7 @@ var quantity_detail = {
|
|
|
var args = {
|
|
|
row:row,
|
|
|
editingText:1
|
|
|
- }
|
|
|
+ };
|
|
|
if(row < gljOprObj.detailData.length){
|
|
|
args.insertRecode = true;
|
|
|
}
|
|
@@ -240,18 +246,22 @@ var quantity_detail = {
|
|
|
};
|
|
|
|
|
|
quantity_detail.prototype.moveDown = function (row) {
|
|
|
+ let sel = gljOprObj.detailSheet.getSelections()[0];
|
|
|
this.swapRow(row);
|
|
|
+ gljOprObj.detailSheet.setSelection(row+1,sel.col,sel.rowCount,sel.colCount);//更改选中行
|
|
|
};
|
|
|
quantity_detail.prototype.moveUp = function (row) {
|
|
|
+ let sel = gljOprObj.detailSheet.getSelections()[0];
|
|
|
this.swapRow(row-1);
|
|
|
+ gljOprObj.detailSheet.setSelection(row-1,sel.col,sel.rowCount,sel.colCount);//更改选中行
|
|
|
};
|
|
|
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;
|
|
|
+ let me = this;
|
|
|
+ let update_task = [];
|
|
|
+ let a_row = gljOprObj.detailData[preRow];//
|
|
|
+ let b_row = gljOprObj.detailData[preRow +1];//
|
|
|
+ let temA = a_row.seq;
|
|
|
+ let 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;
|
|
@@ -274,13 +284,89 @@ var quantity_detail = {
|
|
|
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.calcResult = function (doc) {//return false 代表输入有误
|
|
|
+ let field = doc.billID?"billID":"rationID";// doc.rationID
|
|
|
+ let detailList = this.getListByID(doc[field],field);
|
|
|
+ let result = this.getEvalResult(doc.referenceIndexs,detailList,doc.regex);
|
|
|
+ if(result === null){
|
|
|
+ return false;
|
|
|
+ }else {
|
|
|
+ doc.result = result;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ quantity_detail.prototype.getEvalResult = function(referenceIndexs,detailList,regex) {
|
|
|
+ try {
|
|
|
+ let decimal = getDecimal("quantity_detail");
|
|
|
+ for(let i of referenceIndexs){
|
|
|
+ regex = this.replaceReference(i,detailList,regex)
|
|
|
+ }
|
|
|
+ console.log('replace all C reference -----'+regex);
|
|
|
+ regex = this.replaceSqr(regex);
|
|
|
+ console.log('replace all sqar reference -----'+regex);
|
|
|
+ return scMathUtil.roundTo(eval(regex), -decimal);
|
|
|
+ }catch (error){
|
|
|
+ alert('输入的表达式有误,请重新输入!');
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ quantity_detail.prototype.replaceReference = function(index,detailList,str) {
|
|
|
+ str=str.toUpperCase();
|
|
|
+ let rstr= detailList[index-1].regex==null?'0':'('+detailList[index-1].regex+')';
|
|
|
+ str=this.replaceAll('C'+index,rstr,str);
|
|
|
+ if(detailList[index-1].referenceIndexs.length>0){
|
|
|
+ for (let i of detailList[index-1].referenceIndexs){
|
|
|
+ str =this.replaceReference(i,detailList,str);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return str;
|
|
|
+ };
|
|
|
+
|
|
|
+ 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=this.converSqrByArr(sqararr,text);
|
|
|
+ }
|
|
|
+ if(sqararr2){
|
|
|
+ text=this.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.checkAndCalcResult = function (regex,row,doc) {//return false 表示没有通过检查
|
|
|
+ if(!this.regexChecking(regex)||!this.referenceChecking(regex,row,doc)||!this.calcResult(doc)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ };
|
|
|
+
|
|
|
quantity_detail.prototype.updateQuantityDetail=function (args,dataCode,recode,selected,batchCallback) {
|
|
|
var doc ={},me = this;
|
|
|
var query={
|
|
@@ -290,6 +376,10 @@ var quantity_detail = {
|
|
|
var selected = selected?selected:projectObj.project.mainTree.selected;
|
|
|
doc[dataCode]=args.editingText;
|
|
|
if (dataCode == 'regex') {
|
|
|
+ if(this.checkAndCalcResult(args.editingText,args.row,doc) === false){
|
|
|
+ gljOprObj.showQuantityDetailData();
|
|
|
+ return;
|
|
|
+ }
|
|
|
if(recode.hasOwnProperty('rationID')){
|
|
|
query.rationID=recode.rationID;
|
|
|
}else {
|