<template>
	<a-card title="职位信息" :headStyle="{ 'background-color': '#f0f0f0' }">
		<a-form :model="createForm" layout="vertical">
			<a-row :gutter="20">
				
				<a-col span="24">
					<a-flex justify="flex-end">
						<a-space>
							<a-button type="primary" @click="sumbitForm" size="large">暂存</a-button>
						</a-space>
					</a-flex>
				</a-col>
			</a-row>
		</a-form>
	</a-card>

</template>

<script setup lang="ts">
	import { ref, onMounted, computed, watch, defineEmits, defineProps } from 'vue';
	import { GetDictTree, GetCompanyDepartmentList, PostCompanyJobAdd } from '@/apis/models';
	import { warnToast, successToast } from '@/utils/toastHelper';
	import { intersectionAlike } from '@/utils/dataHelper';
	import { dataForm, otherDataForm, reset } from '@/components/company/invite/position/info/data.ts';
	import { useCommon } from '@/hooks/useCommon';
	let { store, dayjs, richOption, ExclamationCircleOutlined, Modal } = useCommon();
	const dayjsRef = ref(dayjs);
	const emit = defineEmits();
	const props = defineProps(['job_detail']);
	let createForm = ref<CompanyInviteInfoType.InviteInfoFormType>(dataForm)
	let addOtherForm = ref<CompanyInviteInfoType.OtherFormType>(otherDataForm)
	const job_id = ref<object>(null);

	
	const sumbitForm = () => {
		sessionStorage.setItem("first", JSON.stringify(createForm.value))
		sessionStorage.setItem("firstOther", JSON.stringify(addOtherForm.value))
	}

	const resetForm = () => {
		createForm.value = reset().dataForm as CompanyInviteInfoType.InviteInfoFormType;
		addOtherForm.value = reset().otherDataForm as CompanyInviteInfoType.OtherFormType;
	}



	watch(() => [props.job_detail], async (newVal : string[], oldVal) => {
		if (newVal[0]) {
			job_id.value = newVal[0].id;
			
			sessionStorage.setItem("first", JSON.stringify(createForm.value))
			sessionStorage.setItem("firstOther", JSON.stringify(addOtherForm.value))
		} else {
			addOtherForm.value = sessionStorage.getItem('firstOther') ? JSON.parse(sessionStorage.getItem('firstOther')) : addOtherForm.value
			addOtherForm.value.daoqi_date = addOtherForm.value.daoqi_date ? dayjsRef.value(addOtherForm.value.daoqi_date) : ''
			createForm.value = sessionStorage.getItem('first') ? JSON.parse(sessionStorage.getItem('first')) : createForm.value
		}
	}, { immediate: true })
</script>

<style>
</style>