<!--
 * @Author: zwq
 * @Date: 2023-08-21 14:26:23
 * @LastEditors: zwq
 * @LastEditTime: 2023-10-12 15:12:25
 * @Description:
-->
<template>
	<div class="app-container">
		<search-bar
			:formConfigs="formConfig"
			ref="searchBarForm"
			@headBtnClick="buttonClick" />
		<div class="tips">
			<el-tag effect="dark" color="#7362F3" style="border: none">满</el-tag>
			<el-tag effect="dark" color="#16DC09" style="border: none">空</el-tag>
			<el-tag effect="dark" color="#FFA08F" style="border: none">锁</el-tag>
		</div>
		<div class="mainbody">
			<div v-for="i in listQuery.total" :key="i">
				<el-row>
					<el-col :span="24">
						<el-row type="flex" class="flex-warp">
							<div
								class="dashboard-layout-item"
								v-for="a in wareData.one.slice((i - 1) * 10, i * 10)"
								:key="a.id + a.warehouseStorehouseCode"
								style="background: #fff8e8; float: left">
								<div
									class="dashboard-layout-item-cricle"
									:style="{
										background: bgColor[a.warehouseStorehouseState],
									}" />
								{{ a.warehouseStorehouseName }}
							</div>
						</el-row>
						<el-row type="flex" class="flex-warp">
							<div
								class="dashboard-layout-item"
								v-for="b in wareData.two.slice((i - 1) * 10, i * 10)"
								:key="b.id + b.warehouseStorehouseCode"
								style="background: #fff8e8; float: left">
								<div
									class="dashboard-layout-item-cricle"
									:style="{
										background: bgColor[b.warehouseStorehouseState],
									}" />
								{{ b.warehouseStorehouseName }}
							</div>
						</el-row>
					</el-col>
				</el-row>
				<el-divider class="divider"></el-divider>
				<el-row>
					<el-col :span="24">
						<el-row type="flex" class="flex-warp">
							<div
								class="dashboard-layout-item"
								v-for="c in wareData.there.slice((i - 1) * 10, i * 10)"
								:key="c.id + c.warehouseStorehouseCode"
								style="background: #fff8e8; float: left">
								<div
									class="dashboard-layout-item-cricle"
									:style="{
										background: bgColor[c.warehouseStorehouseState],
									}" />
								{{ c.warehouseStorehouseName }}
							</div>
						</el-row>
						<el-row type="flex" class="flex-warp">
							<div
								class="dashboard-layout-item"
								v-for="d in wareData.four.slice((i - 1) * 10, i * 10)"
								:key="d.id + d.warehouseStorehouseCode"
								style="background: #fff8e8; float: left">
								<div
									class="dashboard-layout-item-cricle"
									:style="{
										background: bgColor[d.warehouseStorehouseState],
									}" />
								{{ d.warehouseStorehouseName }}
							</div>
						</el-row>
					</el-col>
				</el-row>
			</div>
		</div>
	</div>
</template>

<script>
import basicPage from '../mixins/basic-page';
import {
	getWarehouseStorehouseList,
	exportWarehouseStorehouseExcel,
} from '@/api/asrs/warehouseStorehouse';

export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
				getDataListURL: getWarehouseStorehouseList,
				exportURL: exportWarehouseStorehouseExcel,
			},
			listQuery: {
				stacker: 1,
				wareLayer: 1,
				total: 0,
			},
			wareData: {
				one: [],
				two: [],
				there: [],
				four: [],
			},
			bgColor: ['#16DC09', '#FFA08F', '#7362F3'],
			formConfig: [
				{
					type: 'select',
					label: '选择堆垛机',
					selectOptions: [
						{ id: 1, name: '一号堆垛机' },
						{ id: 2, name: '二号堆垛机' },
						{ id: 3, name: '三号堆垛机' },
						{ id: 4, name: '四号堆垛机' },
					],
					param: 'stacker',
					filterable: true,
					defaultSelect: 1,
					clearable: false,
				},
				{
					type: 'select',
					label: '选择层',
					selectOptions: [
						{ id: 1, name: '1' },
						{ id: 2, name: '2' },
						{ id: 3, name: '3' },
						{ id: 4, name: '4' },
					],
					param: 'value',
					filterable: true,
					defaultSelect: 1,
					clearable: false,
				},
				{
					type: 'button',
					btnName: '搜索',
					name: 'search',
					color: 'primary',
				},
				{
					type: 'button',
					btnName: '下载',
					name: 'export',
					plain: true,
					color: 'primary',
				},
			],
		};
	},
	components: {},
	created() {},
	methods: {
		// 获取数据列表
		getDataList() {
			this.dataListLoading = true;
			(this.wareData = {
				one: [],
				two: [],
				there: [],
				four: [],
			}),
				this.urlOptions.getDataListURL(this.listQuery).then((response) => {
					response.data.forEach((a, b) => {
						if (b % 4 === 0) {
							this.wareData.one.push(a);
						} else if (b % 4 === 1) {
							this.wareData.two.push(a);
						} else if (b % 4 === 2) {
							this.wareData.there.push(a);
						} else if (b % 4 === 3) {
							this.wareData.four.push(a);
						}
					});
					this.listQuery.total = Math.ceil(response.data.length / 40);
					this.dataListLoading = false;
				});
		},
		buttonClick(val) {
			switch (val.btnName) {
				case 'search':
					this.listQuery.wareLayer = val.value;
					this.listQuery.stacker = val.stacker;
					this.getDataList();
					break;
				case 'export':
					this.handleExport(this.aId);
					break;
				default:
					console.log(val);
			}
		},
	},
};
</script>

<style lang="scss" scoped>
.mainbody {
	display: flex;
	gap: 70px;
	flex-direction: column;
}
.flex-warp {
	flex-wrap: nowrap;
}
.dashboard-layout-item {
	width: 100px;
	text-align: center;
	height: 32px;
	box-shadow: 0px 3px 6px 0px rgba(166, 174, 190, 0.8);
	border-radius: 2px 4px 4px 2px;
	margin: 0 3px 8px 0;
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
	.dashboard-layout-item-cricle {
		display: inline-block;
		width: 12px;
		height: 12px;
		border-radius: 6px;
		position: absolute;
		top: 10px;
		left: 5px;
	}
	&:hover {
		cursor: pointer;
    z-index: 10;
		transform: scale(1.3) translateZ(0);
	}
	&:nth-child(2n) {
		margin-right: 30px;
	}
	&:first-child {
		margin-left: 50px;
	}
	&:last-child {
		margin-right: 30px;
	}
}
.el-divider--horizontal {
	margin: 10px 0;
}
.el-divider {
	background-color: black;
}
.tips {
	position: absolute;
	top: 22px;
	right: 120px;
}
</style>
