<!--
 * @Author: zwq
 * @Date: 2024-01-17 09:58:41
 * @LastEditors: zwq
 * @LastEditTime: 2024-08-02 16:24:47
 * @Description:
-->
<template>
	<div class="app-container">
		<search-bar
			:formConfigs="formConfig"
			ref="searchBarForm"
			@headBtnClick="buttonClick" />
		<div class="tips">
			<el-tag effect="dark" color="#d3d3d3" style="border: none">空</el-tag>
			<el-tag effect="dark" color="#16DC09" style="border: none">满</el-tag>
			<el-tag effect="dark" color="#ff0000" style="border: none">不可用</el-tag>
		</div>
		<div class="mainbody">
			<div v-for="i in listQuery.total" :key="i">
				<el-row style="margin-bottom: 10px">
					<el-col :span="24">
						<el-row type="flex" class="flex-warp">
							<div
								class="dashboard-layout-item"
								v-for="j in wareData.filter(
									(item) => item.arrange === (i - 1) * 4 + 1
								)"
								:key="j.id + j.name"
								:title="j.name">
								<div class="x-coordinate coordinate" v-if="j.arrange === 1">
									{{ j.col }}
								</div>
								<div class="y-coordinate coordinate" v-if="j.col === 1">
									{{ j.arrange }}
								</div>
								<el-popover
									placement="top-start"
									:title="j.name"
									width="200"
									trigger="click"
									@show="getLocationInfo(j.id)">
									<div v-for="(k, index) in goodsData" :key="index">
										物品名称:
										<span style="margin-left: 5px;">{{ k.name }}</span>
										<br />
										物品数量:
										<span style="margin-left: 5px">{{ k.num }}</span>
										<br />
										入库时间:
										<span style="margin-left: 5px">{{ parseTime(k.inTime) }}</span>
									</div>
									<div
										slot="reference"
										class="hoverDiv"
										:style="{
											cursor: j.enabled === 0 ? 'not-allowed' : 'pointer',
											background:
												j.enabled === 1
													? j.status === 0
														? '#d3d3d3'
														: '#16DC09'
													: '#ff0000',
										}" />
								</el-popover>
							</div>
						</el-row>
						<el-row type="flex" class="flex-warp">
							<div
								class="dashboard-layout-item"
								v-for="j in wareData.filter(
									(item) => item.arrange === (i - 1) * 4 + 2
								)"
								:key="j.id + j.name"
								:title="j.name">
								<div class="y-coordinate coordinate" v-if="j.col === 1">
									{{ j.arrange }}
								</div>
								<el-popover
									placement="top-start"
									:title="j.name"
									width="200"
									trigger="click"
									@show="getLocationInfo(j.id)">
									<div v-for="(k, index) in goodsData" :key="index">
										物品名称:
										<span style="margin-left: 5px">{{ k.name }}</span>
										<br />
										物品数量:
										<span style="margin-left: 5px">{{ k.num }}</span>
										<br />
										入库时间:
										<span style="margin-left: 5px">{{ parseTime(k.inTime) }}</span>
									</div>
									<div
										slot="reference"
										class="hoverDiv"
										:style="{
											cursor: j.enabled === 0 ? 'not-allowed' : 'pointer',
											background:
												j.enabled === 1
													? j.status === 0
														? '#d3d3d3'
														: '#16DC09'
													: '#ff0000',
										}" />
								</el-popover>
							</div>
						</el-row>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="24">
						<el-row type="flex" class="flex-warp">
							<div
								class="dashboard-layout-item"
								v-for="j in wareData.filter(
									(item) => item.arrange === (i - 1) * 4 + 3
								)"
								:key="j.id + j.name"
								:title="j.name">
								<div class="y-coordinate coordinate" v-if="j.col === 1">
									{{ j.arrange }}
								</div>
								<el-popover
									placement="top-start"
									:title="j.name"
									width="200"
									trigger="click"
									@show="getLocationInfo(j.id)">
									<div v-for="(k, index) in goodsData" :key="index">
										物品名称:
										<span style="margin-left: 5px">{{ k.name }}</span>
										<br />
										物品数量:
										<span style="margin-left: 5px">{{ k.num }}</span>
										<br />
										入库时间:
										<span style="margin-left: 5px">{{ parseTime(k.inTime) }}</span>
									</div>
									<div
										slot="reference"
										class="hoverDiv"
										:style="{
											cursor: j.enabled === 0 ? 'not-allowed' : 'pointer',
											background:
												j.enabled === 1
													? j.status === 0
														? '#d3d3d3'
														: '#16DC09'
													: '#ff0000',
										}" />
								</el-popover>
							</div>
						</el-row>
						<el-row type="flex" class="flex-warp">
							<div
								class="dashboard-layout-item"
								v-for="j in wareData.filter((item) => item.arrange === i * 4)"
								:key="j.id + j.name"
								:title="j.name">
								<div class="y-coordinate coordinate" v-if="j.col === 1">
									{{ j.arrange }}
								</div>
								<el-popover
									placement="top-start"
									:title="j.name"
									width="200"
									trigger="click"
									@show="getLocationInfo(j.id)">
									<div v-for="(k, index) in goodsData" :key="index">
										物品名称:
										<span style="margin-left: 5px">{{ k.name }}</span>
										<br />
										物品数量:
										<span style="margin-left: 5px">{{ k.num }}</span>
										<br />
										入库时间:
										<span style="margin-left: 5px">{{ parseTime(k.inTime) }}</span>
									</div>
									<div
										slot="reference"
										class="hoverDiv"
										:style="{
											cursor: j.enabled === 0 ? 'not-allowed' : 'pointer',
											background:
												j.enabled === 1
													? j.status === 0
														? '#d3d3d3'
														: '#16DC09'
													: '#ff0000',
										}" />
								</el-popover>
							</div>
						</el-row>
					</el-col>
				</el-row>
				<el-divider class="divider" v-if="i < listQuery.total"></el-divider>
			</div>
		</div>
	</div>
