<vxe-column field="danjia" title="单价" fixed="left" min-width="120">
<template #default="{ row }">
<el-input
@blur="updateData(row)"
v-if="!row.children.length"
v-model="row.danjia"
>
<div slot="suffix" class="customSuffix">元</div>
</el-input>
<span v-else></span>
</template>
</vxe-column>
<vxe-column field="count" title="数量" min-width="120">
<template #default="{ row }">
<el-input
@blur="updateData(row)"
v-if="!row.children.length"
v-model="row.count"
>
<div slot="suffix" class="customSuffix">个</div>
</el-input>
<span v-else></span>
</template>
</vxe-column>
calculateFeiyong(row) {
const feiyong = row.children.reduce((prev, cur) => prev + cur.feiyong, 0);
return feiyong;
},
updateParentNode(row) {
const parentRow = this.tableData.find((x) => x.id === row.parrentId);
if (!parentRow) {
return;
}
if (!row.children.length) {
const feiyong = Number(row.price) * Number(row.count);
row.feiyong = (feiyong || 0);
}
parentRow.feiyong = this.calculateFeiyong(parentRow);
this.updateParentNode(parentRow);
},
updateData(row) {
this.updateParentNode(row);
},