<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"
			:max-height="tableH"
			:table-data="tableData">
			<method-btn
				v-if="tableBtn.length"
				slot="handleBtn"
				:width="90"
				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 { getMoveHisPage } from '@/api/warehouse/warehouseRealtimeLocation';
import { publicFormatter } from '@/utils/dict';
import tableHeightMixin from '@/mixins/tableHeightMixin';

const tableProps = [
	{
		prop: 'oldWarehouseName',
		label: '源仓库名称',
	},
	{
		prop: 'oldWarehouseAreaName',
		label: '源库区名称',
	},
	{
		prop: 'oldCode',
		label: '源库位编码',
		width: 150,
	},
	{
		prop: 'palletCode',
		label: '移动托盘编码',
		width: 150,
	},
	{
		prop: 'goodName',
		label: '物品名称',
		filter: (val) => (val ? val.join(',') : '-'),
	},
	{
		prop: 'newWarehouseName',
		label: '目的仓库',
	},
	{
		prop: 'newWarehouseAreaName',
		label: '目的库区',
	},
	{
		prop: 'newCode',
		label: '目的库位编码',
		width: 150,
	},
	{
		prop: 'createTime',
		label: '操作时间',
		filter: parseTime,
		width: 150,
	},
	{
		prop: 'creator',
		label: '操作人',
	},
];

export default {
	mixins: [basicPage, tableHeightMixin],
	data() {
		return {
			urlOptions: {
				getDataListURL: getMoveHisPage,
			},
			tableData: [],
			tableProps,
			tableBtn: [
				{
					type: 'detail',
					btnName: '详情',
				},
			].filter((v) => v),
			formConfig: [
				{
					type: 'input',
					label: '库位编码',
					placeholder: '库位编码',
					param: 'kcode',
				},
				{
					type: 'input',
					label: '托盘编码',
					placeholder: '托盘编码',
					param: 'tcode',
				},
				{
					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() {},
	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 = '详情';
				this.$nextTick(() => {
					this.$refs.addOrUpdate.init(val.data);
				});
			}
		},
		handleCancel() {
			this.addOrUpdateVisible = false;
			this.addOrEditTitle = '';
		},
	},
};
</script>
<style>
.app-container .el-table .el-table__cell {
	padding: 0;
	height: 35px;
}
</style>