浏览代码

起讫地点

zhangweicheng 6 年之前
父节点
当前提交
12a7fed26c
共有 2 个文件被更改,包括 92 次插入11 次删除
  1. 13 2
      web/building_saas/main/js/models/project_glj.js
  2. 79 9
      web/building_saas/main/js/views/material_calc_view.js

+ 13 - 2
web/building_saas/main/js/models/project_glj.js

@@ -677,8 +677,19 @@ ProjectGLJ.prototype.updateUserFreight =async function (data) {
     try {
         $.bootstrapLoading.start();
         let result = await ajaxPost('/glj/updateUserFreight',data);
-       // this.refreshMaterialCalcCache(sumMap);
-        //materialCalcObj.showDatas();
+        if(data.action == "add"){
+            for(let f of data.freights){
+                materialCalcObj.userFreightList.push(f);
+            }
+        }
+        if(data.action == "update"){
+            for(let u of materialCalcObj.userFreightList){
+                if(u.ID == data.ID){
+                    gljUtil.updateProperty(u,data.doc);
+                }
+            }
+        }
+        materialCalcObj.showFreightDatas();
     }catch (e){
         console.log(e)
     }finally {

+ 79 - 9
web/building_saas/main/js/views/material_calc_view.js

@@ -191,8 +191,6 @@ materialCalcObj = {
         let startCol = _.findIndex(this.freightSetting.header,{'dataCode':'start'});
         let startOptions = this.getUserFreightOptions();
         sheetCommonObj.setComboBox(-1,startCol,this.freightSheet,startOptions,false,true);
-
-
         sel.row =  oldData?_.findIndex(this.freightDatas,{'ID':oldData.ID}):sel.row ;
         this.freightSheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
         this.refreshRationView();
@@ -427,9 +425,39 @@ materialCalcObj = {
              weightCoe:'1',//加权系数
              connect_key:gljUtil.getIndex(material),
              unit_price_file_id:material.unit_price.unit_price_file_id
-         }
+         };
         return newData;
     },
+    getSavedFreight:function (start,material) {
+        let t = null;
+        for(let f of this.userFreightList){
+            if(f.freight.start == start){
+                t = newDatas(f.freight,material);
+                break;
+            }
+        }
+        return t;
+        function newDatas(freight,material) {
+            let doc = {};
+            for(let key in freight){
+                doc[key] = freight[key];
+                if(key == "ID") doc[key] = uuid.v1();
+                if(key == "connect_key") doc[key] = gljUtil.getIndex(material);
+                if(key == "unit_price_file_id") doc[key] = material.unit_price.unit_price_file_id;
+            }
+            return doc;
+        }
+    },
+    checkSavedFreight:function (start) {
+        let t = null;
+        for(let f of this.userFreightList){
+            if(f.freight.start == start){
+                t = f;
+                break;
+            }
+        }
+        return t;
+    },
     onFreightValueChange:function (sender,args) {
         let me = materialCalcObj;
         let dataCode = me.freightSetting.header[args.col].dataCode;
@@ -444,10 +472,19 @@ materialCalcObj = {
             value = value?scMathUtil.roundForObj(value,getDecimal("glj.unitPrice"))+'':'0'//4舍五入加默认为0
         }
         if(args.row >= me.freightDatas.length){//新增
-            let newData = me.getNewFreightData(material);
-            newData[dataCode] = value;
-            newData.calcType = me.getDefualtCalcType();
-            if(newData.calcType == "内蒙古") newData.materialType = "地方材料";
+            let newData = {};
+            let tempFreight = null;
+            if(dataCode == "start"){
+                tempFreight = me.getSavedFreight(value,material);
+            }
+            if(tempFreight){
+                newData = tempFreight;
+            }else {
+                newData = me.getNewFreightData(material);
+                newData[dataCode] = value;
+                newData.calcType = me.getDefualtCalcType();
+                if(newData.calcType == "内蒙古") newData.materialType = "地方材料";
+            }
             projectObj.project.projectGLJ.addFreightCalc([newData],material.id);
         }else {//修改
             let recode = me.freightDatas[args.row];
@@ -477,6 +514,11 @@ materialCalcObj = {
                 if(dataCode == "materialType") doc["unitFreight"] = me.calcNeiMengUnitFreight(recode.kmDistance,value);
                 if(dataCode == "kmDistance") doc["unitFreight"] = me.calcNeiMengUnitFreight(value,recode.materialType);
             }
+            if(dataCode == "start"){
+               let t_f = me.getSavedFreight(value,material);
+               if(t_f) doc = t_f;
+
+            }
             projectObj.project.projectGLJ.updateFreightCalc([{ID:recode.ID,doc:doc}],material.id);
         }
     },
@@ -640,10 +682,20 @@ materialCalcObj = {
 
     },
     saveFreight:function (row) {
+        let me = this;
         let record = this.freightDatas[row];
         if(record){
-            console.log(record);
-            //to do 检查是否已经存在,存在给出是否覆盖提示
+            let exist = this.checkSavedFreight(record.start);
+            if(exist){//已存在的情况,更新
+                let info =`起讫地点“${record.start}”已存在,是否覆盖?`;
+                //to do 检查是否已经存在,存在给出是否覆盖提示
+                hintBox.infoBox('操作确认', info, 2, function () {
+                    me.updateUserFreight(record,exist)
+                }, function () {
+                    //
+                },['确定','取消'],false);
+                return true;
+            }
             let user_freight = {rootProjectID:projectObj.project.projectInfo.property.rootProjectID};
             let f = {};
             for(let key in record){
@@ -653,9 +705,27 @@ materialCalcObj = {
             user_freight.freight = f;
             projectObj.project.projectGLJ.updateUserFreight({freights:[user_freight],action:"add"});
         }
+    },
+
+    updateUserFreight:function (record,userFreight) {
+        let t  = {};
+        for(let t_key in userFreight){
+            if(t_key == "ID") continue;
+            t[t_key] = userFreight[t_key];
+        }
+
+        t.rootProjectID = projectObj.project.projectInfo.property.rootProjectID;
+        let f = {};
+        for(let key in record){
+            f[key] = record[key];
+            if(key =="ration" || key == "ration_gljs")f[key] = [];//下面的定额和工料机不用保存
+        }
+        t.freight = f;
+        projectObj.project.projectGLJ.updateUserFreight({ID:userFreight.ID,doc:t,action:"update"});
 
     },
 
+
     getSideResize: function () {
         let rg_sideResizeEles = {};
         rg_sideResizeEles.eleObj = {