zhangweicheng 7 年之前
父節點
當前提交
d4654f68cb

+ 32 - 16
modules/glj/models/glj_list_model.js

@@ -17,6 +17,7 @@ import MixRatioModel from "./mix_ratio_model";
 import GljModel from "../../complementary_glj_lib/models/gljModel";
 const ProjectModel = require('../../pm/models/project_model').project;
 const scMathUtil = require('../../../public/scMathUtil').getUtil();
+import decimal_facade from "../../main/facade/decimal_facade";
 
 class GLJListModel extends BaseModel {
 
@@ -75,8 +76,11 @@ class GLJListModel extends BaseModel {
      */
     async getListByProjectId(projectId, unitPriceFileId) {
         let gljData = null;
+        let decimal =await decimal_facade.getProjectDecimal(projectId);
+        let quantity_decimal = decimal.glj.quantity?decimal.glj.quantity:6;//取消耗量保留小数据位,默认6位
         let mixRatioConnectData = {};
         let mixRationMap={};
+        let keyMap={};
         try {
             // 首先获取对应标段下所有的项目工料机数据
             let condition = {project_id: projectId};
@@ -96,6 +100,8 @@ class GLJListModel extends BaseModel {
             let gljIdList = [];
             for(let tmp of gljData) {
                 gljIdList.push(tmp.id);
+                let c_key = this.getIndex(tmp,['code','name','specs','unit','type']);
+                keyMap[tmp.id] = c_key; //工料机ID和连接key的对照表;
             }
             // 从定额工料机库中获取消耗量
             condition = {
@@ -104,22 +110,25 @@ class GLJListModel extends BaseModel {
             };
             let quantityData = await RationGLJFacade.getQuantityByProjectGLJ(condition);
             let quantityList = {};
-            // 整理数据
+            // 整理数据 得到总定额消耗量
             for (let tmp of quantityData) {
                 let tmpNum = parseFloat(tmp.rationQuantity);
                 tmpNum = isNaN(tmpNum) ||tmpNum==0? 1 : tmpNum;
-                if (quantityList[tmp.projectGLJID] === undefined) {
-                    quantityList[tmp.projectGLJID] = tmp.quantity * tmpNum;
+                let tmp_con_key = keyMap[tmp.projectGLJID];
+
+                if (quantityList[tmp_con_key] === undefined) {
+                    quantityList[tmp_con_key] = scMathUtil.roundTo(tmp.quantity * tmpNum,-quantity_decimal);
                 } else {
-                    quantityList[tmp.projectGLJID] += tmp.quantity * tmpNum;
+                    quantityList[tmp_con_key] = scMathUtil.roundTo(quantityList[tmp_con_key]+tmp.quantity * tmpNum,-quantity_decimal);
                 }
             }
             // 整理获取有组成物的项目工料机的数据
             let connect_keys = [];
             for(let tmp of gljData) {
-                // 有组成物的类型且消耗量大于0才查找
-                if (quantityList[tmp.id] !== undefined) {
-                   let key = this.getIndex(tmp,['code','name','specs','unit','type']);
+                // 有组成物的类型才查找
+                let key = keyMap[tmp.id];
+                if (quantityList[key]!=undefined&&(tmp.type === GLJTypeConst.CONCRETE || tmp.type === GLJTypeConst.MORTAR ||
+                    tmp.type === GLJTypeConst.MIX_RATIO || tmp.type === GLJTypeConst.GENERAL_MACHINE)){
                     connect_keys.push(key);
                 }
             }
@@ -132,11 +141,18 @@ class GLJListModel extends BaseModel {
                 let mixRatioList = await mixRatioModel.findDataByCondition(condition, null, false);
                 for (let tmp of mixRatioList) {
                    let t_index = tmp.connect_key;
-                    let consumption=parseFloat(tmp.consumption);
-                    totalComposition[t_index] = totalComposition[t_index] === undefined ? consumption :
+                   let consumption=parseFloat(tmp.consumption);
+                   let m_index = this.getIndex(tmp,['code','name','specs','unit','type']);
+                   let r_quantity = quantityList[t_index]?quantityList[t_index]:0;
+                   if(quantityList[m_index]!==undefined){
+                       quantityList[m_index]=quantityList[m_index]+r_quantity*consumption;
+                   }else {
+                       quantityList[m_index] = r_quantity*consumption;
+                   }
+                    quantityList[m_index] = scMathUtil.roundTo(quantityList[m_index],-quantity_decimal);
+                /*    totalComposition[t_index] = totalComposition[t_index] === undefined ? consumption :
                         totalComposition[t_index] + consumption;
-                    totalComposition[t_index] = scMathUtil.roundTo(totalComposition[t_index], -4);
-
+                    totalComposition[t_index] = scMathUtil.roundTo(totalComposition[t_index], -quantity_decimal);*/
                     if (mixRatioData[t_index] !== undefined) {
                         mixRatioData[t_index].push(tmp);
                     } else {
@@ -209,11 +225,11 @@ class GLJListModel extends BaseModel {
             let gljId = glj.glj_id + '';
             let projectGljId = glj.id + '';
             // 消耗量赋值
-            glj.quantity = quantityList[projectGljId] !== undefined ? quantityList[projectGljId] : 0;
+         /*   glj.quantity = quantityList[projectGljId] !== undefined ? quantityList[projectGljId] : 0;
             glj.quantity = totalComposition[g_index] !== undefined ? totalComposition[g_index] : glj.quantity;
             glj.quantity = compositionConsumption[g_index] !== undefined ?  glj.quantity + compositionConsumption[g_index] : glj.quantity;
-            glj.quantity = scMathUtil.roundTo(parseFloat(glj.quantity), -3);
-
+            glj.quantity = scMathUtil.roundTo(parseFloat(glj.quantity), -3);*/
+            glj.quantity = quantityList[g_index]?quantityList[g_index]:0;
             // 组成物数据
             gljList[index].ratio_data = mixRatioData[g_index] !== undefined ? mixRatioData[g_index] : [];
             //因为schema中设置base_price 为string 类型,所以要通过中间变量转换为数字再做计算,不然会自动变成字符串类型
@@ -350,7 +366,7 @@ class GLJListModel extends BaseModel {
         //查找单价信息,有则返回,没有则新增并返回
         let unitPriceFileId = unitPriceFile.id;
         let unitPriceModel = new UnitPriceModel();
-        let [unitPriceData, isAdd] = await unitPriceModel.addUnitPrice(data, unitPriceFileId);
+        let [unitPriceData, isAdd] = await unitPriceModel.addUnitPrice(data, unitPriceFileId,"modify");
         let gljData={};
         if(isAdd){ //如果是新增,则新增一条新的项目工料机
             data.code = unitPriceData.code;
@@ -448,7 +464,7 @@ class GLJListModel extends BaseModel {
             let unitPriceModel = new UnitPriceModel();
 
             let gljCount = gljListData.length;
-            let [unitPriceData, isAdd] = await unitPriceModel.addUnitPrice(updateData, unitPriceFileId, gljCount);
+            let [unitPriceData, isAdd] = await unitPriceModel.addUnitPrice(updateData, unitPriceFileId,"modify", gljCount);
 
             // 判断是否已存在对应数据
             let includeField = [

+ 12 - 6
modules/glj/models/unit_price_model.js

@@ -80,7 +80,7 @@ class UnitPriceModel extends BaseModel {
      * @param {Number} gljCount
      * @return {Promise} 返回数据以及是否新增
      */
-    async addUnitPrice(data, unitPriceFileId, gljCount = 0) {
+    async addUnitPrice(data, unitPriceFileId,operation='add', gljCount = 0) {
         if (data.original_code===undefined||data.code === undefined || data.project_id === undefined || data.name === undefined
             || data.market_price === undefined) {
             return [null, false];
@@ -88,7 +88,12 @@ class UnitPriceModel extends BaseModel {
         // 先查找是否有原始code相同的记录
         let unitPriceData = await this.findDataByCondition({original_code: data.original_code, unit_price_file_id: unitPriceFileId}, null, false);
         // 如果有记录,判断是否存在一样的名称,单位...等,有则直接返回数据
-        let unitPrice =  this.isPropertyInclude(unitPriceData,['name','specs','unit','type'],data);
+        let unitPrice=null;
+        if(operation=='add'){//新增操作时,要把code也一起判断,是否完全一样
+            unitPrice =  this.isPropertyInclude(unitPriceData,['code','name','specs','unit','type'],data);
+        }else {//修改操作时,code不用加入判读,因为code是需要改变的
+            unitPrice =  this.isPropertyInclude(unitPriceData,['name','specs','unit','type'],data);
+        }
         if(unitPrice){
             return [unitPrice, false];
         }
@@ -111,11 +116,12 @@ class UnitPriceModel extends BaseModel {
             unit:data.unit,
             type: data.type,
             short_name: data.shortName !== undefined ? data.shortName : '',
-            glj_id: data.glj_id
+            glj_id: data.glj_id,
+            is_add:0
         };
-
-        // 如果原始编码能找到,但不存在一样的编号,名称,单位.更改 等,更改code和添加新增标记
-        if (unitPriceData&&unitPriceData.length>0) {
+        if(data.from=='cpt'){//如果是来自补充工料机,则都添加新增标记
+            insertData.is_add=1;
+        }else if (unitPriceData&&unitPriceData.length>0) {// 如果原始编码能找到,但不存在一样的编号,名称,单位.型号等,更改code和添加新增标记
             insertData.code = data.original_code+"-"+unitPriceData.length;
             insertData.is_add=1;
         }

+ 18 - 0
modules/main/facade/decimal_facade.js

@@ -0,0 +1,18 @@
+/**
+ * Created by zhang on 2017/11/22.
+ */
+let projectsModel = require("../../pm/models/project_schema");
+
+
+module.exports ={
+    getProjectDecimal:getProjectDecimal
+}
+
+async function getProjectDecimal(projectID) {
+    let decimal = null;
+    let project =await projectsModel.findOne({ID:projectID});
+    if(project){
+        decimal = project.property.decimal
+    }
+    return decimal;
+}

+ 2 - 1
modules/main/facade/prj_properties_facade.js

@@ -5,6 +5,7 @@ let mongoose = require("mongoose");
 let prj_prop_mdl = mongoose.model("project_property");
 let std_prj_prop_mdl = mongoose.model("cfg_prj_property");
 
+
 module.exports = {
     createPrjProperties: createPrjProperties,
     removePrjProperties : removePrjProperties,
@@ -126,4 +127,4 @@ function addOrChangePropertyWithCallBack(prjId, newItem, cb) {
 
 function removeOnePropertyWithCallBack(prjId, key, cb) {
     prj_prop_mdl.update({"projectID": prjId}, {"$pull": {"properties": {"key": key}}}, cb);
-}
+}

+ 0 - 1
modules/ration_glj/controllers/ration_glj_controller.js

@@ -103,7 +103,6 @@ async function mReplaceGLJ(req, res){
     try {
         let data = req.body.data;
         data = JSON.parse(data);
-        console.log(data);
         let mresult= await ration_glj_facade.mReplaceGLJ(data);
         result.data=mresult;
     }catch (err){

+ 7 - 7
modules/ration_glj/facade/glj_calculate_facade.js

@@ -28,7 +28,7 @@ let stateSeq ={
 }
 
 
-async function calculateQuantity(query,isMarkPriceAjust){
+async function calculateQuantity(query,noNeedCal){
     try {
          let  result ={
              glj_result:[],
@@ -51,11 +51,11 @@ async function calculateQuantity(query,isMarkPriceAjust){
                  }
          }
          for(let i =0;i<gljList.length;i++ ){
-             let r = await calculateQuantityPerGLJ(gljList[i],i,coeList,assList,adjustState,isMarkPriceAjust);
+             let r = await calculateQuantityPerGLJ(gljList[i],i,coeList,assList,adjustState,noNeedCal);
              result.glj_result.push(r);
          }
 
-        if(isMarkPriceAjust==null){
+        if(noNeedCal==null){
             await ration_glj.bulkWrite(generateUpdateTasks(result.glj_result));
         }
          adjustState= _.sortByOrder(adjustState, ['index'], ['asc']);
@@ -85,8 +85,8 @@ function generateUpdateTasks(result) {
 }
 
 
-async function calculateQuantityPerGLJ(glj,index,coeList,assList,adjustState,isMarkPriceAjust) {
-    let quantity =  glj.quantity;
+async function calculateQuantityPerGLJ(glj,index,coeList,assList,adjustState,noNeedCal) {
+    let quantity =  scMathUtil.roundTo(parseFloat(glj.quantity),-6);
     let result={
         query:{
             ID:glj.ID,
@@ -97,9 +97,9 @@ async function calculateQuantityPerGLJ(glj,index,coeList,assList,adjustState,isM
         }
     };
     try {
-        if(isMarkPriceAjust==null){
+        if(noNeedCal==null){
             if(!glj._doc.hasOwnProperty('customQuantity')||glj.customQuantity==null){
-                quantity =glj.rationItemQuantity;
+                quantity =scMathUtil.roundTo(parseFloat(glj.rationItemQuantity),-6);
                 quantity =calculateAss(quantity,assList,glj);
                 quantity = calculateQuantityByCoes(quantity,coeList,glj);
             }else {

+ 18 - 7
modules/ration_glj/facade/ration_glj_facade.js

@@ -572,6 +572,7 @@ async function addGLJ(rgList) {
        g.marketPrice=result.unit_price.market_price;
        g.adjustPrice=result.unit_price.base_price;
        g.basePrice=result.unit_price.base_price;
+       g.isAdd=result.unit_price.is_add,
        g.projectGLJID=result.id;
        g.isEstimate=result.is_evaluate;
        g.ID=uuidV1();
@@ -595,13 +596,18 @@ async function replaceGLJ(data) {
     let rdata={};
     let projectGljModel = new GLJListModel();
     let result = await projectGljModel.addList(getGLJSearchInfo(data));
+    data.projectGLJID=result.id;
+    let updateResult=await ration_glj.findOneAndUpdate({ID:data.ID,projectID:data.projectID},data);//更新定额工料机
+    //组装回传数据
     data.marketPrice=result.unit_price.market_price;
     data.adjustPrice=result.unit_price.base_price;
     data.basePrice=result.unit_price.base_price;
-    data.projectGLJID=result.id;
+    data.isAdd=result.unit_price.is_add;
     data.isEstimate=result.is_evaluate;
-    let updateResult=await ration_glj.findOneAndUpdate({ID:data.ID,projectID:data.projectID},data);
-    let stateResult =  await glj_calculate_facade.calculateQuantity({projectID:data.projectID,rationID:data.rationID});
+    if(result.hasOwnProperty('subList')&&result.subList.length>0){
+        data.subList=getMixRatioShowDatas(result.subList);
+    }
+    let stateResult =  await glj_calculate_facade.calculateQuantity({projectID:data.projectID,rationID:data.rationID},true);
     rdata.data=data;
     rdata.adjustState=stateResult.adjustState;
     return rdata;
@@ -610,13 +616,18 @@ async function mReplaceGLJ(data) {
     let mresult={};
     let projectGljModel = new GLJListModel();
     let result = await projectGljModel.addList(getGLJSearchInfo(data.doc));
+    data.doc.projectGLJID=result.id;
+    let rationList=await ration_glj.distinct('rationID',data.query);
+    let updateResult=await ration_glj.update(data.query,data.doc,{multi: true});
+
     data.doc.marketPrice=result.unit_price.market_price;
     data.doc.adjustPrice=result.unit_price.base_price;
     data.doc.basePrice=result.unit_price.base_price;
-    data.doc.projectGLJID=result.id;
+    data.doc.isAdd=result.unit_price.is_add;
     data.doc.isEstimate=result.is_evaluate;
-    let rationList=await ration_glj.distinct('rationID',data.query);
-    let updateResult=await ration_glj.update(data.query,data.doc,{multi: true});
+    if(result.hasOwnProperty('subList')&&result.subList.length>0){
+        data.doc.subList=getMixRatioShowDatas(result.subList);
+    }
     let stateList= await changAdjustState(data,rationList);
     mresult.data=data;
     mresult.stateList=stateList;
@@ -700,7 +711,7 @@ async function getGLJClass(info,data) {
 async function changAdjustState(data,rationList) {
     let stateList=[];
     for(let r of rationList){
-      let stateResult = await glj_calculate_facade.calculateQuantity({projectID:data.query.projectID,rationID:r});
+      let stateResult = await glj_calculate_facade.calculateQuantity({projectID:data.query.projectID,rationID:r},true);
       stateList.push({rationID:r,adjustState:stateResult.adjustState});
     }
     return stateList;

+ 0 - 1
web/building_saas/glj/js/composition_spread.js

@@ -133,7 +133,6 @@ CompositionSpread.prototype.getRatioData = function(projectGLJid) {
         success: function(response) {
             if (response.err === 0) {
                 response.data = JSON.parse(response.data);
-                console.log(response.data);
                 // 设置数据
                 self.sheetObj.setData(response.data);
                 self.specialColumn(response.data);

+ 35 - 9
web/building_saas/main/js/models/ration_glj.js

@@ -98,8 +98,9 @@ var ration_glj = {
         ration_glj.prototype.refreshAfterSave=function(data){
             let neRecodes=[];
             if(data){
-                neRecodes=data.newRecords;
-                gljOprObj.sheetData=data.showDatas;
+               // neRecodes=data.newRecords;//原来是显示和缓存分开的,后来发现会导致数据不一致的问题所以改成统一的了,这里也只是会作为显示。
+                neRecodes = data.showDatas;
+                gljOprObj.sheetData=neRecodes;
             }
             if(projectObj.project.ration_glj.datas&&Array.isArray(projectObj.project.ration_glj.datas)){
                 if(data){
@@ -181,7 +182,7 @@ var ration_glj = {
                 for(let i=0;i<data.rationGljList.length;i++){
                     let temdata = data.rationGljList[i];
                     let newGLJ = {};
-                    newGLJ.projectID = newRation.projectID;
+                    newGLJ.projectID = parseInt(newRation.projectID);
                     newGLJ.GLJID = temdata.gljId;
                     newGLJ.rationID = newRation.ID;
                     newGLJ.billsItemID=newRation.billsItemID,
@@ -346,6 +347,7 @@ var ration_glj = {
                   quantity:0,
                   name:glj.name,
                   code:glj.code,
+                  original_code:glj.code,
                   unit:glj.unit,
                   specs:glj.specs,
                   basePrice:glj.basePrice,
@@ -356,10 +358,17 @@ var ration_glj = {
               }
               if(glj.hasOwnProperty("compilationId")){
                   ration_glj.from="cpt";
+                  if(glj.code.indexOf('-')!=-1){//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
+                      ration_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
+                  }
               }
+
               gljList.push(ration_glj);
           });
-            CommonAjax.post("/rationGlj/addGLJ",gljList,callback);
+          $.bootstrapLoading.start();
+            CommonAjax.post("/rationGlj/addGLJ",gljList,callback,function () {
+                $.bootstrapLoading.end();
+            });
         };
         ration_glj.prototype.replaceGLJ=function (selectCode,oldData,callback) {
             var allGLJ=gljOprObj.AllRecode;
@@ -375,16 +384,23 @@ var ration_glj = {
             oldData.rationItemQuantity=0;
             oldData.name=glj.name;
             oldData.code=glj.code;
+            oldData.original_code=glj.code;
             oldData.unit=glj.unit;
             oldData.specs=glj.specs;
             oldData.basePrice=glj.basePrice;
             oldData.repositoryId=glj.repositoryId;
             if(glj.hasOwnProperty("compilationId")){
                 oldData.from="cpt";
+                if(glj.code.indexOf('-')!=-1){//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
+                    oldData.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
+                }
             }else {
                 oldData.from="std";
             }
-            CommonAjax.post("/rationGlj/replaceGLJ",oldData,callback);
+            $.bootstrapLoading.start();
+            CommonAjax.post("/rationGlj/replaceGLJ",oldData,callback,function () {
+                $.bootstrapLoading.end();
+            });
         };
 
         ration_glj.prototype.mReplaceGLJ=function (selectCode,oldData,callback) {
@@ -396,7 +412,12 @@ var ration_glj = {
             var query={
                 projectID:oldData.projectID,
                 code:oldData.code,
-                name:oldData.name
+                name:oldData.name,
+                unit:oldData.unit,
+                type:oldData.type
+            }
+            if(oldData.specs&&oldData.specs!=''){
+                query.specs=oldData.specs;
             }
             var doc={
                 GLJID:glj.ID,
@@ -404,6 +425,7 @@ var ration_glj = {
                 rationItemQuantity:0,
                 name:glj.name,
                 code:glj.code,
+                original_code:glj.code,
                 unit:glj.unit,
                 specs:glj.specs,
                 type:glj.gljType,
@@ -418,12 +440,16 @@ var ration_glj = {
             }
             if(glj.hasOwnProperty("compilationId")){
                 doc.from="cpt";
+                if(glj.code.indexOf('-')!=-1){//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
+                    doc.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
+                }
             }else {
                 doc.from="std";
             }
-            CommonAjax.post("/rationGlj/mReplaceGLJ",{query:query,doc:doc},callback);
-
-
+            $.bootstrapLoading.start();
+            CommonAjax.post("/rationGlj/mReplaceGLJ",{query:query,doc:doc},callback,function () {
+                $.bootstrapLoading.end();
+            });
         };
         return new ration_glj(project);
     }

+ 45 - 23
web/building_saas/main/js/views/glj_view.js

@@ -430,6 +430,11 @@ var gljOprObj = {
         var me = gljOprObj;
         var header = me.setting.header;
         var disable = null;
+        if(me.sheetData[args.row]!=undefined){
+            if(me.sheetData[args.row].isMixRatio){
+                disable = true;
+            }
+        }
         if(header[args.col]&&header[args.col].dataCode=='marketPrice'){
             var type = me.sheetData[args.row].shortName;
             var index= _.indexOf(me.setting.notEditedType,type);
@@ -546,22 +551,25 @@ var gljOprObj = {
         }
     },
     showRationGLJSheetData:function (init) {
-        if(init){
-            this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true);
-            this.sheetData=_.sortBy(this.sheetData,'type');
-            this.addMixRatioToShow();
-            this.initRationTree();
-        }
+        this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true);
+        this.sheetData=_.sortBy(this.sheetData,'type');
+        this.addMixRatioToShow();
+        this.initRationTree(init);
         sheetCommonObj.showData(this.sheet,this.setting,this.sheetData);
 
     },
-    initRationTree:function () {
+    initRationTree:function (init) {
         this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType(this.sheetData));
         for(var i =0;i<this.sheetData.length;i++){
             if(this.sheetData[i].hasOwnProperty('subList')){
-                this.sheet.setTag(i,0,true);
-                this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).visible(false);
-                this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).locked(true);
+                var collapsed = false;
+                if(init){
+                    this.sheetData[i].collapsed=true;
+                    collapsed = true;
+                }else {
+                    collapsed = this.sheetData[i].collapsed==undefined?true:this.sheetData[i].collapsed;
+                }
+                this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).visible(!collapsed);// this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).locked(true);
             }
         }
     },
@@ -709,10 +717,14 @@ var gljOprObj = {
         var recode = me.sheetData[args.row];
         var newval;
         if(updateField=='marketPrice'||updateField=='customQuantity'||updateField=='basePrice'){
-            newval = number_util.checkNumberValue(args.editingText,this.decimalSetting[updateField]);
-            if(!newval){
-                me.sheet.getCell(args.row, args.col).value(recode[updateField]);
-                return;
+            if(args.editingText==null){
+                newval="";
+            }else {
+                newval = number_util.checkNumberValue(args.editingText,this.decimalSetting[updateField]);
+                if(newval==null){
+                    me.sheet.getCell(args.row, args.col).value(recode[updateField]);
+                    return;
+                }
             }
         }else {
              if(updateField=='name'||updateField=='unit'){
@@ -724,6 +736,9 @@ var gljOprObj = {
              }
             newval=args.editingText==null?"":args.editingText;
         }
+        if(newval === recode[updateField]){//如果值完全相等,则不需要更新
+            return
+        }
         if(updateField=='marketPrice'||updateField=='basePrice'){
             projectObj.project.projectGLJ.updatePriceFromRG(recode,updateField,newval);
         } else {
@@ -899,15 +914,17 @@ var gljOprObj = {
             return _.find(gljOprObj.sheetData,{'code':n})?false:true;
         })
         if(gljOprObj.GLJSelection.length>0&&selected&&selected.sourceType==ModuleNames.ration){
+            $("#glj_tree_div").modal('hide');
             project.ration_glj.addGLJByLib(gljOprObj.GLJSelection,selected.data,function (result) {
                 if(result){
                     selected.data.adjustState=result.adjustState;
-                    project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);
+                    //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
+                    project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
                     gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData)
                     gljOprObj.showRationGLJSheetData();
                     project.projectGLJ.loadData();
                     projectObj.mainController.refreshTreeNode([selected]);
-                    $("#glj_tree_div").modal('hide');
+                    $.bootstrapLoading.end();
                 }
             });//doc.rationID=selected.data.ID;
         }else {
@@ -921,6 +938,7 @@ var gljOprObj = {
         var project= projectObj.project;
         var selectCode=gljOprObj.GLJSelection[0];
         var selected = projectObj.project.mainTree.selected;
+        $("#glj_tree_div").modal('hide');
         project.ration_glj.replaceGLJ(selectCode,oldData,function (result) {
             if(result){
                 //result.adjustState;
@@ -932,7 +950,7 @@ var gljOprObj = {
                 selected.data.adjustState=result.adjustState;
                 projectObj.mainController.refreshTreeNode([selected]);
             }
-            $("#glj_tree_div").modal('hide');
+            $.bootstrapLoading.end();
         })
     },
     doMReplaceGLJ:function () {
@@ -940,18 +958,21 @@ var gljOprObj = {
         var oldData=me.sheetData[gljContextMenu.selectedRow];
         var project= projectObj.project;
         var selectCode=me.GLJSelection[0];
+        $("#glj_tree_div").modal('hide');
         project.ration_glj.mReplaceGLJ(selectCode,oldData,function (result) {
             var data=result.data;
             var stateList= result.stateList;
+            var n_index = me.getIndex(data.query,['code','name','specs','unit','type']);
             _.forEach(project.ration_glj.datas,function (t) {
-                if(t.code==data.query.code&&t.name==data.query.name){
+                var t_index =me.getIndex(t,['code','name','specs','unit','type']);
+                if(n_index==t_index){
                     me.updateProperty(t,data.doc);
                 }
             })
             me.showRationGLJSheetData();
             project.projectGLJ.loadData();
             me.refreshStateAfterMreplace(stateList);
-            $("#glj_tree_div").modal('hide');
+            $.bootstrapLoading.end();
         })
     },
     updateProperty:function (obj,doc) {
@@ -1043,7 +1064,7 @@ var gljOprObj = {
                 var recode = data[options.row];
                 if(recode&&recode.hasOwnProperty('subList')){
                     drowRect(ctx,x,y,w,h);
-                    var collapsed = options.sheet.getTag(options.row,options.col);
+                    var collapsed = recode.collapsed==undefined?true:recode.collapsed;//options.sheet.getTag(options.row,options.col);
                     drowSymbol(ctx,x,y,w,h,collapsed);
                 }else if(recode&&recode.isMixRatio){
                     offset= drowSubItem(ctx,x,y,w,h,offset,data[options.row+1]);
@@ -1069,9 +1090,10 @@ var gljOprObj = {
             if(recode&&recode.hasOwnProperty('subList')){
                var hoffset= hitinfo.cellRect.x+3;
                 if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10){
-                    var collapsed =  hitinfo.sheet.getTag(hitinfo.row,hitinfo.col,hitinfo.sheetArea);
-                    collapsed = !collapsed;
-                    hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
+                    var collapsed = recode.collapsed==undefined?true:recode.collapsed;
+                    collapsed = !collapsed
+                    recode.collapsed=collapsed;
+                    //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
                     hitinfo.sheet.getRange(hitinfo.row+1, -1, recode.subList.length, -1).visible(!collapsed);
                     hitinfo.sheet.invalidateLayout();
                     hitinfo.sheet.repaint();