<template>
	<a-drawer :width="500" title="搜索" placement="right" :open="openSearchModel" @close="onClose">
	    <template #extra>
	      <a-button style="margin-right: 8px" @click="clearSearch">清空搜索</a-button>
	      <a-button type="primary" @click="getData">搜索</a-button>
	    </template>
	    <a-form :model="commomParams.search">
	    	<a-row :gutter="[10]">
	    		<a-col span="24">
	    			<a-form-item>
	    				<a-input addon-before="企业名称" v-model:value="commomParams.search.keyword" placeholder="请输入企业名称" @keyup.enter="getData"/>
	    			</a-form-item>
	    		</a-col>
	    		<a-col span="24">
	    			<a-form-item>
	    				<a-input addon-before="登录名称" v-model:value="commomParams.search.login_name" placeholder="请输入登录名称" @keyup.enter="getData"/>
	    			</a-form-item>
	    		</a-col>
	    		<a-col span="24">
	    			<a-form-item>
	    				<a-input addon-before="企业ID" v-model:value="commomParams.search.id" placeholder="请输入企业ID" @keyup.enter="getData"/>
	    			</a-form-item>
	    		</a-col>
	    		<a-col span="24">
	    			<a-form-item>
	    				<a-input addon-before="会员类型" v-model:value="commomParams.search.member_type" placeholder="请输入会员类型" @keyup.enter="getData"/>
	    			</a-form-item>
	    
	    		</a-col>
	    		<a-col span="24">
	    			<a-form-item>
	    				<a-input addon-before="会员状态" v-model:value="commomParams.search.member_status" placeholder="请输入会员状态" @keyup.enter="getData"/>
	    			</a-form-item>
	    		</a-col>
	    		<a-col span="24">
	    			<a-form-item>
	    				<a-input addon-before="开通状态" v-model:value="commomParams.search.status" placeholder="请输入开通状态" @keyup.enter="getData"/>
	    			</a-form-item>
	    		</a-col>
	    		
	    	</a-row>
	    </a-form>
	  </a-drawer>
</template>

<script lang="ts" setup>
	import { ref, onMounted, watch, computed } from 'vue';
	import { useCommon } from '@/hooks/useCommon';
	let { store, commomParams, openSearchModel, hideSearch } = useCommon();
	let props = defineProps(['search_params']);
	const emit = defineEmits();
	
	openSearchModel = computed(() => {
		return store.state.openSearchModel;
	})

	interface listType {
		login_name ?: String
		id : Number | 0,
		member_type ?: String
		member_status : Number | 0,
		status : Number | 0,
	}

	commomParams.value.search = commomParams.value.search as listType;
	commomParams.value.search.login_name = '';
	commomParams.value.search.id = 0;
	commomParams.value.search.member_type = '';
	commomParams.value.search.member_status = 0;
	commomParams.value.search.status = 0;

	watch(() => props.search_params, (newVal) => {
		emit('searchData', commomParams.value.search)
	})

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

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

<style>
</style>