<template>
	<a-form :model="createForm" layout="vertical" class="resume-form">
		<a-row :gutter="20">
			<a-col span="12">
				<a-form-item label="姓名" name="name">
					<a-input v-model:value="createForm.name" placeholder="请输入姓名" />
				</a-form-item>
			</a-col>
			<a-col span="12">
				<a-form-item label="电话" name="telephone">
					<a-input v-model:value="createForm.telephone" placeholder="请输入电话" />
				</a-form-item>
			</a-col>
			<a-col span="12">
				<a-form-item label="地址" name="address">
					<a-input v-model:value="createForm.address" placeholder="请输入地址" />
				</a-form-item>
			</a-col>
			<a-col span="12">
				<a-form-item label="传真" name="fax">
					<a-input v-model:value="createForm.fax" placeholder="请输入传真" />
				</a-form-item>
			</a-col>
			<a-col span="12">
				<a-form-item label="邮编" name="postal">
					<a-input v-model:value="createForm.postal" placeholder="请输入邮编" />
				</a-form-item>
			</a-col>
			<a-col span="12">
				<a-form-item label="电子邮箱" name="email">
					<a-input v-model:value="createForm.email" placeholder="请输入邮箱" />
				</a-form-item>
			</a-col>
			<a-col span="12">
				<a-form-item label="反馈内容" name="content">
					<a-input v-model:value="createForm.content" placeholder="请输入反馈内容" />
				</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>

<script setup lang="ts">
	import { ref, onMounted, computed, defineProps, watch, defineEmits } from 'vue';
	import { PostFeedbackAdd, PostFeedbackUpdate , GetFeedbackDetail } from '@/apis/models';
	import { warnToast, successToast } from '@/utils/toastHelper';
	import { dataForm, otherDataForm, reset } from '@/components/message/feedback/data.ts';
	import { useCommon } from '@/hooks/useCommon';
	let { store, message } = useCommon();
	let props = defineProps(['edit_id']);
	const emit = defineEmits();
	let createForm = ref(dataForm)



	onMounted(async () => {

	})


	const sumbitForm = () => {
		if (!createForm.value.id) {
			PostFeedbackAdd(createForm.value).then(res => {
				successToast('保存成功');
				resetForm();
			}).catch(err => {
			})
		} else {
			PostFeedbackUpdate(createForm.value).then(res => {
				successToast('编辑成功');
				resetForm();
			}).catch(err => {
			})

		}
	}

	const resetForm = () => {
		createForm.value = reset().dataForm;
		emit('send')
	}


	watch(() => props.edit_id, (newVal) => {
		if (newVal) {
			GetFeedbackDetail({ id: newVal }).then(res => {
				let resData =  res.data
				createForm.value = {
					id: resData.id,
					name: resData.name,
					address: resData.address,
					telephone: resData.telephone,
					fax: resData.fax,
					postal: resData.postal,
					email: resData.email,
					content: resData.content,
				}
				
			})

		}
	}, {immediate: true})
</script>

<style scoped lang="less">
	:deep(.ant-table-thead >tr>th) {
		background-color: #fff !important;
		border: none !important;
		color: #bbb !important;
	}

	:deep(.ant-table-thead >tr>th::before) {
		display: none !important;
	}

	:deep(.ant-table-tbody >tr >td) {
		border: none !important;
	}
</style>