<template>
	<div>
		<a-form :model="createForm" layout="vertical" class="resume-form">
			<a-row :gutter="20">
				<a-col span="24">
					<a-form-item required label="个人简介" name="description">
						<QuillEditor theme="snow" :options="richOption" toolbar="full"
							v-model:content="addOtherForm.description" @update:content="onEditorUpdate($event)"
							contentType="html" />
					</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>

	</div>
</template>

<script setup lang="ts">
	import { ref, onMounted, computed, defineProps, watch, defineEmits, createVNode } from 'vue';
	import { PostJobapplicantAddintroduction, PostJobapplicantUpdateintroduction, GetJobapplicantIntroductiondetail } from '@/apis/models';
	import { intersectionAlike } from '@/utils/dataHelper';
	import { warnToast, successToast } from '@/utils/toastHelper';
	import { dataForm, otherDataForm, reset } from '@/views/jobSeeker/resume/add/introduction/data.ts';
	import { useCommon } from '@/hooks/useCommon';
	let { store, dayjs, richOption, ExclamationCircleOutlined, Modal } = useCommon();
	const dayjsRef = ref(dayjs);
	let props = defineProps(['customer_record']);
	const emit = defineEmits();
	let createForm = ref<JobseekerIntroductionType.JobseekerIntroductionFormType>(dataForm)
	let addOtherForm = ref<JobseekerIntroductionType.OtherFormType>(otherDataForm)

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

	const getBasic = () => {
		GetJobapplicantIntroductiondetail({ 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 = {
				description: res.data.description,
			}
		})
	}

	// 富文本
	const onEditorUpdate = (data) => {
		createForm.value.description = data
	}


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

	const resetForm = () => {
		createForm.value = reset().dataForm as JobseekerIntroductionType.JobseekerIntroductionFormType;
		addOtherForm.value = reset().otherDataForm as JobseekerIntroductionType.OtherFormType;

	}

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

<style>
</style>