|
@@ -2,19 +2,121 @@
|
|
* Created by zhang on 2018/9/12.
|
|
* Created by zhang on 2018/9/12.
|
|
*/
|
|
*/
|
|
let MaterialController = {
|
|
let MaterialController = {
|
|
- rule1:"材质及规格:",
|
|
|
|
- replaceMaterial:function(node){
|
|
|
|
-
|
|
|
|
- this.getMaterial([node]);
|
|
|
|
|
|
+ //规则相关映射
|
|
|
|
+ rule1: function (node) {
|
|
let itemText = node.data.itemCharacterText;
|
|
let itemText = node.data.itemCharacterText;
|
|
- let keyWord = this.getKeyString(itemText,this.rule1);
|
|
|
|
- console.log(keyWord);
|
|
|
|
|
|
+ let name = this.getKeyString(itemText,"材质及规格:");
|
|
|
|
+ if(name){
|
|
|
|
+ return{name:name}
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ },
|
|
|
|
+ rule2:function (node) {
|
|
|
|
+ let itemText = node.data.itemCharacterText;
|
|
|
|
+ let name = this.getKeyString(itemText,"混凝土种类:");
|
|
|
|
+ let specs = this.getKeyString(itemText,"混凝土强度等级:");
|
|
|
|
+ if(name||specs){
|
|
|
|
+ let doc ={};
|
|
|
|
+ if(name) doc["name"] = name;
|
|
|
|
+ if(specs) doc["specs"] = specs;
|
|
|
|
+ return doc;
|
|
|
|
+ }
|
|
|
|
+ return null
|
|
|
|
+ },
|
|
|
|
+ replaceMaterial:function(nodes){
|
|
|
|
+ let me = this;
|
|
|
|
+ this.getMaterial(nodes,function (result) {
|
|
|
|
+ if(!_.isEmpty(result)){
|
|
|
|
+ me.startReplace(nodes,result);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
|
|
|
|
+ startReplace:function (nodes,result) {//其实应该是批量修改工料机属性,与替换工料机不同
|
|
|
|
+ let me = this,updateData = [];
|
|
|
|
+ for(let n of nodes){
|
|
|
|
+ let code = n.data.code;
|
|
|
|
+ if(code.length >= 9){
|
|
|
|
+ let r_list = this.eachNode(n,result[code.substr(0,9)]);
|
|
|
|
+ if(r_list.length > 0) updateData.push(...r_list);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(updateData.length == 0) return;
|
|
|
|
+ $.bootstrapLoading.start();
|
|
|
|
+ CommonAjax.post("/material/replace",updateData,function(result){
|
|
|
|
+ $.bootstrapLoading.end();
|
|
|
|
+ me.updateCacheAfterReplace(result)
|
|
|
|
+ })
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ updateCacheAfterReplace:function (result){
|
|
|
|
+ let nodes = [];
|
|
|
|
+ for(let data of result){
|
|
|
|
+ let node = projectObj.project.ration_glj.refreshRationNode(data.name,data.adjustState,data.rationID);//刷新定额名称和子目调整状态
|
|
|
|
+ if(node) nodes.push(node);
|
|
|
|
+ if(data.ration_gljs.length > 0) this.refreshRationGLJ(data.ration_gljs);
|
|
|
|
+ }
|
|
|
|
+ if(nodes.length >0){
|
|
|
|
+ projectObj.project.projectGLJ.loadData(function () {//先加载项目工料机
|
|
|
|
+ projectObj.project.calcProgram.calcNodesAndSave(nodes,function(){
|
|
|
|
+ installationFeeObj.calcInstallationFee();
|
|
|
|
+ });
|
|
|
|
+ gljOprObj.refreshView();
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ refreshRationGLJ:function(ration_gljs){
|
|
|
|
+ let ration_glj_model = projectObj.project.ration_glj;
|
|
|
|
+ for(let rg of ration_gljs){
|
|
|
|
+ let glj = ration_glj_model.refreshByID(rg.ID,rg.doc);
|
|
|
|
+ ration_glj_model.refreshTreeNodeIfNeeded(glj);//刷新造价书上的树节点(如果需要)
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ eachNode:function (node,item) {
|
|
|
|
+ let replaceDatas =[];
|
|
|
|
+ if(item && item.bills.rule){
|
|
|
|
+ let replace_property = this["rule"+item.bills.rule](node);//按清单设置的规则获取要修改的属性
|
|
|
|
+ if(replace_property){
|
|
|
|
+ replaceDatas = this.getReplaceData(node.data.ID,item.materialMap,replace_property);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return replaceDatas;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getReplaceData:function (billsItemID,materialMap,replace_property) {
|
|
|
|
+ let list = [];
|
|
|
|
+ let replace_glj_list = this.findMatchRationGLJ(billsItemID,materialMap);//取出需要替换的工料机和对替换的材料内容
|
|
|
|
+ for(let r of replace_glj_list){
|
|
|
|
+ let doc = this.getDoc(r.glj,r.material,replace_property);//获取要修改的字段
|
|
|
|
+ list.push({glj:gljOprObj.setGLJPrice(r.glj),doc:doc});
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ },
|
|
|
|
|
|
|
|
|
|
|
|
+ getDoc:function (glj,material,replace_property) {//取定额工料机中需要修改的内容
|
|
|
|
+ let doc = {},keyList = ['name','specs','type','unit'];
|
|
|
|
+ for(let key of keyList){
|
|
|
|
+ if(glj[key] != material[key]) doc[key] = material[key];
|
|
|
|
+ }
|
|
|
|
+ for(let rkey in replace_property){
|
|
|
|
+ doc[rkey] = replace_property[rkey]
|
|
|
|
+ }
|
|
|
|
+ return doc;
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
|
|
|
|
+
|
|
|
|
+ findMatchRationGLJ:function (billsItemID,materialMap) {//查找清单下匹配的需要替换的定额工料机
|
|
|
|
+ let replaceList=[];
|
|
|
|
+ for(let g of projectObj.project.ration_glj.datas){
|
|
|
|
+ if(g.billsItemID == billsItemID && materialMap[g.original_code]) {
|
|
|
|
+ replaceList.push({glj:g,material:materialMap[g.original_code]});
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return replaceList;
|
|
|
|
+ },
|
|
getMaterial:function (nodes,callback) {
|
|
getMaterial:function (nodes,callback) {
|
|
let data = [],materialMap= null;
|
|
let data = [],materialMap= null;
|
|
for(let n of nodes){
|
|
for(let n of nodes){
|
|
@@ -25,11 +127,11 @@ let MaterialController = {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(data.length>0){
|
|
if(data.length>0){
|
|
- //data去重
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ //data 按编码去重
|
|
|
|
+ let dataMap = _.indexBy(data,'code');
|
|
|
|
+ CommonAjax.post("/material/getMaterial",dataMap,function (result) {
|
|
|
|
+ callback(result);
|
|
|
|
+ })
|
|
}else {
|
|
}else {
|
|
callback(null);
|
|
callback(null);
|
|
}
|
|
}
|