<template>
	<div class="app-container">
		<search-bar
			:isFold="true"
			:formConfigs="formConfig"
			ref="searchBarForm"
			@headBtnClick="buttonClick" />
		<el-table
			:data="tableData"
			:header-cell-style="{
				background: '#F2F4F9',
				color: '#606266',
			}"
			border
			v-loading="dataListLoading"
			style="width: 100%"
			ref="dataList">
			<el-table-column type="expand">
				<template slot-scope="scope">
					<product :warehouse-id="scope.row.id" :prop-type="'3'"></product>
				</template>
			</el-table-column>
			<el-table-column prop="warehouseName" label="仓库名"></el-table-column>
			<el-table-column prop="warehouseCode" label="仓库编码"></el-table-column>
			<el-table-column prop="warehouseStorehouseName" label="库位名" />
			<el-table-column
				prop="warehouseStorehouseCode"
				label="库位编码"></el-table-column>
			<el-table-column prop="trayCode" label="托盘编码"></el-table-column>
			<el-table-column
				prop="process"
				label="工序"
				width="110"></el-table-column>
			<el-table-column prop="createTime" label="出入库时间">
				<template v-slot="scope">
					<span>{{ parseTime(scope.row.createTime) }}</span>
				</template>
			</el-table-column>
			<el-table-column
				prop="warehouseStorehouseStorageState"
				label="出入库状态"
				width="100">
				<template slot-scope="scope">
					<span>
						{{
							scope.row.warehouseStorehouseStorageState >= 0
								? warehouseStorehouseStorageState[
										scope.row.warehouseStorehouseStorageState
								  ].name
								: ''
						}}
					</span>
				</template>
			</el-table-column>
		</el-table>
		<pagination
			:limit.sync="listQuery.pageSize"
			:page.sync="listQuery.pageNo"
			:total="listQuery.total"
			@pagination="getDataList" />
	</div>
</template>

<script>
import product from '../product-mini';
import basicPage from '../mixins/basic-page';
import {
	getWarehouseStorehouseStoragePage,
	exportWarehouseStorehouseStorageExcel,
} from '@/api/asrs/warehouseStorehouseStorage';
const warehouseStorehouseStorageState = [
	{
		name: '入库',
		id: 0,
	},
	{
		name: '出库',
		id: 1,
	},
	{
		name: '移库',
		id: 2,
	},
];
const processArr = [
	{
		name: '开始',
		id: 0,
	},
	{
		name: '一次分切后',
		id: 1,
	},
	{
		name: '一次分拣后',
		id: 2,
	},
	{
		name: '二次分切后',
		id: 3,
	},
	{
		name: '二次分拣后',
		id: 4,
	},
];
export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
				getDataListURL: getWarehouseStorehouseStoragePage,
				exportURL: exportWarehouseStorehouseStorageExcel,
			},
			processArr,
			tableData: [],
			warehouseStorehouseStorageState,
			formConfig: [
				{
					type: 'input',
					label: '库位名',
					placeholder: '库位名',
					param: 'name',
				},
				{
					type: 'input',
					label: '库位编码',
					placeholder: '库位编码',
					param: 'kcode',
				},
				{
					type: 'input',
					label: '托盘编码',
					placeholder: '托盘编码',
					param: 'tcode',
				},
				{
					type: 'select',
					label: '出入库状态',
					selectOptions: warehouseStorehouseStorageState,
					param: 'state',
					defaultSelect: '',
					filterable: true,
				},
				{
					type: 'datePicker',
					label: '出入库时间',
					dateType: 'daterange',
					format: 'yyyy-MM-dd',
					valueFormat: 'yyyy-MM-dd HH:mm:ss',
					rangeSeparator: '-',
					startPlaceholder: '开始时间',
					endPlaceholder: '结束时间',
					param: 'searchTime',
				},
				{
					type: 'button',
					btnName: '搜索',
					name: 'search',
					color: 'primary',
				},
				{
					type: 'button',
					btnName: '导出',
					name: 'export',
					color: 'primary',
					plain: true,
				},
			],
		};
	},
	components: {
		product,
	},
	created() {},
	methods: {
		buttonClick(val) {
			switch (val.btnName) {
				case 'search':
					this.listQuery.pageNo = 1;
					this.listQuery.pageSize = 10;
					this.listQuery.warehouseStorehouseName = val.name;
					this.listQuery.warehouseStorehouseCode = val.kcode;
					this.listQuery.trayCode = val.tcode;
					this.listQuery.warehouseStorehouseStorageState = val.state;
					this.listQuery.createTime = val.searchTime;
					this.listQuery.startTime = val.searchTime ? val.searchTime[0] : '';
					this.listQuery.endTime = val.searchTime ? val.searchTime[1] : '';
					this.getDataList();
					break;
				case 'reset':
					this.$refs.searchBarForm.resetForm();
					this.listQuery = {
						pageSize: 10,
						pageNo: 1,
						total: 1,
					};
					this.getDataList();
					break;
				case 'add':
					this.addOrEditTitle = '新增';
					this.addOrUpdateVisible = true;
					this.addOrUpdateHandle();
					break;
				case 'export':
					this.listQuery.pageNo = undefined;
					this.listQuery.pageSize = undefined;
					this.listQuery.warehouseStorehouseName = val.name;
					this.listQuery.warehouseStorehouseCode = val.kcode;
					this.listQuery.trayCode = val.tcode;
					this.listQuery.warehouseStorehouseStorageState = val.state;
					this.listQuery.createTime = val.searchTime;
					this.listQuery.startTime = val.searchTime ? val.searchTime[0] : '';
					this.listQuery.endTime = val.searchTime ? val.searchTime[1] : '';
					this.handleExport(this.listQuery, '出入库历史信息导出');
					break;
				default:
					console.log(val);
			}
		},
	},
};
</script>
<style>
.app-container .el-table .el-table__cell {
	padding: 0;
	height: 35px;
}
.el-table .warning-row {
	background: oldlace;
}

.el-table .success-row {
	background: #f0f9eb;
}
</style>
