|
@@ -18,10 +18,75 @@ let gljComponentOprObj = {
|
|
|
lockedCols:[1, 2, 3]
|
|
|
}
|
|
|
},
|
|
|
+ //生成列头(多单价)(多消耗量)
|
|
|
+ initHeaders: function (priceProperties, consumeAmtProperties) {
|
|
|
+ let headers = [
|
|
|
+ {headerName:"编码",headerWidth:80,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
|
|
|
+ {headerName:"名称",headerWidth:90,dataCode:"name", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
|
|
|
+ {headerName:"单位",headerWidth:45,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
|
|
|
+ ];
|
|
|
+ //生成消耗量列
|
|
|
+ if(!consumeAmtProperties || consumeAmtProperties.length === 0){
|
|
|
+ headers.push({headerName:"消耗量",headerWidth:70,dataCode:"consumeAmt", dataType: "Number", formatter: "0.000", hAlign: "right", vAlign: "center"});
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ for(let consumeAmtProp of consumeAmtProperties){
|
|
|
+ let colData = {
|
|
|
+ headerName: consumeAmtProp.consumeAmt.dataName,
|
|
|
+ headerWidth: 60,
|
|
|
+ dataCode: consumeAmtProp.consumeAmt.dataCode,
|
|
|
+ dataType: 'Number',
|
|
|
+ formatter: '0.000',
|
|
|
+ hAlign: 'right',
|
|
|
+ vAlign: 'center'
|
|
|
+ };
|
|
|
+ headers.push(colData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //生成单价列
|
|
|
+ if(!priceProperties || priceProperties.length === 0){
|
|
|
+ headers.push({headerName:"定额价",headerWidth:80,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"});
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ for(let priceProp of priceProperties){
|
|
|
+ let colData = {
|
|
|
+ headerName: priceProp.price.dataName,
|
|
|
+ headerWidth: 100,
|
|
|
+ dataCode: priceProp.price.dataCode,
|
|
|
+ dataType: 'Number',
|
|
|
+ formatter: '0.00',
|
|
|
+ hAlign: 'right',
|
|
|
+ vAlign: 'center'
|
|
|
+ };
|
|
|
+ headers.push(colData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return headers;
|
|
|
+ },
|
|
|
+ setFrozen: function (sheet) {
|
|
|
+ const fixedHeadersLen = 3;
|
|
|
+ let frozenCol = 0;
|
|
|
+ if(consumeAmtProperties && consumeAmtProperties.length > 0){
|
|
|
+ frozenCol = fixedHeadersLen + consumeAmtProperties.length;
|
|
|
+ }
|
|
|
+ else if(priceProperties && priceProperties.length > 0){
|
|
|
+ frozenCol = fixedHeadersLen + 1;
|
|
|
+ }
|
|
|
+ if(frozenCol > 0){
|
|
|
+ sheet.frozenColumnCount(frozenCol);
|
|
|
+ }
|
|
|
+ },
|
|
|
buildSheet: function(container) {
|
|
|
let me = gljComponentOprObj;
|
|
|
+ //生成人材机组成物表格列头
|
|
|
+ me.setting.header = me.initHeaders(priceProperties, consumeAmtProperties);
|
|
|
+ //生成人材机组成物列映射
|
|
|
+ sheetCommonObj.initColMapping(me, me.setting.header);
|
|
|
+ repositoryGljObj.initPriceCols.call(me, priceProperties, me.colMapping);
|
|
|
+ me.initConsumeAmtCols(consumeAmtProperties, me.colMapping);
|
|
|
me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30, me);
|
|
|
- //sheetCommonObj.bindEscKey(me.workBook, [{sheet: me.workBook.getSheet(0), editStarting: me.onCellEditStart, editEnded: me.onCellEditEnd}]);
|
|
|
+ me.setFrozen(me.workBook.getSheet(0));
|
|
|
+ sheetCommonObj.bindEscKey(me.workBook, [{sheet: me.workBook.getSheet(0), editStarting: me.onCellEditStart, editEnded: me.onCellEditEnd}]);
|
|
|
me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
|
|
|
me.workBook.getSheet(0).setFormatter(-1, 0, "@", GC.Spread.Sheets.SheetArea.viewport);
|
|
|
sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
|
|
@@ -34,9 +99,18 @@ let gljComponentOprObj = {
|
|
|
me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
|
|
|
},
|
|
|
getRowData: function (sheet, row, setting) {
|
|
|
- let rst = {};
|
|
|
+ let rst = {priceProperty: {}, consumeAmtProperty: {}};
|
|
|
for(let i = 0; i < setting.header.length; i++){
|
|
|
- rst[setting.header[i].dataCode] = sheet.getValue(row, i);
|
|
|
+ let v = sheet.getValue(row, i);
|
|
|
+ if(this.pricePropertyCols.includes(i)){
|
|
|
+ rst.priceProperty[setting.header[i].dataCode] = v && v !== '' ? v : 0;
|
|
|
+ }
|
|
|
+ else if(this.consumeAmtPropertyCols.includes(i)){
|
|
|
+ rst.consumeAmtProperty[setting.header[i].dataCode] = v && v !== '' ? v : 0;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ rst[setting.header[i].dataCode] = v;
|
|
|
+ }
|
|
|
}
|
|
|
return rst;
|
|
|
},
|
|
@@ -50,6 +124,63 @@ let gljComponentOprObj = {
|
|
|
}
|
|
|
return component;
|
|
|
},
|
|
|
+ //根据消耗量字段设置组成物消耗量
|
|
|
+ setConsumeAmt: function (component, field, value) {
|
|
|
+ const compareStr = 'consumeAmt';
|
|
|
+ if(field.includes(compareStr)){
|
|
|
+ if(field === compareStr){
|
|
|
+ component[field] = value;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ component['consumeAmtProperty'][field] = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ initConsumeAmtCols: function (consumeAmtProperties, colMapping) {
|
|
|
+ let consumeAmtCols = [],
|
|
|
+ consumeAmtPropertyCols = [];
|
|
|
+ if(!consumeAmtProperties || consumeAmtProperties.length === 0){
|
|
|
+ consumeAmtCols.push(colMapping.fieldToCol['consumeAmt']);
|
|
|
+ }
|
|
|
+ for(let consumeAmtProp of consumeAmtProperties){
|
|
|
+ consumeAmtPropertyCols.push(colMapping.fieldToCol[consumeAmtProp.consumeAmt.dataCode]);
|
|
|
+ consumeAmtCols.push(colMapping.fieldToCol[consumeAmtProp.consumeAmt.dataCode]);
|
|
|
+ }
|
|
|
+ this.consumeAmtCols = consumeAmtCols;
|
|
|
+ this.consumeAmtPropertyCols = consumeAmtPropertyCols;
|
|
|
+ },
|
|
|
+ //消耗量赋初值
|
|
|
+ initConsumeAmt: function (component) {
|
|
|
+ if(!consumeAmtProperties || consumeAmtProperties.length === 0){
|
|
|
+ component.consumeAmt = 0;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ let consumeAmtProperty = {};
|
|
|
+ for(let consumeAmtProp of consumeAmtProperties){
|
|
|
+ consumeAmtProperty[consumeAmtProp.consumeAmt.dataCode] = 0;
|
|
|
+ }
|
|
|
+ component.consumeAmtProperty = consumeAmtProperty;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ consumeAmtChanged: function (component, consumeAmt, col) {
|
|
|
+ if(!consumeAmtProperties || consumeAmtProperties.length === 0){
|
|
|
+ if(consumeAmt !== component.consumeAmt){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if(consumeAmt !== component.consumeAmtProperty[this.colMapping.colToField[col]]){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ consumeAmtIsEqual: function (consumeAmtA, consumeAmtB) {
|
|
|
+ if(!consumeAmtProperties || consumeAmtProperties.length === 0){
|
|
|
+ return consumeAmtA.consumeAmt === consumeAmtB.consumeAmt;
|
|
|
+ }
|
|
|
+ return _.isEqual(consumeAmtA.consumeAmtProperty, consumeAmtB.consumeAmtProperty);
|
|
|
+ },
|
|
|
gljComponentDelOpr: function () {
|
|
|
let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [], removeArr = [], isUpdate = false, updateBasePrc= [];
|
|
|
me.workBook.commandManager().register('gljComponentDel', function () {
|
|
@@ -57,6 +188,7 @@ let gljComponentOprObj = {
|
|
|
if(sels.length > 0 && that.currentComponent.length > 0){
|
|
|
let component = that.currentGlj.component;
|
|
|
for(let i = 0; i < sels.length > 0; i++){
|
|
|
+ let selField = me.colMapping.colToField(sels[i].col);
|
|
|
if(sels[i].colCount === me.setting.header.length){//可删除
|
|
|
for(let j = 0; j < sels[i].rowCount; j++){
|
|
|
if(sels[i].row + j < that.currentComponent.length){
|
|
@@ -65,19 +197,21 @@ let gljComponentOprObj = {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else if(sels[i].col === 0){
|
|
|
+ else if(selField === 'code'){
|
|
|
//编码不可为空
|
|
|
alert("编码不可为空!");
|
|
|
|
|
|
}
|
|
|
- else if(sels[i].col === 4){//消耗量修改为0
|
|
|
+ else if(selField.includes('consumeAmt')){//消耗量修改为0
|
|
|
if(sels[i].row === -1){//全修改
|
|
|
for(let j = 0; j < that.currentComponent.length; j++){
|
|
|
isUpdate = true;
|
|
|
- that.currentComponent[j].consumeAmt = 0;
|
|
|
+ //that.currentComponent[j].consumeAmt = 0;
|
|
|
+ me.setConsumeAmt(that.currentComponent[j], selField, 0);
|
|
|
for(let k = 0; k < component.length; k++){
|
|
|
if(component[k].ID === that.currentComponent[j].ID){
|
|
|
- component[k].consumeAmt = 0;
|
|
|
+ //component[k].consumeAmt = 0;
|
|
|
+ me.setConsumeAmt(component[k], selField, 0);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -87,10 +221,12 @@ let gljComponentOprObj = {
|
|
|
for(let j = 0; j < sels[i].rowCount; j++){
|
|
|
if(sels[i].row + j < that.currentComponent.length){
|
|
|
isUpdate = true;
|
|
|
- that.currentComponent[sels[i].row + j].consumeAmt = 0;
|
|
|
+ me.setConsumeAmt(that.currentComponent[sels[i].row + j], selField, 0);
|
|
|
+ //that.currentComponent[sels[i].row + j].consumeAmt = 0;
|
|
|
for(let k = 0; k < component.length; k++){
|
|
|
if(component[k].ID === that.currentComponent[sels[i].row + j].ID){
|
|
|
- component[k].consumeAmt = 0;
|
|
|
+ //component[k].consumeAmt = 0;
|
|
|
+ me.setConsumeAmt(component[k], selField, 0);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -113,18 +249,8 @@ let gljComponentOprObj = {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //重新计算工料机
|
|
|
- let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
|
|
|
- if(gljBasePrc !== that.currentGlj.basePrice){
|
|
|
- that.currentGlj.basePrice = gljBasePrc;
|
|
|
- that.reshowGljBasePrc(that.currentGlj);
|
|
|
- updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
|
|
|
- }
|
|
|
updateArr.push(that.currentGlj);
|
|
|
me.updateComponent(updateArr);
|
|
|
- if(updateBasePrc.length > 0){
|
|
|
- that.updateRationBasePrcRq(updateBasePrc, me.workBook);
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -195,18 +321,8 @@ let gljComponentOprObj = {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- //重新计算工料机
|
|
|
- let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(gljComponent));
|
|
|
- if(gljBasePrc !== that.currentGlj.basePrice){
|
|
|
- that.currentGlj.basePrice = gljBasePrc;
|
|
|
- that.reshowGljBasePrc(that.currentGlj);
|
|
|
- updateBasePrcArr.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
|
|
|
- }
|
|
|
updateArr.push(that.currentGlj);
|
|
|
me.updateComponent(updateArr);
|
|
|
- if(updateBasePrcArr.length > 0 && that.rationLibs.length > 0){
|
|
|
- that.updateRationBasePrcRq(updateBasePrcArr, me.workBook);
|
|
|
- }
|
|
|
}},
|
|
|
"batchClear": {name: '批量删除消耗量为0的组成物', disabled: insertDis, icon: 'fa-remove', callback: function (key, opt) {
|
|
|
co.insertType = 'batchClear';
|
|
@@ -223,6 +339,7 @@ let gljComponentOprObj = {
|
|
|
},
|
|
|
onCellEditStart: function(sender, args) {
|
|
|
let me = gljComponentOprObj, that = repositoryGljObj;
|
|
|
+ console.log(me.colMapping);
|
|
|
if(me.isPending){
|
|
|
args.cancel = true;
|
|
|
}
|
|
@@ -231,7 +348,8 @@ let gljComponentOprObj = {
|
|
|
let thatRow = that.workBook.getSheet(0).getSelections()[0].row;
|
|
|
if(thatRow < that.currentCache.length){
|
|
|
that.currentGlj = that.currentCache[thatRow];
|
|
|
- if(me.setting.view.lockedCols.indexOf(args.col) !== -1 || !allowComponent.includes(that.currentGlj.gljType) ||
|
|
|
+ //编码和消耗量可编辑
|
|
|
+ if(!(me.colMapping.colToField[args.col] === 'code' || me.colMapping.colToField[args.col].includes('consumeAmt')) || !allowComponent.includes(that.currentGlj.gljType) ||
|
|
|
(that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList)) ||
|
|
|
(args.col === 4 && (!that.currentComponent|| args.row >= that.currentComponent.length))){
|
|
|
args.cancel = true;
|
|
@@ -244,8 +362,10 @@ let gljComponentOprObj = {
|
|
|
onCellEditEnd: function (sender, args) {
|
|
|
let me = gljComponentOprObj, that = repositoryGljObj, updateBasePrc = [];
|
|
|
let gljList = that.gljList, updateArr = [];
|
|
|
+ let dataCode = me.colMapping.colToField[args.col];
|
|
|
//if(args.editingText !== me.currentEditingComponent.code){
|
|
|
- if(args.col === 0 && args.editingText && args.editingText.trim().length > 0 && args.editingText !== me.currentEditingComponent.code){
|
|
|
+ //编辑编码
|
|
|
+ if(dataCode === 'code' && args.editingText && args.editingText.trim().length > 0 && args.editingText !== me.currentEditingComponent.code){
|
|
|
let component = that.currentGlj.component, hasCode = false;
|
|
|
for(let i = 0; i < gljList.length; i++){
|
|
|
if(gljList[i].code === args.editingText){//有效的组成物
|
|
@@ -266,7 +386,13 @@ let gljComponentOprObj = {
|
|
|
rObj.ID = gljList[i].ID;
|
|
|
//rObj.basePrice = gljList[i].basePrice;
|
|
|
if(typeof that.currentComponent[args.row] !== 'undefined'){
|
|
|
- rObj.consumeAmt = that.currentComponent[args.row].consumeAmt;
|
|
|
+ if(!consumeAmtProperties || consumeAmtProperties.length === 0){
|
|
|
+ rObj.consumeAmt = that.currentComponent[args.row].consumeAmt;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ rObj.consumeAmtProperty = that.currentComponent[args.row].consumeAmtProperty;
|
|
|
+ }
|
|
|
+ //rObj.consumeAmt = that.currentComponent[args.row].consumeAmt;
|
|
|
let index;
|
|
|
for(let j = 0; j < component.length; j++){
|
|
|
if(component[j].ID === that.currentComponent[args.row].ID){
|
|
@@ -276,27 +402,12 @@ let gljComponentOprObj = {
|
|
|
}
|
|
|
component.splice(index, 1);
|
|
|
component.splice(index, 0, rObj);
|
|
|
- //计算工料机单价
|
|
|
- let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(component));
|
|
|
- if(gljBasePrc !== that.currentGlj.basePrice){
|
|
|
- that.currentGlj.basePrice = gljBasePrc;
|
|
|
- that.reshowGljBasePrc(that.currentGlj);
|
|
|
- //工料机单价改变,重算引用了该工料机的定额单价
|
|
|
- updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
|
|
|
- }
|
|
|
updateArr.push(that.currentGlj);
|
|
|
}
|
|
|
else{
|
|
|
- rObj.consumeAmt = 0;
|
|
|
+ me.initConsumeAmt(rObj);
|
|
|
+ //rObj.consumeAmt = 0;
|
|
|
component.push(rObj);
|
|
|
- //计算工料机单价
|
|
|
- let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(component));
|
|
|
- if(gljBasePrc !== that.currentGlj.basePrice){
|
|
|
- that.currentGlj.basePrice = gljBasePrc;
|
|
|
- that.reshowGljBasePrc(that.currentGlj);
|
|
|
- //工料机单价改变,重算引用了该工料机的定额单价
|
|
|
- updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
|
|
|
- }
|
|
|
updateArr.push(that.currentGlj);
|
|
|
}
|
|
|
break;
|
|
@@ -329,41 +440,34 @@ let gljComponentOprObj = {
|
|
|
//不存在
|
|
|
}
|
|
|
}
|
|
|
- else if(args.col === 4 && me.currentEditingComponent.code && args.editingText && args.editingText.trim().length > 0){//消耗量
|
|
|
+ //编辑消耗量
|
|
|
+ else if(dataCode.includes('consumeAmt') && me.currentEditingComponent.code && args.editingText && args.editingText.trim().length > 0){//消耗量
|
|
|
let consumeAmt = parseFloat(args.editingText);
|
|
|
- if(!isNaN(consumeAmt) && consumeAmt !== me.currentEditingComponent.consumeAmt){
|
|
|
+ if(!isNaN(consumeAmt) && me.consumeAmtChanged(me.currentEditingComponent, consumeAmt, args.col)){
|
|
|
let roundCons = scMathUtil.roundTo(parseFloat(consumeAmt), -3);
|
|
|
let component = that.currentGlj.component;
|
|
|
for(let i = 0; i < component.length; i++){
|
|
|
if(component[i].ID === that.currentComponent[args.row].ID){
|
|
|
- component[i].consumeAmt = roundCons;
|
|
|
+ me.setConsumeAmt(component[i], dataCode, roundCons);
|
|
|
+ //component[i].consumeAmt = roundCons;
|
|
|
}
|
|
|
}
|
|
|
- that.currentComponent[args.row].consumeAmt = roundCons;
|
|
|
- //计算工料机单价
|
|
|
- let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
|
|
|
- if(gljBasePrc !== that.currentGlj.basePrice){
|
|
|
- that.currentGlj.basePrice = gljBasePrc;
|
|
|
- that.reshowGljBasePrc(that.currentGlj);
|
|
|
- //工料机单价改变,重算引用了该工料机的定额单价
|
|
|
- updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
|
|
|
- }
|
|
|
+ //that.currentComponent[args.row].consumeAmt = roundCons;
|
|
|
+ me.setConsumeAmt(that.currentComponent[args.row], dataCode, roundCons);
|
|
|
updateArr.push(that.currentGlj);
|
|
|
}
|
|
|
else{
|
|
|
//只能输入数值
|
|
|
- args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
|
|
|
- me.currentEditingComponent[me.setting.header[args.col].dataCode]: 0);
|
|
|
+ sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
- args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
|
|
|
- me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
|
|
|
+ sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
|
|
|
}
|
|
|
if(updateArr.length > 0){
|
|
|
me.updateComponent(updateArr);
|
|
|
- if(updateBasePrc.length > 0){
|
|
|
+ if(updateBasePrc.length > 0 && that.rationLibs.length > 0){
|
|
|
me.isPending = true;
|
|
|
that.updateRationBasePrcRq(updateBasePrc, me.workBook, function () {
|
|
|
me.isPending = false;
|
|
@@ -384,8 +488,17 @@ let gljComponentOprObj = {
|
|
|
}
|
|
|
let that = repositoryGljObj;
|
|
|
let maxCol = info.cellRange.col + info.cellRange.colCount - 1;
|
|
|
+ //粘贴的字段只能含有编码和消耗量
|
|
|
+ for(let i = 0; i < info.cellRange.colCount; i++){
|
|
|
+ let col = info.cellRange.col + i;
|
|
|
+ let dataCode = me.colMapping.colToField[col];
|
|
|
+ if(dataCode !== 'code' && !dataCode.includes('consumeAmt')){
|
|
|
+ info.cancel = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
//复制的列数超过正确的列数,不可复制
|
|
|
- if(info.cellRange.col !== 0 && info.cellRange.col !== 4 || info.cellRange.colCount > 1 || (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList))){
|
|
|
+ if(maxCol > me.setting.header.length - 1){
|
|
|
info.cancel = true;
|
|
|
}
|
|
|
},
|
|
@@ -418,7 +531,13 @@ let gljComponentOprObj = {
|
|
|
let obj = {};
|
|
|
obj.ID = gljCache[j].ID;
|
|
|
if(typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'){//更新
|
|
|
- obj.consumeAmt = that.currentComponent[info.cellRange.row + i].consumeAmt;
|
|
|
+ //obj.consumeAmt = that.currentComponent[info.cellRange.row + i].consumeAmt;
|
|
|
+ if(!consumeAmtProperties || consumeAmtProperties.length === 0){
|
|
|
+ obj.consumeAmt = that.currentComponent[info.cellRange.row + i].consumeAmt;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ obj.consumeAmtProperty = that.currentComponent[info.cellRange.row + i].consumeAmtProperty;
|
|
|
+ }
|
|
|
let index;
|
|
|
for(let k = 0; k < component.length; k++){
|
|
|
if(that.currentComponent[info.cellRange.row + i].ID === component[k].ID){
|
|
@@ -430,7 +549,7 @@ let gljComponentOprObj = {
|
|
|
component.splice(index, 0, obj);
|
|
|
}
|
|
|
else{//新增
|
|
|
- obj.consumeAmt = 0;
|
|
|
+ me.initConsumeAmt(obj);
|
|
|
component.push(obj);
|
|
|
}
|
|
|
break;
|
|
@@ -444,10 +563,6 @@ let gljComponentOprObj = {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- /* else{
|
|
|
- me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
|
|
|
- typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
|
|
|
- }*/
|
|
|
}
|
|
|
if(!existCode){
|
|
|
me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
|
|
@@ -455,35 +570,47 @@ let gljComponentOprObj = {
|
|
|
}
|
|
|
}
|
|
|
if(isChange){
|
|
|
- //计算工料机单价
|
|
|
- let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(component));
|
|
|
- if(gljBasePrc !== that.currentGlj.basePrice){
|
|
|
- that.currentGlj.basePrice = gljBasePrc;
|
|
|
- that.reshowGljBasePrc(that.currentGlj);
|
|
|
- updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
|
|
|
- }
|
|
|
updateArr.push(that.currentGlj);
|
|
|
}
|
|
|
}
|
|
|
- else if(info.cellRange.col === 4){
|
|
|
+ //消耗量
|
|
|
+ else if(me.colMapping.colToField[info.cellRange.col].includes('consumeAmt')){
|
|
|
let items = sheetCommonObj.analyzePasteData(me.setting, info);
|
|
|
let row = info.cellRange.row;
|
|
|
for(let i = 0; i < items.length; i++){
|
|
|
if(row + i < that.currentComponent.length){
|
|
|
let currentObj = that.currentComponent[row + i];
|
|
|
- if(items[i].consumeAmt.trim().length > 0 && items[i].consumeAmt !== currentObj.consumeAmt){
|
|
|
- let roundCons = scMathUtil.roundTo(parseFloat(items[i].consumeAmt), -3);
|
|
|
+ if(!me.consumeAmtIsEqual(items[i], currentObj)){
|
|
|
isChange = true;
|
|
|
- currentObj.consumeAmt = roundCons;
|
|
|
- for(let j = 0; j < component.length; j++){
|
|
|
- if(component[j].ID === currentObj.ID){
|
|
|
- component[j].consumeAmt = currentObj.consumeAmt;
|
|
|
- break;
|
|
|
+ if(!consumeAmtProperties || consumeAmtProperties.length === 0){
|
|
|
+ let roundCons = scMathUtil.roundTo(parseFloat(items[i].consumeAmt), -3);
|
|
|
+ currentObj.consumeAmt = roundCons;
|
|
|
+ for(let j = 0; j < component.length; j++){
|
|
|
+ if(component[j].ID === currentObj.ID){
|
|
|
+ component[j].consumeAmt = currentObj.consumeAmt;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ for(let attr in items[i]){
|
|
|
+ //是消耗量字段
|
|
|
+ if(attr.includes('consumeAmt') && items[i][attr] && !isNaN(parseFloat(items[i][attr]))){
|
|
|
+ let roundCons = scMathUtil.roundTo(parseFloat(items[i][attr]), -3);
|
|
|
+ currentObj.consumeAmtProperty[attr] =roundCons;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(let j = 0; j < component.length; j++){
|
|
|
+ if(component[j].ID === currentObj.ID){
|
|
|
+ component[j].consumeAmtProperty = currentObj.consumeAmtProperty;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
- me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, currentObj.consumeAmt);
|
|
|
+ sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
|
|
|
+ //me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, currentObj.consumeAmt);
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
@@ -491,13 +618,6 @@ let gljComponentOprObj = {
|
|
|
}
|
|
|
}
|
|
|
if(isChange){
|
|
|
- //计算工料机单价
|
|
|
- let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
|
|
|
- if(gljBasePrc !== that.currentGlj.basePrice){
|
|
|
- that.currentGlj.basePrice = gljBasePrc;
|
|
|
- that.reshowGljBasePrc(that.currentGlj);
|
|
|
- updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
|
|
|
- }
|
|
|
updateArr.push(that.currentGlj);
|
|
|
}
|
|
|
}
|
|
@@ -512,7 +632,7 @@ let gljComponentOprObj = {
|
|
|
}
|
|
|
else {
|
|
|
sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
|
|
|
- sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, that.currentComponent);
|
|
|
+ sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
|
|
|
}
|
|
|
let focusInter = setInterval(function () {
|
|
|
if(!$('#loadingPage').is(':visible')){
|
|
@@ -534,23 +654,37 @@ let gljComponentOprObj = {
|
|
|
if(result.data[0]){
|
|
|
that.currentComponent = that.getCurrentComponent(result.data[0].component);
|
|
|
sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
|
|
|
- sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, that.currentComponent);
|
|
|
+ sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- reCalGljBasePrc: function (component) {
|
|
|
- let me = gljComponentOprObj, gljBasePrc = 0;
|
|
|
- for(let i = 0; i < component.length; i++){
|
|
|
- let roundBasePrc = scMathUtil.roundTo(parseFloat(component[i].basePrice), -2);
|
|
|
- let roundConsumeAmt = scMathUtil.roundTo(parseFloat(component[i].consumeAmt), -3);
|
|
|
- //gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * parseFloat(component[i].consumeAmt), -2) + gljBasePrc, -2); 旧算法
|
|
|
- gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljBasePrc, me.processDecimal);
|
|
|
- }
|
|
|
- console.log(`scMathUtil.roundTo(gljBasePrc, -2)`);
|
|
|
- console.log(scMathUtil.roundTo(gljBasePrc, -2));
|
|
|
- console.log(scMathUtil.roundTo(gljBasePrc, -3));
|
|
|
- return scMathUtil.roundTo(gljBasePrc, -2);
|
|
|
+ reCalGljBasePrc: function (components) {
|
|
|
+ let me = gljComponentOprObj, re = repositoryGljObj;
|
|
|
+ //只有一个单价的情况,只有一个单价则只有一个消耗量
|
|
|
+ if(!priceProperties || priceProperties.length === 0){
|
|
|
+ let gljBasePrc = 0;
|
|
|
+ for(let i = 0; i < components.length; i++){
|
|
|
+ let roundBasePrc = scMathUtil.roundTo(parseFloat(components[i].basePrice), -2);
|
|
|
+ let roundConsumeAmt = scMathUtil.roundTo(parseFloat(components[i].consumeAmt), -3);
|
|
|
+ gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljBasePrc, me.processDecimal);
|
|
|
+ }
|
|
|
+ return scMathUtil.roundTo(gljBasePrc, -2);
|
|
|
+ }
|
|
|
+ //多单价的情况
|
|
|
+ else {
|
|
|
+ let gljPriceProperty = re.getPriceProperty(priceProperties);
|
|
|
+ for(let priceProp in gljPriceProperty){
|
|
|
+ let consumeAmtField = re.getConsumeAmtField(consumeAmtProperties, priceProp);
|
|
|
+ for(let component of components){
|
|
|
+ let roundBasePrc = scMathUtil.roundTo(parseFloat(component['priceProperty'][priceProp]), -2);
|
|
|
+ let roundConsumeAmt = scMathUtil.roundTo(parseFloat(component['consumeAmtProperty'][consumeAmtField]), -3);
|
|
|
+ gljPriceProperty[priceProp] = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljPriceProperty[priceProp], me.processDecimal);
|
|
|
+ }
|
|
|
+ scMathUtil.roundTo(gljPriceProperty[priceProp], -2);
|
|
|
+ }
|
|
|
+ return gljPriceProperty;
|
|
|
+ }
|
|
|
}
|
|
|
};
|