<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"></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 codeFilter from '../mixins/code-filter';
import { parseTime } from '../mixins/code-filter';
import { getEquipmentLogPage } from '@/api/oth/equipment';

const tableProps = [
	{
		prop: 'partCode',
		label: '部件编号',
	},
	{
		prop: 'partName',
		label: '部件名称',
	},
	{
		prop: 'maintenanceType',
		label: '保养类型',
		filter: codeFilter('maintenanceType'),
	},
	{
		prop: 'maintenanceTime',
		label: '保养时间',
		filter: (val)=>parseTime(val,'{y}-{m}-{d}'),
	},
];

const mainTaskType = [
	{
		name: '更换',
		id: 1,
	},
	{
		name: '清洗',
		id: 2,
	},
	{
		name: '润滑',
		id: 3,
	},
];
export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
				getDataListURL: getEquipmentLogPage,
			},
			tableProps,
			tableData: [],
			formConfig: [
				{
					type: 'input',
					label: '部件编号',
					placeholder: '部件编号',
					param: 'code',
				},
				{
					type: 'input',
					label: '部件名称',
					placeholder: '部件名称',
					param: 'name',
				},
				{
					type: 'datePicker',
					label: '日期',
					dateType: 'daterange',
					format: 'yyyy-MM-dd',
					valueFormat: 'yyyy-MM-dd HH:mm:ss',
					rangeSeparator: '-',
					startPlaceholder: '开始时间',
					endPlaceholder: '结束时间',
					param: 'searchTime',
				},
				{
					type: 'select',
					label: '保养类型',
					selectOptions: mainTaskType,
					param: 'type',
					defaultSelect: '',
				},
				{
					type: 'button',
					btnName: '搜索',
					name: 'search',
					color: 'primary',
				},
				{
					type: 'button',
					btnName: '重置',
					name: 'reset',
				},
			],
		};
	},
	components: {},
	created() {
    this.listQuery.warehouseId = undefined;
	},
	methods: {
		buttonClick(val) {
			switch (val.btnName) {
				case 'search':
					this.listQuery.pageNo = 1;
					this.listQuery.pageSize = 10;
					this.listQuery.partCode = val.code;
					this.listQuery.partName = val.name;
					this.listQuery.maintenanceTime = val.searchTime;
					this.listQuery.maintenanceType = val.type;
					this.getDataList();
					break;
				case 'reset':
					this.$refs.searchBarForm.resetForm();
					this.listQuery = {
						pageSize: 10,
						pageNo: 1,
						total: 1,
					};
					this.getDataList();
					break;
				default:
					console.log(val);
			}
		},
	},
};
</script>
