<template>
	<a-form :model="commomParams.search">
		<a-row :gutter="[10]">
			<a-col span="6">
				<a-form-item>
					<a-select v-model:value="value" @change="recruitmentbookChange" placeholder="请选择招聘会" show-search
						:filter-option="false" label-in-value @search="recruitmentbookSearch">
						<a-select-option v-for="item in recruitmentbook_list" :key="item.id" :value="item.id"
							:label="item.title" label-in-value>{{item.title}}</a-select-option>
					</a-select>
				</a-form-item>
			</a-col>

			<a-col>
				<a-form-item>
					<a-button type="primary" @click="getData">
						搜索
					</a-button>
				</a-form-item>
			</a-col>
			<a-col>
				<a-form-item>
					<a-button danger @click="clearSearch">
						清空搜索
					</a-button>
				</a-form-item>
			</a-col>
		</a-row>
	</a-form>
</template>

<script lang="ts" setup>
	import { ref, onMounted, watch, computed } from 'vue';
	import { useCommon } from '@/hooks/useCommon';
	import { listRecruitment } from '@/apis/models';
	let { commomParams } = useCommon();
	let props = defineProps(['search_params']);
	const emit = defineEmits();
	
	interface listType {
		recruitment_id : String
	}

	commomParams.value.search = commomParams.value.search as listType;
	commomParams.value.search.recruitment_id = '';

	watch(() => props.search_params, (newVal) => {
		console.log(newVal)
	})

	// 选择招聘会
	let recruitmentbook_list = ref<Object[]>([])
	const recruitmentbookSearch = (val) => {
		listRecruitment({ keyword: val }).then(res => {
			recruitmentbook_list.value = res.data.recruitments;
		})
	}
	const recruitmentbookChange = (val : Object) => {
		commomParams.value.search.recruitment_id = val.key;
		getData()
	}

	const getData = () => {
		emit('searchData', commomParams.value.search)
	}

	// 清空搜索
	const clearSearch = () => {
		commomParams.value.search = {
			page: 1,
			pagesize: 10,
			sort: 'id',
			sortby: 'asc',
			keyword: ''
		}
		emit('clearData', commomParams.value.search)
	}
</script>

<style>
</style>