<template>
	<div class="app-container">
		<search-bar
			:formConfigs="formConfig"
			ref="searchBarForm"
      :isFold="true"
			@headBtnClick="buttonClick" />
		<base-table
			: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 { parseTime } from '@/filter/code-filter';
import { deptHolidayLogList } from '@/api/group/holidaySetting';

const tableProps = [
	{
		prop: 'createTime',
		label: '操作时间',
		filter: parseTime
	},
	{
		prop: 'opPeopleName',
		label: '操作人'
	},
	{
		prop: 'opType',
		label: '操作类型',
    filter: (val)=>{return val?['','创建','删除','修改','-','-'][val]:'-'}
	},
	{
		prop: 'name',
		label: '节假日名称'
	},
	{
		prop: 'opDet',
		label: '修改内容'
	},
	{
		prop: 'planType',
		label: '更新排班计划',
    filter: (val)=>{return val?['','是','否','无排班计划'][val]:'-'}
	},
];

export default {
	data() {
		return {
      listQuery: { //分页
        pageSize: 10,
        pageNo: 1,
        total: 1,
      },
			tableProps,
			tableData: [],
			formConfig: [
				{
					type: 'datePicker',
					label: '时间范围',
					dateType: 'daterange',
					format: 'yyyy-MM-dd',
					valueFormat: 'yyyy-MM-dd HH:mm:ss',
					rangeSeparator: '-',
					startPlaceholder: '开始时间',
					endPlaceholder: '结束时间',
					param: 'createTime',
				},
				{
					type: 'input',
					label: '操作人',
					placeholder: '操作人',
					param: 'opPeopleName',
				},
				{
					type: 'select',
					label: '操作类型',
					selectOptions: [
						{
							id: 1,
							name: '创建',
						},
						{
							id: 2,
							name: '删除',
						},
						{
							id: 3,
							name: '修改',
						},
						{
							id: 4,
							name: '解除继承',
						},
						{
							id: 5,
							name: '恢复继承',
						},
					],
					param: 'opType',
				},
				{
					type: 'select',
					label: '更新排班计划',
					selectOptions: [
						{
							id: 1,
							name: '是',
						},
						{
							id: 2,
							name: '否',
						},
						{
							id: 3,
							name: '无排班计划',
						},
					],
					param: 'planType',
				},
				{
					type: 'button',
					btnName: '搜索',
					name: 'search',
					color: 'primary',
				},
				{
					type: 'separate',
				},
				{
					type: 'button',
					btnName: '重置',
					name: 'reset',
				},
			],
		};
	},
	created() {},
	methods: {
    // 获取数据列表
    getDataList() {
      deptHolidayLogList(this.listQuery).then(response => {
        this.tableData = response.data.list;
        this.listQuery.total = response.data.total;
      });
    },
		buttonClick(val) {
			switch (val.btnName) {
				case 'search':
					this.listQuery.pageNo = 1;
					this.listQuery.pageSize = 10;
					this.listQuery.createTime = val.createTime || [];
					this.listQuery.planType = val.planType || undefined;
					this.listQuery.opType = val.opType || undefined;
					this.listQuery.opPeopleName = val.opPeopleName || undefined;
					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>
