|
|
@@ -128,6 +128,7 @@ materialCalcObj = {
|
|
|
this.freightSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onFreightValueChange);
|
|
|
this.freightSheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onFreightSelectionChange);
|
|
|
this.freightSheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onFreightEditStarting);
|
|
|
+ this.freightSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onFreightPriceRangeChange);
|
|
|
this.freightSheet.name('freight_calc');
|
|
|
if(projectReadOnly){
|
|
|
disableSpread(this.freightSpread);
|
|
|
@@ -172,6 +173,7 @@ materialCalcObj = {
|
|
|
sheetCommonObj.spreadDefaultStyle(this.priceSpread);
|
|
|
this.priceSheet = this.priceSpread.getSheet(0);
|
|
|
sheetCommonObj.initSheet(this.priceSheet, this.priceSetting, 30);
|
|
|
+ this.priceSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onFreightPriceRangeChange);
|
|
|
this.priceSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onPriceValueChange);
|
|
|
this.priceSheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onPriceSelectionChange);
|
|
|
this.priceSheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onPriceEditStarting);
|
|
|
@@ -189,12 +191,12 @@ materialCalcObj = {
|
|
|
this.freightSheet.setRowCount(0);
|
|
|
this.freightDatas = this.getFreightDatas();
|
|
|
sheetCommonObj.showData(this.freightSheet, this.freightSetting,this.freightDatas);
|
|
|
- this.freightSheet.setRowCount(this.freightDatas+20);
|
|
|
+ this.freightSheet.setRowCount(this.freightDatas.length+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);
|
|
|
+ sheetCommonObj.setComboBox(-1,startCol,this.freightSheet,startOptions,false,true,5);
|
|
|
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();
|
|
|
@@ -382,6 +384,7 @@ materialCalcObj = {
|
|
|
let me = materialCalcObj;
|
|
|
let dataCode = me.rationSetting.header[args.col].dataCode;
|
|
|
let datas = type == "freight"?me.freightRations:me.priceRations;
|
|
|
+ if(type == 'price' && !gljUtil.isDef(me.getSelectedPrice())) args.cancel = true;//没有选中原价,不可编辑
|
|
|
if(args.row > datas.length){
|
|
|
args.cancel = true;
|
|
|
}else if(args.row == datas.length && dataCode != "code"){
|
|
|
@@ -456,6 +459,7 @@ materialCalcObj = {
|
|
|
if(key == "connect_key") doc[key] = gljUtil.getIndex(material);
|
|
|
if(key == "unit_price_file_id") doc[key] = material.unit_price.unit_price_file_id;
|
|
|
}
|
|
|
+ delete doc._id;
|
|
|
return doc;
|
|
|
}
|
|
|
},
|
|
|
@@ -469,69 +473,100 @@ materialCalcObj = {
|
|
|
}
|
|
|
return t;
|
|
|
},
|
|
|
+ onFreightPriceRangeChange:function (sender,args) {
|
|
|
+ let me = materialCalcObj;
|
|
|
+ let dataMap={};
|
|
|
+ let sheetName = args.sheet.name();
|
|
|
+ for(let c of args.changedCells){
|
|
|
+ let info = {row:c.row,col:c.col,cancel:false};
|
|
|
+ sheetName == 'price_calc'?me.onPriceEditStarting(sender,info): me.onFreightEditStarting(sender,info);
|
|
|
+ if(info.cancel) return me.showDatas();
|
|
|
+ let value= args.sheet.getCell(c.row, c.col).text();
|
|
|
+ if(dataMap[c.row]){
|
|
|
+ dataMap[c.row][c.col]=value;
|
|
|
+ }else{
|
|
|
+ dataMap[c.row] ={};
|
|
|
+ dataMap[c.row][c.col] = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sheetName == 'price_calc'?me.addOrUpdatePriceCalc(dataMap):me.addOrUpdateFreightCalc(dataMap);
|
|
|
+ },
|
|
|
onFreightValueChange:function (sender,args) {
|
|
|
let me = materialCalcObj;
|
|
|
- let dataCode = me.freightSetting.header[args.col].dataCode;
|
|
|
- let value = args.newValue;
|
|
|
+ let dataMap = {};
|
|
|
+ dataMap[args.row]={};
|
|
|
+ dataMap[args.row][args.col] = args.newValue;
|
|
|
+ me.addOrUpdateFreightCalc(dataMap);
|
|
|
+ },
|
|
|
+ addOrUpdateFreightCalc:function (dataMap) {//{2:{col:value}}
|
|
|
+ let me = materialCalcObj;
|
|
|
let material = me.getMaterialSelected();
|
|
|
- if (value&&!sheetCommonObj.checkData(args.col,me.freightSetting,value)) {
|
|
|
- alert('输入的数据类型不对,请重新输入!');
|
|
|
- me.showDatas();
|
|
|
- return;
|
|
|
- }
|
|
|
- if(dataCode != 'start'&&dataCode != 'conveyance'&&dataCode != 'calcType'&&dataCode != 'materialType'){
|
|
|
- value = value?scMathUtil.roundForObj(value,getDecimal("glj.unitPrice"))+'':'0'//4舍五入加默认为0
|
|
|
- }
|
|
|
- if(args.row >= me.freightDatas.length){//新增
|
|
|
+ let addDatas=[],updateDatas=[];
|
|
|
+ for(let row in dataMap) {
|
|
|
+ let t = dataMap[row];
|
|
|
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;
|
|
|
- }
|
|
|
- projectObj.project.projectGLJ.addFreightCalc([newData],material.id);
|
|
|
- }else {//修改
|
|
|
- let recode = me.freightDatas[args.row];
|
|
|
- if(recode[dataCode] == value) return;
|
|
|
let doc = {};
|
|
|
- doc[dataCode] = value;
|
|
|
- if(dataCode == "conveyance"){//如果运输方式从自办运输切换成其它的东西时,要把底下挂的定额和定额工料机都清空
|
|
|
- if(args.oldValue == "自办运输"){
|
|
|
- doc["rations"] = [];
|
|
|
- doc["ration_gljs"] = [];
|
|
|
+ let recode = me.freightDatas[row];
|
|
|
+ for (let col in t) {
|
|
|
+ let value = t[col];
|
|
|
+ let dataCode = me.freightSetting.header[col].dataCode;
|
|
|
+ if (value && !sheetCommonObj.checkData(col, me.freightSetting, value)) {
|
|
|
+ alert('输入的数据类型不对,请重新输入!');
|
|
|
+ return me.showDatas();
|
|
|
}
|
|
|
- if(value == "自办运输"){//当运输工具下拉选择“自办运输”时,“Km运距”、“装卸费单价”、“装卸次数”、“运价增加率(%)”列数据归0,且灰选不可编辑
|
|
|
- doc["kmDistance"] = '0';
|
|
|
- doc["unitLoadingFee"] ='0';
|
|
|
- doc["loadingTimes"] = '0';
|
|
|
- doc["freightIncreaseRate"] = '0';
|
|
|
+ if (dataCode != 'start' && dataCode != 'conveyance' && dataCode != 'calcType' && dataCode != 'materialType') {
|
|
|
+ value = value ? scMathUtil.roundForObj(value, getDecimal("glj.unitPrice")) + '' : '0'//4舍五入加默认为0
|
|
|
}
|
|
|
- if(args.oldValue =="汽车") doc["materialType"] = "";//当运输方式从汽车切换成其它方式时,清空材料类型
|
|
|
+ if (parseInt(row) >= me.freightDatas.length) {//新增
|
|
|
+ let tempFreight = null;
|
|
|
+ if (dataCode == "start") {
|
|
|
+ tempFreight = me.getSavedFreight(value, material);
|
|
|
+ }
|
|
|
+ if (tempFreight) {
|
|
|
+ newData = tempFreight;
|
|
|
+ } else {
|
|
|
+ if(_.isEmpty(newData)) newData = me.getNewFreightData(material);
|
|
|
+ newData[dataCode] = value;
|
|
|
+ }
|
|
|
+ } else {//修改
|
|
|
+ if (recode[dataCode] == value) continue;
|
|
|
+ doc[dataCode] = value;
|
|
|
+ if (dataCode == "conveyance") {//如果运输方式从自办运输切换成其它的东西时,要把底下挂的定额和定额工料机都清空
|
|
|
+ if (recode[dataCode] == "自办运输") {//没改之前的值
|
|
|
+ doc["rations"] = [];
|
|
|
+ doc["ration_gljs"] = [];
|
|
|
+ }
|
|
|
+ if (value == "自办运输") {//当运输工具下拉选择“自办运输”时,“Km运距”、“装卸费单价”、“装卸次数”、“运价增加率(%)”列数据归0,且灰选不可编辑
|
|
|
+ doc["kmDistance"] = '0';
|
|
|
+ doc["unitLoadingFee"] = '0';
|
|
|
+ doc["loadingTimes"] = '0';
|
|
|
+ doc["freightIncreaseRate"] = '0';
|
|
|
+ }
|
|
|
+ if (recode[dataCode] == "汽车") doc["materialType"] = "";//当运输方式从汽车切换成其它方式时,清空材料类型
|
|
|
|
|
|
- }
|
|
|
- /* if(dataCode == "calcType"){
|
|
|
- if(value == "全国") doc["materialType"] = "";
|
|
|
- if(value == "内蒙古"){
|
|
|
- doc["materialType"] = "地方材料";
|
|
|
- doc["unitFreight"] = me.calcNeiMengUnitFreight(recode.kmDistance,"地方材料");
|
|
|
- }
|
|
|
- }*/
|
|
|
+ }
|
|
|
|
|
|
- if(dataCode == "materialType" && value!="") doc["unitFreight"] = me.calcNeiMengUnitFreight(recode.kmDistance,value);
|
|
|
- if(dataCode == "kmDistance" && gljUtil.isDef(recode.materialType)&&recode.materialType!="") doc["unitFreight"] = me.calcNeiMengUnitFreight(value,recode.materialType);
|
|
|
+ if (dataCode == "materialType" && value != "") doc["unitFreight"] = me.calcNeiMengUnitFreight(recode.kmDistance, value);
|
|
|
+ if (dataCode == "kmDistance" && gljUtil.isDef(recode.materialType) && recode.materialType != "") doc["unitFreight"] = me.calcNeiMengUnitFreight(value, recode.materialType);
|
|
|
|
|
|
- if(dataCode == "start"){
|
|
|
- let t_f = me.getSavedFreight(value,material);
|
|
|
- if(t_f) doc = t_f;
|
|
|
+ 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);
|
|
|
+ if (!_.isEmpty(newData)) addDatas.push(newData);
|
|
|
+ if (!_.isEmpty(doc)) updateDatas.push({ID:recode.ID,doc:doc});
|
|
|
+ }
|
|
|
+ if(addDatas.length > 0 && updateDatas.length > 0) {
|
|
|
+ alert("不能同时增加和更新操作");
|
|
|
+ return me.showDatas();
|
|
|
}
|
|
|
+ if(addDatas.length > 0) projectObj.project.projectGLJ.addFreightCalc(addDatas,material.id);
|
|
|
+ if(updateDatas.length > 0) projectObj.project.projectGLJ.updateFreightCalc(updateDatas,material.id);
|
|
|
+
|
|
|
+
|
|
|
},
|
|
|
calcNeiMengUnitFreight:function (tkmDistance,tmaterialType) {
|
|
|
if(!tkmDistance||tkmDistance == '0') return "0";
|
|
|
@@ -631,39 +666,61 @@ materialCalcObj = {
|
|
|
}
|
|
|
|
|
|
},
|
|
|
- onPriceValueChange:function(sender,args){
|
|
|
+ addOrUpdatePriceCalc:function (dataMap) {
|
|
|
let me = materialCalcObj;
|
|
|
- let dataCode = me.priceSetting.header[args.col].dataCode;
|
|
|
- let value = args.newValue;
|
|
|
let material = me.getMaterialSelected();
|
|
|
- //输入有效性判断, to do
|
|
|
- if (value&&!sheetCommonObj.checkData(args.col,me.priceSetting,value)) {
|
|
|
- alert('输入的数据类型不对,请重新输入!');
|
|
|
- me.showDatas();
|
|
|
- return;
|
|
|
- }
|
|
|
- if(dataCode == 'coe'||dataCode == 'supplyPrice'){
|
|
|
- let decimal = dataCode == 'supplyPrice'?getDecimal("glj.unitPriceHasMix"):getDecimal("glj.unitPrice");
|
|
|
- value = value?scMathUtil.roundForObj(value,decimal)+'':'0'//4舍五入加默认为0
|
|
|
- }
|
|
|
- if(args.row >= me.priceDatas.length){//新增
|
|
|
- let newData = {
|
|
|
- ID:uuid.v1(),
|
|
|
- supplyLocation:"",
|
|
|
- supplyPrice:'0',
|
|
|
- coe:'1',
|
|
|
- connect_key:gljUtil.getIndex(material),
|
|
|
- unit_price_file_id:material.unit_price.unit_price_file_id
|
|
|
- };
|
|
|
- newData[dataCode] = value;
|
|
|
- projectObj.project.projectGLJ.addPriceCalc([newData],material.id);
|
|
|
- }else {//修改
|
|
|
- let recode = me.priceDatas[args.row];
|
|
|
- if(recode[dataCode] == value) return;
|
|
|
+ let addDatas=[],updateDatas=[];
|
|
|
+ for(let row in dataMap) {
|
|
|
+ let t = dataMap[row];
|
|
|
let doc = {};
|
|
|
- doc[dataCode] = value;
|
|
|
- projectObj.project.projectGLJ.updatePriceCalc([{ID:recode.ID,doc:doc}],material.id);
|
|
|
+ let recode = me.priceDatas[row];
|
|
|
+ let newData = {};
|
|
|
+ for (let col in t) {
|
|
|
+ let value = t[col];
|
|
|
+ let dataCode = me.priceSetting.header[col].dataCode;;
|
|
|
+ if (value && !sheetCommonObj.checkData(col, me.priceSetting, value)) {
|
|
|
+ alert('输入的数据类型不对,请重新输入!');
|
|
|
+ return me.showDatas();
|
|
|
+ }
|
|
|
+ if(dataCode == 'coe'||dataCode == 'supplyPrice'){
|
|
|
+ let decimal = dataCode == 'supplyPrice'?getDecimal("glj.unitPriceHasMix"):getDecimal("glj.unitPrice");
|
|
|
+ value = value?scMathUtil.roundForObj(value,decimal)+'':'0'//4舍五入加默认为0
|
|
|
+ }
|
|
|
+ if(parseInt(row) >= me.priceDatas.length){//新增
|
|
|
+ if(_.isEmpty(newData)) newData = me.getNewPriceData(material);
|
|
|
+ newData[dataCode] = value;
|
|
|
+ }else {//修改
|
|
|
+ if(recode[dataCode] == value) continue;
|
|
|
+ doc[dataCode] = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!_.isEmpty(newData)) addDatas.push(newData);
|
|
|
+ if (!_.isEmpty(doc)) updateDatas.push({ID:recode.ID,doc:doc});
|
|
|
+ }
|
|
|
+ if(addDatas.length > 0 && updateDatas.length > 0) {
|
|
|
+ alert("不能同时增加和更新操作");
|
|
|
+ return me.showDatas();
|
|
|
}
|
|
|
+ if(addDatas.length > 0) projectObj.project.projectGLJ.addPriceCalc(addDatas,material.id);
|
|
|
+ if(updateDatas.length > 0) projectObj.project.projectGLJ.updatePriceCalc(updateDatas,material.id);
|
|
|
+ },
|
|
|
+ getNewPriceData:function (material) {
|
|
|
+ let newData = {
|
|
|
+ ID:uuid.v1(),
|
|
|
+ supplyLocation:"",
|
|
|
+ supplyPrice:'0',
|
|
|
+ coe:'1',
|
|
|
+ connect_key:gljUtil.getIndex(material),
|
|
|
+ unit_price_file_id:material.unit_price.unit_price_file_id
|
|
|
+ };
|
|
|
+ return newData;
|
|
|
+ },
|
|
|
+ onPriceValueChange:function(sender,args){
|
|
|
+ let me = materialCalcObj;
|
|
|
+ let dataMap = {};
|
|
|
+ dataMap[args.row]={};
|
|
|
+ dataMap[args.row][args.col] = args.newValue;
|
|
|
+ me.addOrUpdatePriceCalc(dataMap);
|
|
|
},
|
|
|
deleteMaterialCal:function (row) {
|
|
|
let record = this.materialDatas[row];//修改材料计算标记的同时还要删除原价计算,运费计算等
|
|
|
@@ -711,6 +768,7 @@ materialCalcObj = {
|
|
|
let user_freight = {rootProjectID:projectObj.project.projectInfo.property.rootProjectID};
|
|
|
let f = {};
|
|
|
for(let key in record){
|
|
|
+ if(key == "_id") continue;
|
|
|
f[key] = record[key];
|
|
|
if(key =="ration" || key == "ration_gljs")f[key] = [];//下面的定额和工料机不用保存
|
|
|
}
|
|
|
@@ -729,6 +787,7 @@ materialCalcObj = {
|
|
|
t.rootProjectID = projectObj.project.projectInfo.property.rootProjectID;
|
|
|
let f = {};
|
|
|
for(let key in record){
|
|
|
+ if(key == "_id") continue;
|
|
|
f[key] = record[key];
|
|
|
if(key =="ration" || key == "ration_gljs")f[key] = [];//下面的定额和工料机不用保存
|
|
|
}
|
|
|
@@ -922,12 +981,7 @@ materialCalcObj = {
|
|
|
return this.getSelectedRecode(this.priceSheet,this.priceDatas)
|
|
|
},
|
|
|
getSelectedRecode:function (sheet,datas) {
|
|
|
- let sel = sheet.getSelections()[0];
|
|
|
- let srow = sel.row == -1||sel.row == ""?0:sel.row;
|
|
|
- if(gljUtil.isDef(srow) && datas.length>srow){
|
|
|
- return datas[srow];
|
|
|
- }
|
|
|
- return null;
|
|
|
+ return sheetCommonObj.getSelectedRecode(sheet,datas);
|
|
|
}
|
|
|
|
|
|
};
|