<template>
	<a-modal v-model:visible="showBindModel" title="管理已经授权的账号" @cancel="cancelModal" width="80%" :footer="null">
		<a-c-table :data="commomParams.table.data" :columns="commomParams.table.columns" :pagination="commomParams.page"
			@page="getPage" :loading="loading">
			<template #default="{ record }">
				<a-row :gutter="10">
					<a-popconfirm title="是否要解除授权?" @confirm="unBind(record)">
						<a-col><a-button type="primary" size="small" danger>解除授权</a-button></a-col>
					</a-popconfirm>
				</a-row>
			</template>
		</a-c-table>
	</a-modal>
</template>

<script setup lang="ts">
	import { ref, onMounted, computed, defineProps, watch, defineEmits } from 'vue';
	import { GetCompanyRecruiters, PostCompanyTurnJobseeker, PostRecruitmentBookDel } from '@/apis/models';
	import { useCommon } from '@/hooks/useCommon';
	import { cols } from '@/views/company/list/bind/columns.ts';
	import { message } from 'ant-design-vue';
	let { store, commomParams } = useCommon();
	const emit = defineEmits();
	let props = defineProps(['bind_record']);
	let loading = ref<Boolean>(true);

	let showBindModel = computed(() => {
		return store.state.showBindModel;
	})

	let bind_record = ref<Object>({});
	watch(() => props.bind_record, (newVal1) => {
		bind_record.value = newVal1;
		commomParams.value.search.id = newVal1.id;
		getData()
	})

	const getData = async (val) => {
		try {
			loading.value = true;
			let res = await GetCompanyRecruiters(commomParams.value.search);
			loading.value = false;
			commomParams.value.table.data = res.data.customers;
			commomParams.value.table.columns = cols;
			commomParams.value.page = {
				current: commomParams.value.search.page,
				pageSize: commomParams.value.search.pagesize,
				total: res.data.total,
				pageSizeOptions: ['10', '20', '30', '40'],
				hideOnSinglePage: false,
				showSizeChanger: true,
				recruitment_id: bind_record.value.id
			};
		} catch {
			loading.value = false;
		}
	}

	const getPage = (data : object) => {
		commomParams.value.search.page = data.current;
		commomParams.value.search.pagesize = data.pageSize;
		getData();
	}

	const cancelModal = () => {
		store.commit('getShowBindModel', {
			showBindModel: false
		})
	}

	

	// 移除
	const unBind = (record) => {
		PostCompanyTurnJobseeker({company_id:record.company_id, customer_id: record.id, role: 1}).then(res => {
			message.success('解除授权成功');
			getData();
		})
	}
</script>

<style>
</style>