<template>
	<el-container>
		<el-main class="nopadding">
			<scTable
				ref="table"
				:data="tableData"
				id="exportDiv"
				row-key="id"
				hidePagination
				hideDo
				stripe
			>
				<el-table-column type="index" width="50" fixed="left"/>
				<el-table-column label="产品" prop="物料名" fixed="left" width="120">
				</el-table-column>
				<el-table-column label="总数" prop="总数" fixed="left" width="80">
				</el-table-column>
				<el-table-column v-for="item in lists" :key="item" :label="item">
					<template #default="scope">
						<span v-if="scope.row[item]">{{ scope.row[item] }}</span>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
</template>

<script>
export default {
	name: "inmTotal",
	data() {
		return {
			lists:[],
			tableData:[],
		};
	},
    mounted() {
        let that = this;
		that.getData();
		this.getMgroup();
    },
	methods: {
		getMgroup() {
			let that = this;
			 that.$API.mtm.mgroup.list.req({ page: 0,query:'{name}' }).then(res => {
				let end = res.length-1;
				let arr = res.slice(13,end);
				that.mgroups = arr.forEach(item=>{
					that.lists.push(item.name);
				});
			});
		},
        getData(){
            let that = this;
            let params = {};
			that.$API.bi.dataset.exec.req('mat_p_count', params).then((res) => {
				let data = res.data2.ds0;
				let data2 = [];
				data.forEach(item=>{
				if(item.物料名.indexOf('玻璃棒管')<0){
					data2.push(item);
				}
				})
				data2.forEach(item=>{
					if(item.工序数量分布){
						let obj = JSON.parse(item.工序数量分布);
						for(let key in obj){
							item[key]= obj[key];
						}
					}
				})
				data2.forEach(item=>{
					let total = 0;
					that.lists.forEach(list=>{
						if(item[list]){
							total+= item[list];
						}
					})
					item['总数']= total;
				})
				that.tableData = data2;
			});
        },
	},
};
</script>

<style scoped>
</style>
