瀏覽代碼

bugs 起讫地点

zhangweicheng 6 年之前
父節點
當前提交
8f2bdee96e

+ 30 - 1
modules/all_models/material_calc.js

@@ -101,4 +101,33 @@ let originalSchema = {
     ration_gljs:[ration_glj]
 };
 
-mongoose.model("original_calc", new Schema(originalSchema, {versionKey: false, collection: "original_calc"}));
+mongoose.model("original_calc", new Schema(originalSchema, {versionKey: false, collection: "original_calc"}));
+
+
+let userfreightSchema = {
+    ID:String,
+    unit_price_file_id: Number,
+    connect_key: String,// 关联项目工料机的key 不能关联id,因为单价文件导入别的项目后项目工料机id不同
+    start:String,//起讫地点
+    conveyance:String,//运输工具
+    unitFreight:String,//单位运价
+    kmDistance:String,//km运距
+    unitLoadingFee:String,//装卸费单价
+    loadingTimes:String,//装卸次数
+    otherFee:String,//其它费用
+    freightIncreaseRate:String,//运价增加率
+    weightCoe:String,//加权系数
+    rations:[ration_schema],
+    ration_gljs:[ration_glj],
+    calcType:String,//计算方式
+    materialType:String//材料类型
+};
+
+let user_freights = {
+    ID:{type:String,index: true},
+    userID:{type:String,index: true},
+    compilationID:{type:String,index: true},
+    rootProjectID:Number,
+    freight:userfreightSchema
+};
+mongoose.model("user_freights", new Schema(user_freights, {versionKey: false, collection: "user_freights"}));

+ 13 - 67
modules/glj/controllers/glj_controller.js

@@ -404,56 +404,6 @@ class GLJController extends BaseController {
         response.json(result);
     }
 
