|
@@ -32,6 +32,7 @@ let equipmentPurchaseObj = {
|
|
|
sheetCommonObj.initSheet(this.sheet, this.setting, 0);
|
|
|
this.sheet.bind(GC.Spread.Sheets.Events.ValueChanged,this.onValueChange);
|
|
|
this.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onSheetRangeChange);
|
|
|
+ this.sheet.bind(GC.Spread.Sheets.Events.EditStarting, this.onEditStarting);
|
|
|
this.sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e,args) {
|
|
|
args.sheet.repaint();
|
|
|
equipmentPurchaseObj.checkBtn();
|
|
@@ -147,6 +148,25 @@ let equipmentPurchaseObj = {
|
|
|
this.checkBtn();
|
|
|
$('#equipment_total').text(this.sourceData.total);
|
|
|
},
|
|
|
+ onEditStarting: function (sender, args) {
|
|
|
+ let me = equipmentPurchaseObj;
|
|
|
+ let row = args.row;
|
|
|
+ let col = args.col;
|
|
|
+ if (me.editChecking(row, col) == false) {
|
|
|
+ args.cancel = true;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ editChecking:function (row,col) {
|
|
|
+ let me = equipmentPurchaseObj
|
|
|
+ let dataCode = me.setting.header[col].dataCode;
|
|
|
+ let equipment = me.data[row];
|
|
|
+ let children = me.parentMap[equipment.ID];
|
|
|
+ if(children && children.length>0){//父节点只有这三列才能编辑
|
|
|
+ return dataCode === 'unit'||dataCode === 'name'||dataCode === 'code'
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+
|
|
|
onValueChange:function (e,info) {
|
|
|
let me = equipmentPurchaseObj,row = info.row, col = info.col;
|
|
|
let dataCode = me.setting.header[col].dataCode;
|
|
@@ -165,7 +185,65 @@ let equipmentPurchaseObj = {
|
|
|
data.doc[dataCode] = value;
|
|
|
me.updateEquipments([data]);
|
|
|
},
|
|
|
- calcTotalPrice:function(newValue=0,dataCode,doc,equipment){
|
|
|
+ //计算父节点
|
|
|
+ calcParent:function(updateData){
|
|
|
+ let me = this;
|
|
|
+ let temIDMap = {};
|
|
|
+ let temParentMap = {};
|
|
|
+ for(let d of updateData){
|
|
|
+ if(d.doc){
|
|
|
+ temIDMap[d.ID] = d;
|
|
|
+ if(d.doc.ParentID){
|
|
|
+ temParentMap[d.doc.ParentID]?temParentMap[d.doc.ParentID].push(d):temParentMap[d.doc.ParentID]=[d];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(let d of this.data){
|
|
|
+ let children = this.parentMap[d.ID];
|
|
|
+ let newChildren = temParentMap[d.ID];
|
|
|
+ if((children&&children.length > 0) || (newChildren && newChildren.length > 0)){
|
|
|
+ let totalPrice = getTotalPrice(d.ID);
|
|
|
+ if(d.totalPrice !== totalPrice) updateData.push({ID:d.ID,doc: {totalPrice,unitPrice:'',sparePartCost:'',freight:'',originalPrice:'',quantity:''} })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function getTotalPrice(ID){
|
|
|
+ let sum = 0;
|
|
|
+ let children = me.parentMap[ID];
|
|
|
+ let newChildren = temParentMap[ID];
|
|
|
+ if((children&&children.length > 0) || (newChildren && newChildren.length > 0)){
|
|
|
+ if(children&&children.length > 0){
|
|
|
+ for(let c of children){
|
|
|
+ let newChild = temIDMap[c.ID];
|
|
|
+ if(newChild && newChild.doc){
|
|
|
+ if(newChild.doc.ParentID && newChild.doc.ParentID!=ID) continue;//升级操作时,子节点可能已经不是它的子节点了
|
|
|
+ }
|
|
|
+ let totalPrice = getTotalPrice(c.ID);
|
|
|
+ sum = scMathUtil.roundForObj(sum + totalPrice,getDecimal('process'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(newChildren && newChildren.length > 0){
|
|
|
+ for(let c of newChildren){
|
|
|
+ let totalPrice = getTotalPrice(c.ID);
|
|
|
+ sum = scMathUtil.roundForObj(sum + totalPrice,getDecimal('process'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return scMathUtil.roundForObj(sum,getDecimal('glj.unitPrice'));
|
|
|
+ }
|
|
|
+
|
|
|
+ let tem = temIDMap[ID];
|
|
|
+ if(tem && tem.doc){
|
|
|
+ let doc = tem.doc;
|
|
|
+ if(gljUtil.isDef(doc.totalPrice)) return doc.totalPrice;
|
|
|
+ }
|
|
|
+ return me.IDMap[ID].totalPrice?scMathUtil.roundForObj(me.IDMap[ID].totalPrice,getDecimal('glj.unitPrice')):0
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ calcTotalPrice:function(newValue = 0,dataCode,doc,equipment){
|
|
|
//设备原价
|
|
|
let originalPrice = equipment.originalPrice?scMathUtil.roundForObj(equipment.originalPrice,getDecimal('glj.unitPrice')):0;
|
|
|
//设备运杂费
|
|
@@ -197,7 +275,7 @@ let equipmentPurchaseObj = {
|
|
|
sparePartCost = newValue;
|
|
|
}
|
|
|
|
|
|
- unitPrice = scMathUtil.roundForObj(originalPrice + freight,getDecimal('glj.unitPrice'));
|
|
|
+ unitPrice = scMathUtil.roundForObj(originalPrice + freight,getDecimal('process'));
|
|
|
unitPrice = scMathUtil.roundForObj(unitPrice + sparePartCost,getDecimal('glj.unitPrice'));
|
|
|
doc.unitPrice = unitPrice;
|
|
|
doc.totalPrice = scMathUtil.roundForObj(quantity * unitPrice,getDecimal('glj.unitPrice'));
|
|
@@ -226,6 +304,10 @@ let equipmentPurchaseObj = {
|
|
|
let dataCode = me.setting.header[c.col].dataCode;
|
|
|
let value= args.sheet.getCell(c.row, c.col).text();
|
|
|
let equipment = me.data[c.row];
|
|
|
+ if (me.editChecking(c.row, c.col) == false) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
if (value&&!sheetCommonObj.checkData(c.col,me.setting,value)) {
|
|
|
alert('输入的数据类型不对,请重新输入!');
|
|
|
me.showData();
|
|
@@ -242,19 +324,32 @@ let equipmentPurchaseObj = {
|
|
|
let data = {doc:updateMap[ID],ID:ID};
|
|
|
updateData.push(data);
|
|
|
}
|
|
|
- if(updateData.length > 0) me.updateEquipments(updateData);
|
|
|
+ updateData.length > 0? me.updateEquipments(updateData): me.showData();
|
|
|
},
|
|
|
newEquipment:function(ParentID='-1',seq=0){
|
|
|
return {ID:uuid.v1(),ParentID,seq}
|
|
|
},
|
|
|
sumTotal: function(updateData){
|
|
|
- let dataMap = _.indexBy(updateData, 'ID');
|
|
|
+ let dataMap = {};
|
|
|
+ let temParentMap = {};
|
|
|
let total = 0;
|
|
|
+ for(let d of updateData){
|
|
|
+ if(d.doc){
|
|
|
+ dataMap[d.ID] = d;
|
|
|
+ if(d.doc.ParentID){
|
|
|
+ temParentMap[d.doc.ParentID]?temParentMap[d.doc.ParentID].push(d):temParentMap[d.doc.ParentID]=[d];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
for(let d of this.data){
|
|
|
- let totalPrice = d.totalPrice?scMathUtil.roundForObj(d.totalPrice,getDecimal('glj.unitPrice')):0;
|
|
|
- let data = dataMap[d.ID];
|
|
|
- if(data && gljUtil.isDef(data.doc.totalPrice))totalPrice = data.doc.totalPrice;
|
|
|
- total =scMathUtil.roundForObj(total + totalPrice,getDecimal('glj.unitPrice'))
|
|
|
+ //累加所有底层节点就行
|
|
|
+ if(!this.parentMap[d.ID] && !temParentMap[d.ID] ){
|
|
|
+ let totalPrice = d.totalPrice?scMathUtil.roundForObj(d.totalPrice,getDecimal('glj.unitPrice')):0;
|
|
|
+ let data = dataMap[d.ID];
|
|
|
+ if(data && gljUtil.isDef(data.doc.totalPrice))totalPrice = data.doc.totalPrice;
|
|
|
+ total =scMathUtil.roundForObj(total + totalPrice,getDecimal('glj.unitPrice'))
|
|
|
+ }
|
|
|
}
|
|
|
return total;
|
|
|
},
|
|
@@ -270,6 +365,7 @@ let equipmentPurchaseObj = {
|
|
|
},
|
|
|
updateEquipments:async function(updateData){
|
|
|
try {
|
|
|
+ this.calcParent(updateData);
|
|
|
$.bootstrapLoading.start();
|
|
|
let projectID = projectObj.project.ID();
|
|
|
let total = this.sumTotal(updateData);
|
|
@@ -286,6 +382,7 @@ let equipmentPurchaseObj = {
|
|
|
}
|
|
|
projectObj.project.equipment_purchase.datas.total = total;
|
|
|
} catch (error) {
|
|
|
+ console.log(error);
|
|
|
alert('更新失败,请重试');
|
|
|
}
|
|
|
this.showData();
|