<template>
	<view class="warehouse-table-wrap">
		<scroll-view scroll-x class="tableScrollX">
			<wyb-table
				ref="table"
				:headers="headers"
				:contents="contents"
				:width="tableWidth"
				:height="height"
				:first-line-fixed="firstLineFixed"
				@onCellClick="onCellClick"
			/>
		</scroll-view>
	</view>
</template>

<script>
import wybTable from '@/components/wyb-table/wyb-table.vue';

export default {
	components: { wybTable },
	props: {
		headers: { type: Array, default: () => [] },
		contents: { type: Array, default: () => [] },
		height: { type: String, default: 'auto' },
		firstLineFixed: { type: Boolean, default: true },
	},
	computed: {
		tableWidth() {
			const total = (this.headers || []).reduce((sum, col) => sum + (col.width || 160), 0);
			return `${total}rpx`;
		},
	},
	methods: {
		onCellClick(event) {
			if (event && event.lineData) {
				this.$emit('row-click', event.lineData, event);
			}
		},
	},
};
</script>

<style scoped>
.warehouse-table-wrap {
	width: 100%;
	background: #fff;
}
.tableScrollX {
	width: 100%;
}
</style>
