<template>
	<div style="width: 100%;">
			<a-form :model="createForm" layout="vertical" class="resume-form">
				<a-row :gutter="20">
					<a-col span="24">
						<a-form-item required label="上传相片" name="photo">
							<upload upload_txt="上传相片" @uploadSuccess="uploadPhotoSuccess"
								:success_image="addOtherForm.photo_img" images_length="1" image_type="1"></upload>
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item label="简历是否可见" name="hide_resume">
							<a-radio-group v-model:value="createForm.hide_resume" button-style="solid" size="mini">
								<a-radio-button :value="1" style="width: 50%;">是</a-radio-button>
								<a-radio-button :value="2" style="width: 50%;">否</a-radio-button>
							</a-radio-group>
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item label="家政版块是否可见" name="house_keeping_status">
							<a-radio-group v-model:value="createForm.house_keeping_status" button-style="solid"
								size="mini">
								<a-radio-button :value="1" style="width: 50%;">是</a-radio-button>
								<a-radio-button :value="2" style="width: 50%;">否</a-radio-button>
							</a-radio-group>
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item required label="性别" name="gender">
							<a-radio-group v-model:value="createForm.gender" button-style="solid" size="mini"
								>
								<a-radio-button value="男" style="width: 50%;">男</a-radio-button>
								<a-radio-button value="女" style="width: 50%;">女</a-radio-button>
							</a-radio-group>
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item required label="姓名">
							<a-input v-model:value="createForm.name" placeholder="请输入姓名" size="mini" />
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item required label="出生日期" name="dob">
							<a-date-picker v-model:value="addOtherForm.dob" @Change="dobChange" style="width: 100%;"
								size="mini" :disabledDate="disabledDateFront" />
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item required label="身份证" name="id_number">
							<a-input v-model:value="createForm.id_number" placeholder="请输入身份证" size="mini" />
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item label="工作经验(年)" name="work_experience">
							<a-input-number :min="0" type="number" v-model:value="createForm.work_experience"
								placeholder="请输入工作经验" style="width: 100%;" size="mini" />
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item required label="学历" name="education">
							<a-xuanze :dict="2006" placeholder="请选择学历" @saveSelect="saveEducation"
								:select_content="createForm.education"></a-xuanze>
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item required label="户口所在地">
							<a-jilian :dict="2009" @saveCascader="regLevelSave" placeholder="请选择户口所在地"
								:cascader_content="addOtherForm.reg_level_cascader"></a-jilian>
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item required label="现居地">
							<a-jilian :dict="2009" @saveCascader="nowLevelSave" placeholder="请选择现居地"
								:cascader_content="addOtherForm.now_level_cascader"></a-jilian>
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item label="职称">
							<a-xuanze :dict="2014" placeholder="请选择职称" @saveSelect="saveTitle"
								:select_content="createForm.title"></a-xuanze>
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item label="婚姻状况">
							<a-xuanze :dict="2011" placeholder="请选择婚姻状况" @saveSelect="saveMaritalStatus"
								:select_content="createForm.marital_status"></a-xuanze>
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item label="民族">
							<a-xuanze :dict="208" placeholder="请选择民族" @saveSelect="saveEthnicity"
								:select_content="createForm.ethnicity"></a-xuanze>
						</a-form-item>
					</a-col>

					<a-col span="8">
						<a-form-item label="政治面貌">
							<a-xuanze :dict="2010" placeholder="请选择政治面貌" @saveSelect="savePoliticalStatus"
								:select_content="createForm.political_status"></a-xuanze>
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item label="籍贯">
							<a-jilian :dict="2009" @saveCascader="nativePlaceSave" placeholder="请选择籍贯"
								:cascader_content="addOtherForm.native_place_txt"></a-jilian>
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item label="身高(厘米cm)">
							<a-input-number :min="0" type="number" v-model:value="createForm.height" placeholder="请输入身高"
								style="width: 100%;" size="mini" />
						</a-form-item>
					</a-col>
					<a-col span="8">
						<a-form-item label="体重(千克kg)">
							<a-input-number :min="0" type="number" v-model:value="createForm.weight" placeholder="请输入体重"
								style="width: 100%;" size="mini" />
						</a-form-item>
					</a-col>
					<a-col span="24">
						<a-flex justify="flex-end">
							<a-space>
								<a-button @click="resetForm" size="mini">取消</a-button>
								<a-button type="primary" @click="sumbitForm" size="mini">保存</a-button>
							</a-space>
						</a-flex>
					</a-col>
				</a-row>
			</a-form>
	</div>