-    async addOriginalCalc(request, response){
-        let result={error:0};
-        try {
-            let data = JSON.parse(request.body.data);
-            result.data = await glj_facade.addOriginalCalc(data);
-        }catch (err){
-            logger.err(err);
-            result.error=1;
-            result.message = err.message;
-        }
-        response.json(result);
-    }
-
-    async addFreightCalc(request, response){
-        let result={error:0};
-        try {
-            let data = JSON.parse(request.body.data);
-            result.data = await glj_facade.addFreightCalc(data);
-        }catch (err){
-            logger.err(err);
-            result.error=1;
-            result.message = err.message;
-        }
-        response.json(result);
-    }
-
-    async deletePriceCalc(request, response){
-        let result={error:0};
-        try {
-            let data = JSON.parse(request.body.data);
-            result.data = await glj_facade.deletePriceCalc(data);
-        }catch (err){
-            logger.err(err);
-            result.error=1;
-            result.message = err.message;
-        }
-        response.json(result);
-    }
-    async updateOriginalCalc(request, response){
-        let result={error:0};
-        try {
-            let data = JSON.parse(request.body.data);
-            result.data = await glj_facade.updateOriginalCalc(data);
-        }catch (err){
-            logger.err(err);
-            result.error=1;
-            result.message = err.message;
-        }
-        response.json(result);
-    }
     async updateMaterialCalc(request, response){
         let result={error:0};
         try {
@@ -467,20 +417,6 @@ class GLJController extends BaseController {
         response.json(result);
     }
 
-
-    async updateFreightCalc(request, response){
-        let result={error:0};
-        try {
-            let data = JSON.parse(request.body.data);
-            result.data = await glj_facade.updateFreightCalc(data);
-        }catch (err){
-            logger.err(err);
-            result.error=1;
-            result.message = err.message;
-        }
-        response.json(result);
-    }
-
    async updateMaterialCalcTasks(request, response){
        let result={error:0};
        try {
@@ -494,12 +430,11 @@ class GLJController extends BaseController {
        response.json(result);
    }
 
-
-    async deleteFreightCalc(request, response){
+    async updateUserFreight(request, response){
         let result={error:0};
         try {
             let data = JSON.parse(request.body.data);
-            result.data = await glj_facade.deleteFreightCalc(data);
+            result.data = await glj_facade.updateUserFreight(data,request);
         }catch (err){
             logger.err(err);
             result.error=1;
@@ -884,9 +819,20 @@ class GLJController extends BaseController {
             logger.err(err);
         }
         res.json(vvTxtList);
+    }
+
+    async getUserFreights(req,res){
+        let userFreights = [];
+        try {
+            userFreights = await await glj_facade.getUserFreights(req);
+        }catch (err){
+            logger.err(err);
+        }
+        res.json(userFreights);
 
     }
 
+
     async getProjectGLJsByProjectID(projectId){
         return await getGLJListByProjectID(projectId)
     }

+ 20 - 48
modules/glj/facade/glj_facade.js

@@ -6,14 +6,10 @@ module.exports={ //先导出后require可以解决循环引用问题
     changeVvTaxFile:changeVvTaxFile,
     changeAssistProductionFeeRate:changeAssistProductionFeeRate,
     addMixRatioForNew:addMixRatioForNew,
-    addOriginalCalc:addOriginalCalc,
-    deletePriceCalc:deletePriceCalc,
-    updateOriginalCalc:updateOriginalCalc,
-    addFreightCalc:addFreightCalc,
-    deleteFreightCalc:deleteFreightCalc,
-    updateFreightCalc:updateFreightCalc,
     updateMaterialCalc:updateMaterialCalc,
-    updateMaterialCalcTasks:updateMaterialCalcTasks
+    updateMaterialCalcTasks:updateMaterialCalcTasks,
+    updateUserFreight:updateUserFreight,
+    getUserFreights:getUserFreights
 };
 
 const mongoose = require('mongoose');
@@ -27,6 +23,8 @@ let std_glj_lib_gljList_model = mongoose.model('std_glj_lib_gljList');
 let original_calc_model = mongoose.model('original_calc');
 let freight_calc_model = mongoose.model('freight_calc');
 let unit_price_model = mongoose.model('unit_price');
+let user_freights_model = mongoose.model('user_freights');
+
 
 let ration_glj = require('../../ration_glj/facade/ration_glj_facade');
 const uuidV1 = require('uuid/v1');
@@ -191,44 +189,24 @@ async function updateUnitPrice(unitPrice) {//同时支持单个或多个更新
 
 }
 
-async function addOriginalCalc(data) {
-    let datas = data.datas;
-    for(let d of datas){
-        d.ID = uuidV1();
-    }
-    let result = await original_calc_model.create(datas);
-    await updateUnitPrice(data.unitPrice);
-    return result;
-}
-
-
-
-async function addFreightCalc(data){
-    let datas = data.datas;
-    for(let d of datas){
-        d.ID = uuidV1();
+async function updateUserFreight(data,req) {
+    let datas = [];
+    if(data.action == "add"){
+        for(let f of data.freights){
+            f.ID =  uuidV1();
+            f.compilationID = req.session.sessionCompilation._id;
+            f.userID = req.session.sessionUser.id;
+            datas.push(f);
+        }
+        console.log(datas);
+       return await user_freights_model.create(datas);
+    }else if(data.action == "update"){//暂时做成只支持单个更新
+        return await user_freights_model.update({"ID":data.ID},data.doc);
     }
-    let result = await freight_calc_model.create(datas);
-    await updateUnitPrice(data.unitPrice);
-    return result;
 }
 
-async function deletePriceCalc(data){
-    let result = await original_calc_model.deleteOne({ID:data.ID});
-    await updateUnitPrice(data.unitPrice);
-    return result
-}
-
-async function updateOriginalCalc(data){
-    if(data.tasks.length > 0 ) await original_calc_model.bulkWrite(data.tasks);
-    await updateUnitPrice(data.unitPrice);
-    return{};
-}
-
-async function updateFreightCalc(data){
-    if(data.tasks.length > 0 ) await freight_calc_model.bulkWrite(data.tasks);
-    await updateUnitPrice(data.unitPrice);
-    return{};
+async function getUserFreights(req) {
+    return await user_freights_model.find({"userID":req.session.sessionUser.id,"compilationID": req.session.sessionCompilation._id}).lean();
 }
 
 async function updateMaterialCalcTasks(data) {
@@ -280,10 +258,4 @@ async function updateMaterialCalcTasks(data) {
 async function updateMaterialCalc(data) {
     if(data.tasks.length > 0) await unit_price_model.bulkWrite(data.tasks);
     return {}
-}
-
-async function deleteFreightCalc(data){
-    let result = await freight_calc_model.deleteOne({ID:data.ID});
-    await updateUnitPrice(data.unitPrice);
-    return result
 }

+ 2 - 6
modules/glj/routes/glj_router.js

@@ -31,16 +31,12 @@ router.post('/batchUpdateConsumption', gljController.init, gljController.batchUp
 router.post('/modifyKeyValue',gljController.init, gljController.modifyKeyValue);
 router.post('/changeVvTaxFile',gljController.init, gljController.changeVvTaxFile);
 router.post('/changeAssistProductionFeeRate',gljController.init, gljController.changeAssistProductionFeeRate);
-router.post('/addOriginalCalc',gljController.init, gljController.addOriginalCalc);
-router.post('/deletePriceCalc',gljController.init, gljController.deletePriceCalc);
-router.post('/updateOriginalCalc',gljController.init, gljController.updateOriginalCalc);
-router.post('/addFreightCalc',gljController.init, gljController.addFreightCalc);
-router.post('/deleteFreightCalc',gljController.init, gljController.deleteFreightCalc);
-router.post('/updateFreightCalc',gljController.init, gljController.updateFreightCalc);
 router.post('/updateMaterialCalc',gljController.init, gljController.updateMaterialCalc);
 router.post('/updateMaterialCalcTasks',gljController.init, gljController.updateMaterialCalcTasks);
+router.post('/updateUserFreight',gljController.init, gljController.updateUserFreight);
 
 router.get('/getVvTaxList', gljController.init, gljController.getVvTaxList);
+router.get('/getUserFreights', gljController.init, gljController.getUserFreights);
 router.get('/test', gljController.init, gljController.test);
 router.get('/testModify', gljController.init, gljController.testModify);
 router.get('/testDelete', gljController.init, gljController.delete);

+ 2 - 1
public/web/sheet/sheet_common.js

@@ -308,7 +308,7 @@ var sheetCommonObj = {
         sheet.getCell(row, col).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
 
     },
-    setComboBox(row,col,sheet,options,editorValueType){
+    setComboBox(row,col,sheet,options,editorValueType,editable){
         //let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
         let dynamicCombo = sheetCommonObj.getDynamicCombo(true);
         if(options){
@@ -316,6 +316,7 @@ var sheetCommonObj = {
             if(editorValueType==true){
                 dynamicCombo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
             }
+            if(editable) dynamicCombo.editable(true);
         }
         sheet.setCellType(row, col,dynamicCombo,GC.Spread.Sheets.SheetArea.viewport);
     },

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

@@ -496,12 +496,12 @@ ProjectGLJ.prototype.freightCalc= function (glj,grossWeightCoe_n,dataMap,tfreigh
         kmDistance = scMathUtil.roundForObj(kmDistance,unitPirce);
 
         let t = getPrice(unitFreight,kmDistance,conveyance,calcType,materialType,process);//单位运价×km运距
-        console.log(t);
         t = scMathUtil.roundForObj(t*freightIncreaseRate,process);//单位运价×km运距×(1+运距增加率%)
         unitLoadingFee = scMathUtil.roundForObj(unitLoadingFee,unitPirce);
         loadingTimes = scMathUtil.roundForObj(loadingTimes,unitPirce);
         let s = scMathUtil.roundForObj(unitLoadingFee*loadingTimes,process);//装卸费单价×装卸次数
         t = scMathUtil.roundForObj(t + s,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数
+        if(calcType == "内蒙古") t = scMathUtil.roundForObj(t/1.09,process);  //内蒙古要除以税率1.09;
         otherFee = scMathUtil.roundForObj(otherFee,unitPirce);
         t = scMathUtil.roundForObj(t+otherFee,process);//单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用
         t = scMathUtil.roundForObj(t*grossWeightCoe_n,process); //(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重”。 单位毛重:毛重系数
@@ -517,9 +517,9 @@ ProjectGLJ.prototype.freightCalc= function (glj,grossWeightCoe_n,dataMap,tfreigh
 
 
     function getPrice(unitFreight,kmDistance,conveyance,calcType,materialType,process){
+        if(calcType =="内蒙古") return materialCalcObj.calNeiMengTotalFreight(kmDistance,materialType);
         //如果运输方式为自办运输,则直接返回单位运价即可;
-        let price = conveyance == "自办运输"|| calcType =="内蒙古"? scMathUtil.roundForObj(unitFreight,process):scMathUtil.roundForObj(unitFreight * kmDistance,process);//单位运价×km运距
-
+        let price = conveyance == "自办运输" ? scMathUtil.roundForObj(unitFreight,process):scMathUtil.roundForObj(unitFreight * kmDistance,process);//单位运价×km运距
         return price
     }
 
@@ -598,7 +598,6 @@ ProjectGLJ.prototype.m_updateUnitPrice = function (datas) {//批量更新
         }
         return glj;
     }
-
 };
 
 ProjectGLJ.prototype.updateUnitPrice = function(id,unitPrice){
@@ -640,10 +639,8 @@ ProjectGLJ.prototype.updateFreightCalc = async function (datas,pgljID){
     await this.updateMaterialCalcTasks(pgljID,updateMap,"update","freight");
 };
 
-
 ProjectGLJ.prototype.updateMaterialCalcTasks =async function(pgljID,dataMap,actionType,model){
-    //为了统一接口, 参数dataMap 在添加操作时是一个数组,在修改的时候是一个ID - doc 映射表,在删除的时候传入的是一个ID
-
+    //为了统一接口, 参数dataMap 在添加操作时是一个数组,在修改的时候是一个ID - doc 映射表;
     try {
         let actionMap={};
         let calMap = {};
@@ -660,12 +657,8 @@ ProjectGLJ.prototype.updateMaterialCalcTasks =async function(pgljID,dataMap,acti
             } else {
                 sumMap[model] = actionMap;
             }
-        }else if(actionType == "delete"){
-            let IDMap = {};
-            IDMap[dataMap] = true;
-            sumMap[model] = {"delete":IDMap};
         }else {
-            sumMap[model] = actionMap
+            sumMap[model] = actionMap;
         }
         sumMap["unitPrice"] = unitPrices;
 
@@ -678,9 +671,30 @@ ProjectGLJ.prototype.updateMaterialCalcTasks =async function(pgljID,dataMap,acti
     }finally {
         $.bootstrapLoading.end();
     }
+};
 
+ProjectGLJ.prototype.updateUserFreight =async function (data) {
+    try {
+        $.bootstrapLoading.start();
+        let result = await ajaxPost('/glj/updateUserFreight',data);
+       // this.refreshMaterialCalcCache(sumMap);
+        //materialCalcObj.showDatas();
+    }catch (e){
+        console.log(e)
+    }finally {
+        $.bootstrapLoading.end();
+    }
 };
 
+ProjectGLJ.prototype.getUserFreights = async function () {//初始化车船税选择
+    try {
+        let result =  await ajaxGet("/glj/getUserFreights");
+        console.log(result);
+        return result;
+    }catch (e){
+        console.log(e)
+    }
+};
 
 
 ProjectGLJ.prototype.refreshMaterialCalcCache = function (updateMap){
@@ -964,11 +978,15 @@ ProjectGLJ.prototype.calcMaterialRation = function(ID,type){//计算带定额的
 };
 
 ProjectGLJ.prototype.deletePriceCalc = async function (ID,pgljID) {
+    let map = {};
+    map[ID] = true;
     await this.updateMaterialCalcTasks(pgljID,ID,"delete","price");
 };
 
 ProjectGLJ.prototype.deleteFreightCalc = async function (ID,pgljID) {
-    await this.updateMaterialCalcTasks(pgljID,ID,"delete","freight");
+    let map = {};
+    map[ID] = true;
+    await this.updateMaterialCalcTasks(pgljID,map,"delete","freight");
 };
 
 ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) {

+ 92 - 13
web/building_saas/main/js/views/material_calc_view.js

@@ -32,6 +32,7 @@ materialCalcObj = {
     freightSheet:null,
     freightDatas:[],
     conveyanceOptions:["自办运输","汽车","火车","船舶","马车","手推车","拖拉机"],
+    userFreightList:[],
     freightSetting:{
         header:[
             {headerName: "起讫地点", headerWidth: 80, dataCode: "start", dataType: "String"},
@@ -54,8 +55,12 @@ materialCalcObj = {
         getText:{
             forExp:function (item) {
                 let material = materialCalcObj.getMaterialSelected();
+                if(item.calcType == "内蒙古"){
+                  let uString = materialCalcObj.getNeiMengUnitFreightString(item.kmDistance,item.materialType);
+                  return `((${uString}x(1+${item.freightIncreaseRate}%)+${item.unitLoadingFee}x${item.loadingTimes})/1.09+${item.otherFee})x${material.grossWeightCoe_n}x${item.weightCoe}`;
+                }
                 //(单位运价×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重×加权系数
-                if(item.conveyance == "自办运输" || item.calcType == "内蒙古") return `(${item.unitFreight}x(1+${item.freightIncreaseRate}%)+${item.unitLoadingFee}x${item.loadingTimes}+${item.otherFee})x${material.grossWeightCoe_n}x${item.weightCoe}`;
+                if(item.conveyance == "自办运输") return `(${item.unitFreight}x(1+${item.freightIncreaseRate}%)+${item.unitLoadingFee}x${item.loadingTimes}+${item.otherFee})x${material.grossWeightCoe_n}x${item.weightCoe}`;
 
                 //(单位运价×km运距×(1+运距增加率%)+装卸费单价×装卸次数+其它费用)×单位毛重×加权系数
                 return `(${item.unitFreight}x${item.kmDistance}x(1+${item.freightIncreaseRate}%)+${item.unitLoadingFee}x${item.loadingTimes}+${item.otherFee})x${material.grossWeightCoe_n}x${item.weightCoe}`;
@@ -111,7 +116,7 @@ materialCalcObj = {
             this.initRightClick("materialCalcSheet",this.materialSpread)
         }
     },
-    initFreightSpread:function(){
+    initFreightSpread:async function(){
         this.freightSpread = SheetDataHelper.createNewSpread($("#freightSheet")[0]);
         sheetCommonObj.spreadDefaultStyle(this.freightSpread);
         this.freightSheet = this.freightSpread.getSheet(0);
@@ -125,6 +130,7 @@ materialCalcObj = {
         }else {
             this.initRightClick("freightSheet",this.freightSpread)
         }
+        this.userFreightList = await projectObj.project.projectGLJ.getUserFreights();
     },
     initFreightRationSpread:function () {
         this.freightRationSpread = SheetDataHelper.createNewSpread($("#freight_ration_sheet")[0]);
@@ -157,7 +163,7 @@ materialCalcObj = {
             this.initRightClick("price_ration_sheet",this.priceRationSpread);
         }
     },
-    initPriceSpread:function(){
+    initPriceSpread:async function(){
         this.priceSpread = SheetDataHelper.createNewSpread($("#priceSheet")[0]);
         sheetCommonObj.spreadDefaultStyle(this.priceSpread);
         this.priceSheet = this.priceSpread.getSheet(0);
@@ -182,10 +188,22 @@ materialCalcObj = {
         this.freightSheet.setRowCount(this.freightDatas+20);
         let convCol = _.findIndex(this.freightSetting.header,{'dataCode':'conveyance'});
         sheetCommonObj.setComboBox(-1,convCol,this.freightSheet,this.conveyanceOptions,false);
+        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();
     },
+    getUserFreightOptions :function () {
+        let options = [];
+        for(let uf of this.userFreightList){
+            options.push(uf.freight.start);
+        }
+        return options;
+    },
     showFreightRationDatas:function (freight) {
         let sel = this.freightRationSheet.getSelections()[0];
         let oldData = sel.row<this.freightRations.length?this.freightRations[sel.row]:"";
@@ -231,10 +249,10 @@ materialCalcObj = {
         this.priceSheet.setSelection(sel.row==-1?0:sel.row,sel.col,sel.rowCount,sel.colCount);
         this.showPriceRationDatas();
     },
-    showDatas:function(){
+    showDatas:async function(){
         if(!$('#materialCalcSheet').is(':visible')) return;
         if(!this.materialSpread) this.initMaterialSpread();
-        if(!this.freightSpread) this.initFreightSpread();
+        if(!this.freightSpread)await this.initFreightSpread();
         if(!this.priceSpread) this.initPriceSpread();
         if(!this.freightRationSpread) this.initFreightRationSpread();
         if(!this.priceRationSpread) this.initPriceRationSpread();
@@ -462,27 +480,56 @@ materialCalcObj = {
             projectObj.project.projectGLJ.updateFreightCalc([{ID:recode.ID,doc:doc}],material.id);
         }
     },
-    calcNeiMengUnitFreight:function (kmDistance,materialType) {
-        if(!kmDistance||kmDistance == '0') return "0";
+    calcNeiMengUnitFreight:function (tkmDistance,tmaterialType) {
+        if(!tkmDistance||tkmDistance == '0') return "0";
+        let decimal = getDecimal("glj.unitPrice");
+        tkmDistance =  scMathUtil.roundForObj(tkmDistance,decimal);
+        return scMathUtil.roundForObj(this.calNeiMengTotalFreight(tkmDistance,tmaterialType)/tkmDistance,decimal);
+    },
+    calNeiMengTotalFreight:function (kmDistance,materialType) {
+        if(!kmDistance||kmDistance == '0') return 0;
         let decimal = getDecimal("glj.unitPrice");
         let baseMap = {"地方材料":6,"外购材料":13,"沥青、燃料等":19};//"地方材料","外购材料","沥青、燃料等"
         let baseFreight = baseMap[materialType];
         kmDistance =  scMathUtil.roundForObj(kmDistance,decimal);
         //用截取的方式,一段段取值
         let less = kmDistance - 5;//kmDistance <= 5 这段
-        if(less <= 0) return baseFreight+"" ;  //kmDistance <= 5 的时候直接取baseFreight
+        if(less <= 0) return baseFreight ;  //kmDistance <= 5 的时候直接取baseFreight
 
-         //5< kmDistance <= 15  每增运1km 则增加0.6
+        //5< kmDistance <= 15  每增运1km 则增加0.6
         less = less - 10;
-        if(less <=0)  return scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj((less + 10) * 0.6,6),decimal)+"";//baseFreight + (less + 10) * 0.6;
+        if(less <=0)  return scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj((less + 10) * 0.6,6),decimal);//baseFreight + (less + 10) * 0.6;
         baseFreight = baseFreight + 10 * 0.6; //累加5到15这一段的运费;
 
-         //15< kmDistance <= 100  每增运1km 则增加0.45
+        //15< kmDistance <= 100  每增运1km 则增加0.45
         less = less - 85;
-        if(less <=0) return scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj((less + 85)*0.45,6),decimal)+"";//baseFreight + (less + 85)*0.45;
+        if(less <=0) return scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj((less + 85)*0.45,6),decimal);//baseFreight + (less + 85)*0.45;
         baseFreight = scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj(85*0.45,6),6) ;  //累加15到100这一段的运费;
-        return scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj(less * 0.35,6),decimal)+""; // >100 的所有部分每增运1km 则增加0.35  baseFreight + less * 0.35
+        return scMathUtil.roundForObj(baseFreight + scMathUtil.roundForObj(less * 0.35,6),decimal); // >100 的所有部分每增运1km 则增加0.35  baseFreight + less * 0.35
+    },
+
+    getNeiMengUnitFreightString:function (kmDistance,materialType) {
+        if(!kmDistance||kmDistance == '0') return "0";
+        let decimal = getDecimal("glj.unitPrice");
+        let baseMap = {"地方材料":6,"外购材料":13,"沥青、燃料等":19};//"地方材料","外购材料","沥青、燃料等"
+        let baseFreight = baseMap[materialType];
+        kmDistance =  scMathUtil.roundForObj(kmDistance,decimal);
+        let resultString = baseFreight+"";
+        //用截取的方式,一段段取值
+        let less = kmDistance - 5;//kmDistance <= 5 这段
+        if(less <= 0) return resultString ; //kmDistance <= 5 的时候直接取baseFreight
+
+        //5< kmDistance <= 15  每增运1km 则增加0.6
+        less = less - 10;
+        if(less <=0)  return `(${resultString}+0.6x${less + 10})`;//baseFreight + (less + 10) * 0.6;
+        resultString =  `${resultString}+0.6x10`;
+        //15< kmDistance <= 100  每增运1km 则增加0.45
+        less = less - 85;
+        if(less <=0) return `(${resultString}+0.45x${less + 85})`; //baseFreight + (less + 85)*0.45;
+        resultString = `${resultString}+0.45x85`;
+        return `(${resultString}+0.35x${less})`;// >100 的所有部分每增运1km 则增加0.35  baseFreight + less * 0.35
     },
+
     onFreightRationValueChange:function (sender,args) {
         materialCalcObj.onRationValueChange(sender,args,"freight");
     },
@@ -592,6 +639,23 @@ materialCalcObj = {
         projectObj.project.projectGLJ.updateMaterialRation(datas);
 
     },
+    saveFreight:function (row) {
+        let record = this.freightDatas[row];
+        if(record){
+            console.log(record);
+            //to do 检查是否已经存在,存在给出是否覆盖提示
+            let user_freight = {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] = [];//下面的定额和工料机不用保存
+            }
+            user_freight.freight = f;
+            projectObj.project.projectGLJ.updateUserFreight({freights:[user_freight],action:"add"});
+        }
+
+    },
+
     getSideResize: function () {
         let rg_sideResizeEles = {};
         rg_sideResizeEles.eleObj = {
@@ -632,7 +696,22 @@ materialCalcObj = {
                     }
 
                 },
+                "saveFreight":{
+                    name: "保存运输起讫地点",
+                    icon: 'fa-sign-in',
+                    visible:function () {
+                        return id == "freightSheet";
+                    },
+                    disabled: function (){
+                        if(id == "freightSheet") return me.rightClickTarget.row >= me.freightDatas.length;
+                        return me.rightClickTarget.row === undefined;
+                    },
+                    callback:function () {
+                        let row = me.rightClickTarget.row;
+                        me.saveFreight(row);
+                    }
 
+                },
                 "delete": {
                     name: "删除",
                     icon: 'fa-trash-o',