<template>
	<div class="app-container">
		<search-bar
			:formConfigs="formConfig"
			ref="searchBarForm"
			@headBtnClick="buttonClick" />
		<base-table
			v-loading="dataListLoading"
			:table-props="tableProps"
			:page="listQuery.pageNo"
			:limit="listQuery.pageSize"
			:table-data="tableData">
			<method-btn
				v-if="tableBtn.length"
				slot="handleBtn"
				:width="100"
				label="操作"
				:method-list="tableBtn"
				@clickBtn="handleClick" />
		</base-table>
		<pagination
			:limit.sync="listQuery.pageSize"
			:page.sync="listQuery.pageNo"
			:total="listQuery.total"
			@pagination="getDataList" />
		<base-dialog
			:dialogTitle="addOrEditTitle"
			:dialogVisible="addOrUpdateVisible"
			@cancel="handleCancel"
			@confirm="handleConfirm"
			:before-close="handleCancel"
			width="50%">
			<add-or-update
				ref="addOrUpdate"
				@refreshDataList="successSubmit"></add-or-update>
		</base-dialog>
	</div>
</template>

<script>
import AddOrUpdate from './add-or-updata';
import basicPage from '../mixins/basic-page';
import codeFilter from '../mixins/code-filter';
import { deleteWarehouseStorehouse, getWarehouseStorehousePage, } from "@/api/asrs/warehouseStorehouse";

const tableProps = [
	{
		prop: 'warehouseCode',
		label: '仓库编码',
	},
	{
		prop: 'warehouseName',
		label: '仓库名称',
	},
	{
		prop: 'warehouseStorehouseCode',
		label: '库位编码',
	},
	{
		prop: 'warehouseStorehouseName',
		label: '库位名称',
	},
	{
		prop: 'wareRow',
		label: '排',
    width: 70,
	},
	{
		prop: 'wareColumn',
		label: '列',
    width: 70,
	},
	{
		prop: 'wareLayer',
		label: '层',
    width: 70,
	},
	{
		prop: 'cacheLocation',
		label: '缓存库位',
		filter: codeFilter('isOrno'),
    width: 100,
	},
	{
		prop: 'deactivate',
		label: '是否停用',
		filter: codeFilter('deactivate'),
    width: 100,
	},
	{
		prop: 'notes',
		label: '备注',
	},
];

export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
				getDataListURL: getWarehouseStorehousePage,
				deleteURL: deleteWarehouseStorehouse,
			},
			tableProps,
      bPage: true,
			tableBtn: [
				this.$auth.hasPermi(`asrs:warehouse-storehouse:update`)
					? {
							type: 'edit',
							btnName: '编辑',
					  }
					: undefined,
          this.$auth.hasPermi(`asrs:warehouse-storehouse:delete`)
					? {
							type: 'delete',
							btnName: '删除',
					  }
					: undefined,
			].filter((v)=>v),
			tableData: [],
			formConfig: [
				{
					type: 'input',
					label: '库位编码',
					placeholder: '库位编码',
					param: 'code',
				},
				{
					type: 'input',
					label: '库位名称',
					placeholder: '库位名称',
					param: 'name',
				},
				{
					type: 'button',
					btnName: '搜索',
					name: 'search',
					color: 'primary',
				},
				{
					type: 'separate',
				},
				{
					type: this.$auth.hasPermi('asrs:warehouse-storehouse:create') ? 'button' : '',
					btnName: '新增',
					name: 'add',
					color: 'success',
					plain: true,
				},
				// {
				// 	type: this.$auth.hasPermi('base:factory:create') ? 'separate' : '',
				// },
				// {
				// 	type: this.$auth.hasPermi('base:factory:export') ? 'button' : '',
				// 	btnName: '导出',
				// 	name: 'export',
				// 	color: 'warning',
				// },
			],
		};
	},
	components: {
		AddOrUpdate,
	},
	created() {
		this.listQuery.warehouseId = this.bId;
  },
	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.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.handleExport();
					break;
				default:
					console.log(val);
			}
		},
	},
};
</script>