</template>

<script setup lang="ts">
	import { ref, onMounted, computed, defineProps, watch, defineEmits, createVNode } from 'vue';
	import { PostJobapplicantAdd, PostJobapplicantUpdate, GetJobapplicantDetail } from '@/apis/models';
	import Upload from '@/components/upload/one.vue';
	import { intersectionAlike } from '@/utils/dataHelper';
	import { warnToast, successToast } from '@/utils/toastHelper';
	import { dataForm, otherDataForm, reset } from '@/views/jobSeeker/resume/add/basic/data.ts';
	import { useCommon } from '@/hooks/useCommon';
	let { store, dayjs, richOption, ExclamationCircleOutlined, Modal, imageprefix, disabledDateFront } = useCommon();
	const dayjsRef = ref(dayjs);
	let props = defineProps(['customer_record']);
	const emit = defineEmits();
	let createForm = ref<JobseekerBasicType.JobseekerBasicFormType>(dataForm)
	let addOtherForm = ref<JobseekerBasicType.OtherFormType>(otherDataForm)

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

	const getBasic = () => {
		GetJobapplicantDetail({customer_id: props.customer_record.customer_id}).then(res => {
			createForm.value = intersectionAlike(createForm.value, res.data)
			createForm.value.id = res.data.id;
			createForm.value.customer_id = res.data.customer_id;
			addOtherForm.value = {
				dob: dayjsRef.value(res.data.dob),
				reg_level_cascader: [res.data.reg_level1, res.data.reg_level2, res.data.reg_level3, res.data.reg_level4],
				now_level_cascader: [res.data.now_level1, res.data.now_level2, res.data.now_level3, res.data.now_level4],
				native_place_txt: res.data.native_place_txt,
				photo_img: imageprefix + res.data.photo
			}
		})
	}
	
	// 营业执照
	const uploadPhotoSuccess = (data : Object) => {
		addOtherForm.value.photo_img = imageprefix + data
		createForm.value.photo = data
	}

	// 出生日期
	const dobChange = (val) => {
		createForm.value.dob = dayjsRef.value(val).format('YYYY-MM-DD');
	}

	// 学历
	const educationPlaceholder = ref('请选择学历');
	const saveEducation = (data) => {
		createForm.value.education = data.val.key;
	}

	// 职称
	const titlePlaceholder = ref('请选择职称')
	const saveTitle = (data) => {
		createForm.value.title = data.val.key;
	}

	// 婚姻状态
	const maritalStatusPlaceholder = ref('请选择婚姻状态')
	const saveMaritalStatus = (data) => {
		createForm.value.marital_status = data.val.key;
	}

	// 民族
	const ethnicityPlaceholder = ref('请选择民族')
	const saveEthnicity = (data) => {
		createForm.value.ethnicity = data.val.key;
	}

	// 政治面貌
	const politicalStatusPlaceholder = ref('请选择政治面貌')
	const savePoliticalStatus = (data) => {
		createForm.value.political_status = data.val.key;
	}


	// 户口所在地
	const regLevelSave = (data) => {
		for (let i = 0; i < 4; i++) {
			createForm.value[`reg_level${i + 1}`] = data.arr1[i] || 0;
		}
	}

	// 现居地
	const nowLevelSave = (data) => {
		for (let i = 0; i < 4; i++) {
			createForm.value[`now_level${i + 1}`] = data.arr1[i] || 0;
		}
	}

	// 籍贯
	const nativePlaceSave = (data) => {
		if (data.arr1.length == 1) {
			return false;
		} else {
			createForm.value.native_place = data.arr1[1];
		}
	}

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

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

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

<style>
</style>