<template>
<div class="planInfoDerail">
	<h3 class="detail_title"></h3>
	<a-table bordered :dataSource="tableData" :columns="tableColumns">
		<template #bodyCell="{ column, record,index }">
			<template v-if="column.key === 'INDEX'">
				{{index >= tableData.length-1 ? '合计' : index+1}}
			</template>
		</template>
	</a-table>
</div>
</template>
<script setup>

const tableColumns = [
	{title:'序号',width:100,align:'center',key:'INDEX'},
	{title:'作业类型',dataIndex:'_作业类型'},
	{title:'仓房名称',align:'center',dataIndex:'_仓房名称'},
	{title:'货位名称',align:'center',dataIndex:'_货位名称'},
	{title:'品种',align:'center',dataIndex:'_品种'},
	{title:'性质',align:'center',dataIndex:'_性质'},
	{title:'等级',align:'center',dataIndex:'_等级'},
	{title:'数量',align:'center',dataIndex:'_数量'},
	{title:'入库年限',align:'center',dataIndex:'_入库年限'},
];
const tableData = ref([]);

onMounted(()=>{
	getData();
})

function getData(){
	let data = [{'_库区名称':'aaa',a:1,b:2,c:3}];
	setTotalRow(data);
	tableData.value = data;
}

function setTotalRow(data){
	let totalRow = {};
	let rowKeys = Object.keys(data[0]);
	rowKeys.forEach(v=>{
		totalRow[v] = data.reduce((acc,cur)=>{
			return acc + (cur[v] || 0);
		},0)
		if(isNaN(totalRow[v])){ totalRow[v] = '-'; }
	});
	data.push(totalRow);
}
</script>