<template>
	<div class="app-container">
		<!-- 搜索工作栏 -->
		<search-bar
			:isFold="true"
			:formConfigs="formConfig"
			ref="searchBarForm"
			@headBtnClick="buttonClick" />

		<!-- 列表 -->
		<base-table
			v-loading="dataListLoading"
			:table-props="tableProps"
			:page="listQuery.pageNo"
			:limit="listQuery.pageSize"
			:table-data="tableData">
		</base-table>
		<pagination
			:limit.sync="listQuery.pageSize"
			:page.sync="listQuery.pageNo"
			:total="listQuery.total"
			@pagination="getDataList" />

	</div>
</template>

<script>
import basicPage from '../../mixins/basic-page';
import { parseTime } from '../../mixins/code-filter';
import {
	getWarehouseRealtimeHisPage,
} from '@/api/warehouse/warehouseRealtime';
import { getListByType } from '@/api/warehouse/warehouseGoods';

import { listData } from '@/api/system/dict/data';
import { publicFormatter } from '@/utils/dict';

const tableProps = [
	{
		prop: 'warehouseName',
		label: '仓库名称',
	},
	{
		prop: 'name',
		label: '物品名称',
	},
	{
		prop: 'code',
		label: '物品编码',
	},
	{
		prop: 'spec',
		label: '物品规格',
	},
	{
		prop: 'num',
		label: '出入库数量',
	},
	{
		prop: 'goodsBatch',
		label: '物品批次',
	},
	{
		prop: 'operateStatus',
		label: '操作状态',
		filter: publicFormatter('warehouse_operate_status'),
	},
	{
		prop: 'operateTime',
		label: '操作时间',
		filter: parseTime,
		minWidth: 100,
	},
	{
		prop: 'operator',
		label: '操作人',
	},
];

export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
				getDataListURL: getWarehouseRealtimeHisPage,
			},
			listQuery: {
				storageType: 1,
			},
			tableData: [],
			tableProps,
			drawerVisible: false,
			formConfig: [
				{
					type: 'select',
					label: '物品名称',
					selectOptions: [],
					param: 'goodsId',
					defaultSelect: '',
					filterable: true,
				},
				{
					type: 'input',
					label: '操作人',
					placeholder: '操作人',
					param: 'operator',
				},
				{
					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: {
	},
	created() {
		const queryParams = {
			pageNo: 1,
			pageSize: 99,
			dictType: 'warehouse_operate_status',
		};
		listData(queryParams).then((response) => {
			this.formConfig[2].selectOptions = response.data.list;
		});
		getListByType(1).then((response) => {
			this.formConfig[0].selectOptions = response.data;
		});
	},
	methods: {
		buttonClick(val) {
			switch (val.btnName) {
				case 'search':
					this.listQuery.pageNo = 1;
					this.listQuery.pageSize = 10;
					this.listQuery.goodsId = val.goodsId;
					this.listQuery.operator = val.operator;
					this.listQuery.operateStatus = val.status;
					this.listQuery.operateTime = val.searchTime?val.searchTime:null;
					this.getDataList();
					break;
				default:
					console.log(val);
			}
		},
	},
};
</script>
<style>
.app-container .el-table .el-table__cell {
	padding: 0;
	height: 35px;
}
</style>
