<template>
	<list-search @searchData="searchData" @clearData="clearData" :search_params="commomParams.search"></list-search>
	<a-c-operation @refresh="clearData"></a-c-operation>
	<a-c-table :data="commomParams.table.data" :columns="commomParams.table.columns" :pagination="commomParams.page"
		@page="getPage" :loading="loading">
		<template #photo_image="{ record }">
			<a-image :src="imageprefix + record.photo"></a-image>
		</template>
		<template #license_image="{ record }">
			<a-image :src="imageprefix + record.photo"></a-image>
		</template>
		<template #default="{ record }">
			<a-row :gutter="10">
				<a-col><a-button type="primary" size="small" primary @click="edit(record)">编辑</a-button></a-col>
				<a-col><a-button type="primary" size="small" primary
						@click="showDepartment(record)">查看部门</a-button></a-col>
				<a-col><a-button type="primary" size="small" primary
						@click="showPosition(record)">查看职位</a-button></a-col>
			</a-row>
		</template>
	</a-c-table>
	<list-add :edit_record="edit_record" @successAdd="successAdd" @closeAdd="closeAdd"></list-add>
	<list-department :department_record="department_record"></list-department>
	<list-position :position_record="position_record"></list-position>
</template>

<script lang="ts" setup>
	import { ref, onMounted, watch, computed } from 'vue';
	import ListSearch from '@/views/company/list/search/index.vue';
	import ListAdd from '@/views/company/list/add/add.vue';
	import ListDepartment from '@/views/company/list/department/index.vue';
	import ListPosition from '@/views/company/list/position/index.vue';
	import { getCompanyList } from '@/apis/models';
	import { useCommon } from '@/hooks/useCommon';
	import { cols } from '@/views/company/list/columns';
		import { router } from '@/router';
	let { store, commomParams, showModal, showOtherModal1, imageprefix, message } = useCommon();
	let loading = ref<Boolean>(true);
	onMounted(() => {
		getData(commomParams.value.search);
	})

	const searchData = (data : object) => {
		commomParams.value.search = data
		getData();
	}

	const clearData = (data : object) => {
		if (data) {
			commomParams.value.search = data
		} else {
			commomParams.value.search = {
				page: 1,
				pagesize: 10,
				sort: 'id',
				sortby: 'desc',
				keyword: ''
			}
		}
		getData();
	}


	const getPage = (data : object) => {
		commomParams.value.search.page = data.current;
		commomParams.value.search.pagesize = data.pageSize;
		getData();
	}
	const getData = async () => {
		try {
			loading.value = true;
			let res = await getCompanyList(commomParams.value.search);
			loading.value = false;
			commomParams.value.table.data = res.data.list;
			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
			};
		} catch {
			loading.value = false;
		}
	}


	// 编辑
	let edit_record = ref<Object>(null)
	const edit = (record : object) => {
		edit_record.value = record;
		showModal()
	}
	const successAdd = () => {
		getData();
	}
	const closeAdd = () => {
		edit_record.value = null;
	}

	// 查看部门
	let department_record = ref<Object>(null)
	const showDepartment = (record : object) => {
		sessionStorage.setItem('company_id', record.id)
		router.push({
			path: '/department',
		})
		// department_record.value = record;
		// store.commit('getShowDepartmentModel', {
		// 	showDepartmentModel: true
		// })
	}

	// 查看职位
	let position_record = ref<Object>(null)
	const showPosition = (record : object) => {
		sessionStorage.setItem('company_id', record.id)
		router.push({
			path: '/job',
		})
		// position_record.value = record;
		// store.commit('getShowPositionModel', {
		// 	showPositionModel: true
		// })
	}

	// 删除
	// const delOneRole = (id: number) => {
	// 	commomParams.value.delRecord = { id: id };
	// 	PostRoleDel(commomParams.value.delRecord).then(res => {
	// 		message.success('删除成功');
	// 		getData();
	// 	})
	// }
</script>

<style lang="less" scoped>

</style>