|
|
@@ -70,6 +70,21 @@ let zmhs_obj = {
|
|
|
},
|
|
|
emptyRowHeader: true
|
|
|
},
|
|
|
+ stableSpread:null,
|
|
|
+ stableSheet:null,
|
|
|
+ stableSheetData:null,
|
|
|
+ stableSetting:{
|
|
|
+ header: [
|
|
|
+ {headerName: "材料编号", headerWidth: 100, dataCode: "code", dataType: "String"},
|
|
|
+ {headerName: "材料名称", headerWidth: 100, dataCode: "name", dataType: "String"},
|
|
|
+ {headerName: "调整配合比", headerWidth: 80, dataCode: "adjustProportion", dataType: "String", hAlign: "right", validator:"number", precision: 2}
|
|
|
+ ],
|
|
|
+ view: {
|
|
|
+ lockColumns:["code", "name"],
|
|
|
+ rowHeaderWidth:25
|
|
|
+ },
|
|
|
+ emptyRowHeader: true
|
|
|
+ },
|
|
|
initSpread:function () {
|
|
|
this.initCoeSpread();
|
|
|
this.initAssSpread();
|
|
|
@@ -115,6 +130,18 @@ let zmhs_obj = {
|
|
|
SheetDataHelper.protectdSheet(this.assSheet);
|
|
|
}
|
|
|
},
|
|
|
+ initStableSpread:function () {
|
|
|
+ if(zmhs_obj.stableSpread == null){
|
|
|
+ this.stableSpread = SheetDataHelper.createNewSpread($("#stableSpread")[0]);
|
|
|
+ sheetCommonObj.spreadDefaultStyle(this.stableSpread);
|
|
|
+ this.stableSheet = this.stableSpread.getSheet(0);
|
|
|
+ sheetCommonObj.initSheet(this.stableSheet, this.stableSetting, 30);
|
|
|
+ this.stableSheet.name('ration_stable');
|
|
|
+ this.stableSheet.bind(GC.Spread.Sheets.Events.ValueChanged,this.onStableValueChange);
|
|
|
+ this.stableSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onStableRangeChanged);
|
|
|
+ SheetDataHelper.protectdSheet(this.stableSheet);
|
|
|
+ }
|
|
|
+ },
|
|
|
showCoeData:function (node) {
|
|
|
let preSelections = this.coeSheet.getSelections();
|
|
|
let selected = node?node:projectObj.project.mainTree.selected;
|
|
|
@@ -170,7 +197,18 @@ let zmhs_obj = {
|
|
|
disableSpread(zmhs_obj.cusSpread);
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
+ showStableData: function (node) {
|
|
|
+ // 过滤出定额配合比不为0的数据
|
|
|
+ const stableList = gljOprObj.sheetData.filter(glj => !glj.isMixRatio && glj.rationProportion);
|
|
|
+ this.stableSheetData = stableList;
|
|
|
+ sheetCommonObj.showData(this.stableSheet, this.stableSetting, stableList);
|
|
|
+ const proportionCol = this.stableSetting.header.findIndex(item => item.dataCode === 'adjustProportion');
|
|
|
+ this.stableSheet.getRange(0, proportionCol, stableList.length, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
|
|
|
+ this.stableSheet.getRange(stableList.length, -1, this.stableSheet.getRowCount() - stableList.length, -1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
|
|
|
+ if(projectReadOnly){
|
|
|
+ disableSpread(zmhs_obj.cusSpread);
|
|
|
+ }
|
|
|
+ },
|
|
|
getComboBoxForCodes:function (coe,i) {
|
|
|
this.coeSheet.getCell(i, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
|
|
|
let options = coe.option_list; //coe.option_codes.split("|");
|
|
|
@@ -221,8 +259,8 @@ let zmhs_obj = {
|
|
|
}
|
|
|
}
|
|
|
projectObj.mainController.refreshTreeNode(nodes, false);
|
|
|
-
|
|
|
- let rationID= ration_glj.updateCacheAfterAdjust(result.ration_glj);
|
|
|
+ let rationID = result.ration.ID;
|
|
|
+ ration_glj.updateCacheAfterAdjust(result.ration_glj);
|
|
|
if(result.projectGLJDatas){//有添加、替换、工料机等需重新加载的情况
|
|
|
projectObj.project.projectGLJ.refreshByDatas(result.projectGLJDatas);
|
|
|
if(result.add && result.add.length > 0) ration_glj.addToMainTree(result.add);//这个方法有再去项目工料机那里取价格,所以要在回调里调用,不像替换工料的情况
|
|
|
@@ -231,7 +269,7 @@ let zmhs_obj = {
|
|
|
}else {
|
|
|
ration_glj.reCalcWhenGLJChange({rationID:rationID});
|
|
|
}
|
|
|
- gljOprObj.showRationGLJSheetData(true);
|
|
|
+ gljOprObj.refreshView();
|
|
|
},
|
|
|
|
|
|
deleteGLJs:function (IDs) {
|
|
|
@@ -261,12 +299,19 @@ let zmhs_obj = {
|
|
|
$('#coeSpread').is(':visible')&&this.coeSpread?this.coeSpread.refresh():'';
|
|
|
$('#cusSpread').is(':visible')&&this.cusSpread?this.cusSpread.refresh():'';
|
|
|
$('#assSpread').is(':visible')&&this.assSpread?this.assSpread.refresh():'';
|
|
|
+ $('#stableSpread').is(':visible')&&this.stableSpread?this.stableSpread.refresh():'';
|
|
|
},
|
|
|
showDatas:function () {
|
|
|
if($('#itemCharacterText').is(':visible'))MaterialController.showItemCharacterText()
|
|
|
if($('#coeSpread').is(':visible')) this.showCoeData();
|
|
|
if($('#cusSpread').is(':visible')) this.showCusData();
|
|
|
if($('#assSpread').is(':visible')) this.showAssData();
|
|
|
+ if($('#stableSpread').is(':visible')) this.showStableData();
|
|
|
+ },
|
|
|
+ refreshStableDataIfNeeded: function () {
|
|
|
+ if ($('#stableSpread').is(':visible')) {
|
|
|
+ this.showStableData();
|
|
|
+ }
|
|
|
},
|
|
|
showZMHSData:function (node) {
|
|
|
if(this.coeSpread&& this.assSpread && $('#linkZMHS').hasClass('active')){
|
|
|
@@ -554,6 +599,90 @@ let zmhs_obj = {
|
|
|
}
|
|
|
return true;
|
|
|
},
|
|
|
+ onStableValueChange: function (e, args) {
|
|
|
+ const changeData = [{ row: args.row, col: args.col, value: args.newValue }];
|
|
|
+ zmhs_obj.changeStableValue(changeData);
|
|
|
+ },
|
|
|
+ onStableRangeChanged: function (e, args) {
|
|
|
+ const changeData = args.changedCells.map(cell => {
|
|
|
+ const value = args.sheet.getValue(cell.row, cell.col);
|
|
|
+ return { row: cell.row, col: cell.col, value};
|
|
|
+ });
|
|
|
+ zmhs_obj.changeStableValue(changeData);
|
|
|
+ },
|
|
|
+ changeStableValue: function (data) {
|
|
|
+ const isValid = data.every(cell => _commonUtil.isDef(cell.value) && sheetCommonObj.checkData(cell.col, this.stableSetting, cell.value));
|
|
|
+ if (!isValid) {
|
|
|
+ this.showDatas();
|
|
|
+ alert('输入的数据类型不对,请重新输入!');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const precision = this.stableSetting.header.find(item => item.dataCode === 'adjustProportion').precision;
|
|
|
+ this.handleDataWithPrecision(data, precision);
|
|
|
+ const sheetData = this.getAutoStableSheetData(data, precision);
|
|
|
+ // 获取需要更新的数据
|
|
|
+ const rationGLJ = projectObj.project.ration_glj;
|
|
|
+ const updateProportionList = this.getStablePostData(sheetData);
|
|
|
+ const projectID = projectObj.project.ID();
|
|
|
+ const rationID = projectObj.project.mainTree.selected.data.ID;
|
|
|
+ rationGLJ.updateProportion(updateProportionList, projectID, rationID);
|
|
|
+ },
|
|
|
+ // 将值进行四舍五入处理
|
|
|
+ handleDataWithPrecision: function (data, precision) {
|
|
|
+ data.forEach(cell => {
|
|
|
+ cell.value = scMathUtil.roundTo(cell.value, -precision);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 获取经过自动处理后的表格数据
|
|
|
+ getAutoStableSheetData: function (changedData, precision) {
|
|
|
+ const expectedValue = 100;
|
|
|
+ const unchangedData = [];
|
|
|
+ const col = this.stableSetting.header.findIndex(item => item.dataCode === 'adjustProportion');
|
|
|
+ this.stableSheetData.forEach((item, index) => {
|
|
|
+ const matchData = changedData.find(dItem => dItem.row === index);
|
|
|
+ if (!matchData) {
|
|
|
+ unchangedData.push({ row: index, col: col, value: item.adjustProportion});
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 稳定土各项调整配合比总值必须为100,不为100则自动调整某一项
|
|
|
+ const allData = _.sortBy(changedData.concat(unchangedData), 'row');
|
|
|
+ const total = allData.reduce((acc, cur) => scMathUtil.roundTo(acc + cur.value, -precision), 0);
|
|
|
+ if (total === expectedValue) {
|
|
|
+ return allData;
|
|
|
+ }
|
|
|
+ const autoAdjustData = getAutoAdjustData(changedData, unchangedData);
|
|
|
+ // 排除自动调整行后的总值
|
|
|
+ const exclusionTotal = allData.reduce((acc, cur) =>
|
|
|
+ cur.row !== autoAdjustData.row
|
|
|
+ ? scMathUtil.roundTo(acc + cur.value, -precision)
|
|
|
+ : acc + 0 , 0);
|
|
|
+ const autoAdjustValue = scMathUtil.roundTo(expectedValue - exclusionTotal, -precision);
|
|
|
+ autoAdjustData.value = autoAdjustValue;
|
|
|
+ return allData;
|
|
|
+ // 获取自动调整行数据
|
|
|
+ function getAutoAdjustData(changedData, unchangedData) {
|
|
|
+ debugger;
|
|
|
+ const changedMaxData = changedData[changedData.length - 1];
|
|
|
+ // 如果不存在不变的数据,自动调整行号为:最大变化数据行
|
|
|
+ if (!unchangedData.length) {
|
|
|
+ return changedMaxData;
|
|
|
+ }
|
|
|
+ const unchangedMinData = unchangedData[0];
|
|
|
+ // 如果存在不变的数据,则自动调整配合比的行数据为:比最大变化数据行大的行,或最小未变数据行
|
|
|
+ const greaterData = unchangedData.find(item => item.row > changedMaxData.row);
|
|
|
+ return greaterData ? greaterData : unchangedMinData;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getStablePostData: function (sheetData) {
|
|
|
+ const postData = [];
|
|
|
+ sheetData.forEach(cell => {
|
|
|
+ const originItem = this.stableSheetData[cell.row];
|
|
|
+ if (cell.value !== originItem.adjustProportion) {
|
|
|
+ postData.push({ ID: originItem.ID, adjustProportion: cell.value});
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return postData;
|
|
|
+ },
|
|
|
getSideResize: function () {
|
|
|
let zmhs_sideResizeEles = {};
|
|
|
zmhs_sideResizeEles.eleObj = {
|