<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"></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>
			<el-table-column
				prop="warehouseStorehouseCode"
				label="库位编码"></el-table-column>
			<el-table-column prop="trayCode" label="托盘编码"></el-table-column>
			<el-table-column prop="process" label="工序">
				<template slot-scope="scope">
					<span>
						{{
							scope.row.process >= 0 ? processArr[scope.row.process].name : ''
						}}
					</span>
				</template>
			</el-table-column>
			<el-table-column prop="cacheLocation" label="缓存库位">
				<template slot-scope="scope">
					<span>{{ scope.row.cacheLocation === 0 ? '否' : '是' }}</span>
				</template>
			</el-table-column>
			<el-table-column prop="warehouseStorehouseState" label="仓库状态">
				<template slot-scope="scope">
					<span>
						{{
							scope.row.warehouseStorehouseState >= 0
								? warehouseStorehouseState[scope.row.warehouseStorehouseState]
										.name
								: ''
						}}
					</span>
				</template>
			</el-table-column>
			<el-table-column label="操作">
				<template v-slot="scope">
					<el-button
						size="mini"
						v-if="scope.row.warehouseStorehouseState === 0"
						type="text"
						@click="handleClick({ data: { id: scope.row }, type: 'in' })"
						v-hasPermi="['asrs:warehouse-storehouse-storage:update']">
						入库
					</el-button>
					<el-button
						size="mini"
						v-if="scope.row.warehouseStorehouseState === 2"
						type="text"
						@click="handleClick({ data: scope.row, type: 'out' })"
						v-hasPermi="['asrs:warehouse-storehouse-storage:update']">
						出库
					</el-button>
					<el-button
						size="mini"
						v-if="scope.row.warehouseStorehouseState === 2"
						type="text"
						@click="handleClick({ data: scope.row, type: 'move' })"
						v-hasPermi="['asrs:warehouse-storehouse-storage:update']">
						移库
					</el-button>
				</template>
			</el-table-column>
		</el-table>
		<pagination
			:limit.sync="listQuery.pageSize"
			:page.sync="listQuery.pageNo"
			:total="listQuery.total"
			@pagination="getDataList" />
		<add-or-update
			v-if="drawerVisible"
			ref="drawerRef"
			:prop-type="2"
			@refreshDataList="getDataList" />
		<base-dialog
			:dialogTitle="addOrEditTitle"
			:dialogVisible="addOrUpdateVisible"
			@cancel="handleCancel"
			@confirm="handleConfirm"
			:before-close="handleCancel"
			width="50%">
			<out-or-move
				ref="addOrUpdate"
				@refreshDataList="successSubmit"></out-or-move>
		</base-dialog>
	</div>
</template>

<script>
import AddOrUpdate from './add-or-updata';
import outOrMove from './out-or-move';
import product from '../product-mini';
import basicPage from '../mixins/basic-page';
import { parseTime } from '../mixins/code-filter';

import { getWarehouseStorehousePage } from '@/api/asrs/warehouseStorehouse';

const processArr = [
	{
		name: '开始',
		id: 0,
	},
	{
		name: '一次分切后',
		id: 1,
	},
	{
		name: '一次分拣后',
		id: 2,
	},
	{
		name: '二次分切后',
		id: 3,
	},
	{
		name: '二次分拣后',
		id: 4,
	},
];
const warehouseStorehouseState = [
	{
		name: '空',
		id: 0,
	},
	{
		name: '锁定',
		id: 1,
	},
	{
		name: '满',
		id: 2,
	},
];
export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
				getDataListURL: getWarehouseStorehousePage,
			},
			tableData: [],
			processArr,
			drawerVisible: false,
			warehouseStorehouseState,
			formConfig: [
				{
					type: 'input',
					label: '库位名',
					placeholder: '库位名',
					param: 'name',
				},
				{
					type: 'input',
					label: '库位编码',
					placeholder: '库位编码',
					param: 'code',
				},
				{
					type: 'input',
					label: '产品名',
					placeholder: '产品名',
					param: 'pname',
				},
				{
					type: 'input',
					label: '产品编码',
					placeholder: '产品编码',
					param: 'pcode',
				},
				{
					type: 'select',
					label: '工序',
					selectOptions: processArr,
					param: 'processId',
					defaultSelect: '',
					filterable: true,
				},
				{
					type: 'select',
					label: '库位状态',
					selectOptions: warehouseStorehouseState,
					param: 'warehouseStorehouseStateId',
					defaultSelect: '',
					filterable: true,
				},
				{
					type: 'button',
					btnName: '搜索',
					name: 'search',
					color: 'primary',
				},
			],
		};
	},
	components: {
		AddOrUpdate,
		product,
		outOrMove,
	},
	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.code;
					this.listQuery.goodName = val.pname;
					this.listQuery.goodCode = val.pcode;
					this.listQuery.process = val.processId;
					this.listQuery.warehouseStorehouseState =
						val.warehouseStorehouseStateId;
					this.getDataList();
					break;
				case 'reset':
					this.$refs.searchBarForm.resetForm();
					this.listQuery = {
            warehouseId:'1696803324030865409',
						pageSize: 10,
						pageNo: 1,
						total: 1,
					};
					this.getDataList();
					break;
				case 'add':
					this.drawerVisible = true;
					this.$nextTick(() => {
						this.$refs.drawerRef.init(id);
					});
					break;
				case 'export':
					this.handleExport();
					break;
				default:
					console.log(val);
			}
		},
		otherMethods(val) {
			if (val.type === 'out') {
				this.addOrUpdateVisible = true;
				this.addOrEditTitle = '出库';
				this.$nextTick(() => {
					this.$refs.addOrUpdate.init(val.data.id, 0);
				});
			} else if (val.type === 'move') {
				this.addOrUpdateVisible = true;
				this.addOrEditTitle = '移库';
				this.$nextTick(() => {
					this.$refs.addOrUpdate.init(val.data.id, 1);
				});
			} else if (val.type === 'in') {
				this.drawerVisible = true;
				this.$nextTick(() => {
					this.$refs.drawerRef.init(val.data.id);
				});
			} else {
				console.log(11);
			}
		},
	},
};
</script>
<style>
.app-container .el-table .el-table__cell {
	padding: 0;
	height: 35px;
}
</style>
