<template>
	<a-form :model="createForm" :label-col="{span: 4}" labelAlign="left">
		<a-row gutter="20">
			<a-col span="24">
				<a-form-item required label="简历是否可见" name="hide_resume"  :label-col="{span: 0}">
					<a-radio-group v-model:value="createForm.hide_resume" button-style="solid">
						<a-radio-button :value="1">是</a-radio-button>
						<a-radio-button :value="2">否</a-radio-button>
					</a-radio-group>
				</a-form-item>
			</a-col>
			<a-col span="24">
				<a-form-item required label="家政版块是否可见" name="house_keeping_status"  :label-col="{span: 0}">
					<a-radio-group v-model:value="createForm.house_keeping_status" button-style="solid">
						<a-radio-button :value="1">是</a-radio-button>
						<a-radio-button :value="2">否</a-radio-button>
					</a-radio-group>
				</a-form-item>
			</a-col>
			<a-col span="24">
				<a-form-item required label="性别" name="createForm.gender"  :label-col="{span: 0}">
					<a-radio-group v-model:value="createForm.gender" button-style="solid">
						<a-radio-button value="男">男</a-radio-button>
						<a-radio-button value="女">女</a-radio-button>
					</a-radio-group>
				</a-form-item>
			</a-col>
			<a-col span="8">
				<a-form-item required label="出生日期" name="dob">
					<a-date-picker v-model:value="createForm.dob" @Change="dobChange" style="width: 100%;" />
				</a-form-item>
			</a-col>

			<a-col span="8">
				<a-form-item required label="姓名" name="name">
					<a-input v-model:value="createForm.name" placeholder="请输入姓名" />
				</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="请输入身份证" />
				</a-form-item>
			</a-col>

			<a-col span="8">
				<a-form-item required label="工作经验" name="work_experience">
					<a-input-number :min="0" type="number" v-model:value="createForm.work_experience"
						placeholder="请输入工作经验" style="width: 100%;" />
				</a-form-item>
			</a-col>
			<a-col span="8">
				<a-form-item label="学历" name="education">
					<a-c-select :dict="2006" :placeholder="educationPlaceholder"
						@saveSelect="saveEducation"></a-c-select>
				</a-form-item>
			</a-col>

			<a-col span="8">
				<a-form-item label="户口所在地">
					<a-c-cascader :dict="2009" @saveCascader="regLevelSave" placeholder="请选择户口所在地"></a-c-cascader>
				</a-form-item>
			</a-col>
			<a-col span="8">
				<a-form-item label="现居地">
					<a-c-cascader :dict="2009" @saveCascader="nowLevelSave" placeholder="请选择现居地"></a-c-cascader>
				</a-form-item>
			</a-col>
			<a-col span="8">
				<a-form-item label="职称">
					<a-c-select :dict="2014" :placeholder="titlePlaceholder" @saveSelect="saveTitle"></a-c-select>
				</a-form-item>
			</a-col>
			<a-col span="8">
				<a-form-item label="婚姻状况">
					<a-c-select :dict="2011" :placeholder="maritalStatusPlaceholder"
						@saveSelect="saveMaritalStatus"></a-c-select>
				</a-form-item>
			</a-col>
			<a-col span="8">
				<a-form-item label="民族">
					<a-c-select :dict="2012" :placeholder="ethnicityPlaceholder"
						@saveSelect="saveEthnicity"></a-c-select>
				</a-form-item>
			</a-col>

			<a-col span="8">
				<a-form-item label="政治面貌">
					<a-c-select :dict="2010" :placeholder="politicalStatusPlaceholder"
						@saveSelect="savePoliticalStatus"></a-c-select>
				</a-form-item>
			</a-col>
			<a-col span="8">
				<a-form-item label="籍贯">
					<a-c-cascader :dict="2009" @saveCascader="nativePlaceSave" placeholder="请选择籍贯"></a-c-cascader>
				</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%;" />
				</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%;" />
				</a-form-item>
			</a-col>
		</a-row>
		<a-row gutter="20">
			<a-col>
				<a-button type="primary" @click="onSubmit">保存</a-button>
			</a-col>
			<a-col>
				<a-button style="margin-left: 10px">重置</a-button>
			</a-col>
		</a-row>

	</a-form>
</template>

<script lang="ts" setup>
	import { ref, onMounted, computed, defineProps, watch, defineEmits } from 'vue';
	import { message } from 'ant-design-vue';
	import { PostJobapplicantAdd, PostJobapplicantUpdate } from '@/apis/models';
	import dayjs from 'dayjs';
	import 'dayjs/locale/zh-cn';
	let props = defineProps(['customer_record']);
	const emit = defineEmits();
	dayjs.locale('zh-cn');
	let createForm = ref<basicType.addBasicType>({
		id: 0,
		customer_id: 0,
		hide_resume: 0,
		house_keeping_status: 0,
		photo: 'aaa.jpg',
		name: '',
		id_number: '',
		gender: "女",
		dob: '',
		work_experience: 0,
		education: 0,
		reg_level1: 0,
		reg_level2: 0,
		reg_level3: 0,
		reg_level4: 0,
		now_level1: 0,
		now_level2: 0,
		now_level3: 0,
		now_level4: 0,
		title: 0,
		marital_status: 0,
		ethnicity: 0,
		height: 0,
		weight: 0,
		political_status: 0,
		native_place: 0
	})
	
	onMounted(() => {
		if (props.customer_record) {
			createForm.value = {
				id: props.customer_record.id,
				customer_id: props.customer_record.customer_id,
				hide_resume: props.customer_record.hide_resume,
				house_keeping_status: props.customer_record.house_keeping_status,
				photo: props.customer_record.photo?props.customer_record.photo: 'aaa.jpg',
				name: props.customer_record.seekername,
				id_number: props.customer_record.id_number,
				gender: props.customer_record.gender,
				dob: props.customer_record.dob,
				work_experience: props.customer_record.work_experience,
				education: props.customer_record.education,
				reg_level1: props.customer_record.reg_level1,
				reg_level2: props.customer_record.reg_level2,
				reg_level3: props.customer_record.reg_level3,
				reg_level4: props.customer_record.reg_level4,
				now_level1: props.customer_record.now_level1,
				now_level2: props.customer_record.now_level2,
				now_level3: props.customer_record.now_level3,
				now_level4: props.customer_record.now_level4,
				title: props.customer_record.title,
				marital_status: props.customer_record.marital_status,
				ethnicity: props.customer_record.ethnicity,
				height: props.customer_record.height,
				weight: props.customer_record.weight,
				political_status: props.customer_record.political_status,
				native_place: props.customer_record.native_place
			}
		}
		
	})
	
	const onSubmit = () => {
		PostJobapplicantUpdate(createForm.value).then(res => {
			message.success('基本资料编辑成功')
			emit('toNext', {activeKey: "2"})
		})
	}

	const resetForm = () => {
		createForm.value = {
			id: 0,
			customer_id: 0,
			hide_resume: 0,
			house_keeping_status: 0,
			photo: 'aaa.jpg',
			name: '',
			id_number: '',
			gender: "女",
			dob: '',
			work_experience: 0,
			education: 0,
			reg_level1: 0,
			reg_level2: 0,
			reg_level3: 0,
			reg_level4: 0,
			now_level1: 0,
			now_level2: 0,
			now_level3: 0,
			now_level4: 0,
			title: 0,
			marital_status: 0,
			ethnicity: 0,
			height: 0,
			weight: 0,
			political_status: 0,
			native_place: 0
		}
	}

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

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

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

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

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

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


	// 户口所在地
	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];
		}
	}
</script>

<style>
</style>