<!--
 * @Author: zwq
 * @Date: 2021-11-18 14:16:25
 * @LastEditors: zwq
 * @LastEditTime: 2024-08-09 17:00:46
 * @Description:
-->
<template>
	<base-table
		:table-props="tableProps"
		:page="listQuery.pageNo"
		:limit="listQuery.pageSize"
		:height="300"
		:table-data="tableData"
		v-if="tableData.length > 1" />
    <!-- 一条数据 -->
	<div v-else-if="tableData.length === 1">
		<el-form
			:model="tableData[0]"
			ref="dataForm"
			label-width="100px"
			label-position="top">
			<el-row :gutter="20">
				<el-col :span="12">
					<el-form-item label="物品名称" prop="name">
						<el-input v-model="tableData[0].name" readonly />
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="物品编码" prop="code">
						<el-input v-model="tableData[0].code" readonly />
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="物品规格" prop="specifications">
						<el-input v-model="tableData[0].specifications" readonly />
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="物品批次" prop="batchCode">
						<el-input v-model="tableData[0].batchCode" readonly />
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="数量" prop="num">
						<el-input v-model="tableData[0].num" readonly />
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="物品单位" prop="name">
						<el-input v-model="tableData[0].name" readonly />
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
	</div>
	<!-- 没有数据 -->
	<div class="no-data-bg" v-else></div>
</template>

<script>
import { publicFormatter } from '@/utils/dict';
import { getWarehouseLocationHisDet } from '@/api/warehouse/warehouseRealtimeLocation';

const tableProps = [
	{
		prop: 'name',
		label: '物品名称',
	},
	{
		prop: 'code',
		label: '物品编码',
		width: 160,
	},
	{
		prop: 'specifications',
		label: '物品规格',
	},
	{
		prop: 'batchCode',
		label: '物品批次',
	},
	{
		prop: 'num',
		label: '数量',
	},
	{
		prop: 'unit',
		label: '单位',
		filter: publicFormatter('unit_dict'),
		width: 60,
	},
];
export default {
	data() {
		return {
			tableData: [],
			tableProps,
			listQuery: {
				pageSize: 100,
				pageNo: 1,
				total: 1,
			},
			dataListLoading: false,
		};
	},
	methods: {
		// 获取数据列表
		init(id) {
			this.dataListLoading = true;
			getWarehouseLocationHisDet(id).then((response) => {
				this.tableData = response.data;
				this.dataListLoading = false;
			});
		},
	},
};
</script>
