<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"
			:before-close="handleCancel"
			width="50%">
			<add-or-update
				ref="addOrUpdate"
				@refreshDataList="successSubmit"></add-or-update>
			<slot name="footer">
				<el-row slot="footer" type="flex" justify="end">
					<el-col :span="24">
						<el-button size="small" class="btnTextStyle" @click="handleCancel">
							取消
						</el-button>
					</el-col>
				</el-row>
			</slot>
		</base-dialog>
	</div>
</template>

<script>
import AddOrUpdate from './add-or-updata';
import basicPage from '../../mixins/basic-page';
import { parseTime } from '../../mixins/code-filter';
import {
	getWarehouseLocationHisPage,
} from '@/api/warehouse/warehouseRealtimeLocation';
import { listData } from '@/api/system/dict/data';
import { publicFormatter } from '@/utils/dict';

const tableProps = [
	{
		prop: 'warehouseName',
		label: '仓库名称',
	},
	{
		prop: 'name',
		label: '库区名称',
	},
	{
		prop: 'code',
		label: '库位编码',
	},
	{
		prop: 'type',
		label: '库位类型',
		filter: publicFormatter('location_type'),
	},
	{
		prop: 'palletCode',
		label: '托盘编码',
	},
	{
		prop: 'palletCode',
		label: '物品名称',
	},
	{
		prop: 'operateStatus',
		label: '操作状态',
		filter: publicFormatter('warehouse_operate_status'),
	},
	{
		prop: 'createTime',
		label: '操作时间',
		filter: parseTime,
		minWidth: 100,
	},
	{
		prop: 'creator',
		label: '操作人',
	},
];

export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
				getDataListURL: getWarehouseLocationHisPage,
			},
			listQuery: {
				storageType: 1,
			},
			tableData: [],
			tableProps,
			tableBtn: [
				this.$auth.hasPermi(`raw-material:warehouse-location-his:query`)
					? {
							type: 'detail',
							btnName: '详情',
					  }
					: undefined,
			].filter((v) => v),
			drawerVisible: false,
			formConfig: [
				{
					type: 'input',
					label: '库位编码',
					placeholder: '库位编码',
					param: 'kcode',
				},
				{
					type: 'input',
					label: '托盘编码',
					placeholder: '托盘编码',
					param: 'tcode',
				},
				{
					type: 'select',
					label: '操作状态',
					selectOptions: [],
					param: 'status',
					defaultSelect: '',
					filterable: true,
					labelField: 'label',
					valueField: 'value',
				},
				{
					type: 'datePicker',
					label: '操作时间',
					dateType: 'daterange',
					format: 'yyyy-MM-dd',
          valueFormat: "timestamp",
					rangeSeparator: '-',
					startPlaceholder: '开始时间',
					endPlaceholder: '结束时间',
					param: 'searchTime',
				},
				{
					type: 'button',
					btnName: '查询',
					name: 'search',
					color: 'primary',
				},
			],
		};
	},
	components: {
		AddOrUpdate,
	},
	created() {
		const queryParams = {
			pageNo: 1,
			pageSize: 99,
			dictType: 'warehouse_operate_status',
		};
		listData(queryParams).then((response) => {
			this.formConfig[2].selectOptions = response.data.list;
		});
	},
	methods: {
		buttonClick(val) {
			switch (val.btnName) {
				case 'search':
					this.listQuery.pageNo = 1;
					this.listQuery.pageSize = 10;
					this.listQuery.locationCode= val.kcode;
					this.listQuery.palletCode = val.tcode;
					this.listQuery.operateStatus = val.status;
					this.listQuery.createTime = val.searchTime?val.searchTime:null;
					this.getDataList();
					break;
				default:
					console.log(val);
			}
		},
		otherMethods(val) {
			if (val.type === 'detail') {
				this.addOrUpdateVisible = true;
				this.addOrEditTitle = val.data.name + ' -产品信息';
				this.$nextTick(() => {
					this.$refs.addOrUpdate.init(val.data.id);
				});
			}
		},
		handleCancel() {
			this.addOrUpdateVisible = false;
			this.addOrEditTitle = '';
		},
	},
};
</script>
<style>
.app-container .el-table .el-table__cell {
	padding: 0;
	height: 35px;
}
</style>