</template>

<script>
import { listByWarehouse } from '@/api/warehouse/warehouseLocation';
import { getWarehouseRealtimeLocation } from '@/api/warehouse/warehouseRealtimeLocation';

export default {
	data() {
		return {
			listQuery: {
				layer: 1,
				warehouseId: '',
				total: 0,
			},
			wareData: [],
			goodsData: [],
			formConfig: [
				{
					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',
				},
			],
		};
	},
	components: {},
	created() {
		let str = this.$router.currentRoute.path;
		let lastIndex = str.lastIndexOf('/');
		this.listQuery.warehouseId = str.slice(lastIndex + 1);
		this.getDataList();
	},
	methods: {
		buttonClick(val) {
			switch (val.btnName) {
				case 'search':
					this.listQuery.layer = val.value;
					this.getDataList();
					break;
				case 'export':
					// this.handleExport(this.aId);
					break;
				default:
					console.log(val);
			}
		},
		// 获取数据列表
		getDataList() {
			listByWarehouse(this.listQuery).then((response) => {
				this.wareData = response.data;
				this.listQuery.total = Math.ceil(response.data.length / 120);
			});
		},
		getLocationInfo(id) {
			getWarehouseRealtimeLocation(id).then((response) => {
				this.goodsData = response.data;
			});
		},
	},
};
</script>

<style lang="scss" scoped>
.mainbody {
	display: flex;
	flex-direction: column;
	justify-content: space-around;
	min-width: 80vw;
	border-radius: 5px;
	padding-top: 25px;
}
.flex-warp {
	flex-wrap: nowrap;
}
.dashboard-layout-item {
	width: 30px;
	height: 30px;
	background-color: #d3d3d3;
	border-radius: 2px;
	margin: 0 6px 8px 0;
	position: relative;
	&:nth-child(2n) {
		margin-right: 30px;
	}
	&:first-child {
		margin-left: 40px;
	}
	&:last-child {
		margin-right: 30px;
	}
	.coordinate {
		font-weight: bold;
		font-size: 18px;
	}
	.x-coordinate {
		position: absolute;
		top: -25px;
		text-align: center;
		width: 100%;
	}
	.y-coordinate {
		position: absolute;
		line-height: 30px;
		text-align: center;
		width: 20px;
		height: 30px;
		left: -25px;
	}
}
.hoverDiv {
	width: 100%;
	height: 30px;
	&:hover {
		border: 1px #000000 dashed;
		transform: scale(1.3);
	}
}
.el-divider--horizontal {
	margin: 0 0 8px 0;
}
.el-divider {
	background-color: black;
}
.tips {
	position: absolute;
	top: 22px;
	right: 120px;
}
</style>
