<template>
	<div>
		<template v-if="state">
			<a-form :model="createForm" layout="vertical"  class="resume-form">
				<a-row :gutter="20">
					<a-col span="12">
						<a-form-item label="英语" name="english">
							<a-xuanze :dict="2008" placeholder="请选择掌握程度" @saveSelect="saveEnglish"
								:select_content="createForm.english"></a-xuanze>
						</a-form-item>
					</a-col>
					<a-col span="12">
						<a-form-item label="国语" name="mandarin">
							<a-xuanze :dict="2008" placeholder="请选择掌握程度" @saveSelect="saveMandarin"
								:select_content="createForm.mandarin"></a-xuanze>
						</a-form-item>
					</a-col>
					<a-col span="12">
						<a-form-item label="粤语" name="cantonese">
							<a-xuanze :dict="2008" placeholder="请选择掌握程度" @saveSelect="saveCantonese"
								:select_content="createForm.cantonese"></a-xuanze>
						</a-form-item>
					</a-col>
					<a-col span="12">
						<a-form-item label="第二外语" name="other_language">
							<a-xuanze :dict="2007" placeholder="请选择掌握程度" @saveSelect="saveOtherLanguage"
								:select_content="createForm.other_language"></a-xuanze>
						</a-form-item>
					</a-col>
					<a-col span="12">
						<a-form-item label="计算机能力" name="computer_skills">
							<a-input v-model:value="createForm.computer_skills" placeholder="请输入计算机能力" size="large"/>
						</a-form-item>
					</a-col>
					<a-col span="24">
						<a-flex justify="flex-end">
							<a-space>
								<a-button @click="resetForm" size="large">取消</a-button>
								<a-button type="primary" @click="sumbitForm" size="large">保存</a-button>
							</a-space>
						</a-flex>
					</a-col>
				</a-row>
			</a-form>
		</template>
		<template v-else>
			<template v-if="detail">
				<a-row :gutter="[20,20]">
					<a-col span="10">
						<a-row>
							<a-space direction="vertical">
								<a-col span="24">
									英&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;语：{{detail.english_txt}}
								</a-col>
								<a-col span="24">
									国&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;语：{{detail.mandarin_txt}}
								</a-col>
								<a-col span="24">
									粤&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;语：{{detail.cantonese_txt}}
								</a-col>
								<a-col span="24">
									第二外语：{{detail.other_language_txt}}
								</a-col>
								<a-col span="24">
									计算机能力：{{detail.computer_skills}}
								</a-col>
							</a-space>
							
						</a-row>
					</a-col>
				</a-row>
			</template>
			<template v-else>
				<a-row>
					<a-col span="24">
						<a-empty>
							<template #description>
								暂无信息
							</template>
						</a-empty>
					</a-col>
				</a-row>
			</template>
			
		</template>
	</div>
</template>

<script setup lang="ts">
	import { ref, onMounted, computed, defineProps, watch, defineEmits, createVNode } from 'vue';
	import { PostJobapplicantAddskill, PostJobapplicantUpdateskill, PostJobapplicantSkilldetail } from '@/apis/models';
	import { intersectionAlike } from '@/utils/dataHelper';
	import { warnToast, successToast } from '@/utils/toastHelper';
	import { dataForm, otherDataForm, reset } from '@/components/jobseeker/resume/skill/data.ts';
	import { useCommon } from '@/hooks/useCommon';
	let { store, dayjs, richOption, ExclamationCircleOutlined, Modal } = useCommon();
	const dayjsRef = ref(dayjs);
	let props = defineProps(['form_state']);
	const emit = defineEmits();
	let state = ref<Boolean>(false)
	let detail = ref(null)
	let createForm = ref<JobseekerSkillType.JobseekerSkillFormType>(dataForm)

	onMounted(() => {
		getBasic()
	})

	const getBasic = () => {
		PostJobapplicantSkilldetail().then(res => {
			detail.value = res.data;
			createForm.value = intersectionAlike(createForm.value, res.data)
			createForm.value.id = res.data.id;
		})
	}

	// 英语
	const saveEnglish = (data) => {
		createForm.value.english = data.val.key;
	}

	// 国语
	const saveMandarin = (data) => {
		createForm.value.mandarin = data.val.key;
	}

	// 粤语
	const saveCantonese = (data) => {
		createForm.value.cantonese = data.val.key;
	}

	// 第二外语
	const saveOtherLanguage = (data) => {
		createForm.value.other_language = data.val.key;
	}

	const sumbitForm = () => {
		if (createForm.value.id) {
			PostJobapplicantUpdateskill(createForm.value).then(res => {
				successToast('保存成功');
				getBasic();
				resetForm()
			}).catch(err => {
			})
		} else {
			PostJobapplicantAddskill(createForm.value).then(res => {
				successToast('保存成功');
				getBasic();
				resetForm()
			}).catch(err => {
			})
		}
	}

	const resetForm = () => {
		createForm.value = reset().dataForm as JobseekerSkillType.JobseekerSkillFormType;
		console.log(createForm.value)
		state.value = false;
		emit("quitEdit")
	}

	watch(() => [props.form_state], (newVal) => {
		state.value = newVal[0];
		getBasic();
	})
</script>

<style>
</style>
