<template>
	<el-dialog v-model="state.dialogVisible" width="40%" draggable title="标注" destroy-on-close append-to-body @close="close">
		<el-form :model="state.ruleForm" label-width="150px" ref="ruleFormRef">
			<el-form-item label="是否标记为安全生产" prop="gender" :rules="[{ required: true, message: '请选择是否标记为安全生产', trigger: 'change' }]">
				<el-radio-group v-model="state.ruleForm.gender">
					<el-radio :value="true">是</el-radio>
					<el-radio :value="false">否</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="备注" prop="txtHelpRemarks" :rules="[{ required: false, message: '请填写备注', trigger: 'blur' }]">
				<el-input
					type="textarea"
					:autosize="{ minRows: 6, maxRows: 10 }"
					v-model="state.ruleForm.txtHelpRemarks"
					placeholder="请填写备注"
					clearable
				></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<span class="dialog-footer">
				<el-button @click="closeDialog" class="default-button">取 消</el-button>
				<el-button type="primary" @click="onSubmit(ruleFormRef)" :loading="loading">确 定</el-button>
			</span>
		</template>
	</el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue';
import { ElMessage, FormInstance } from 'element-plus';
import { throttle } from '@/utils/tools';
import { addAreaUser, baseAreaUser } from '@/api/snapshot/config';
// 定义子组件向父组件传值/事件
const emit = defineEmits(['updateList']);

// 定义变量内容
const state = reactive<any>({
	dialogVisible: false,
	ruleForm: {
		systemAreaId: null, // 所属区域
		systemAreaName: null, // 所属区域名称
		street: null, // 所属镇/街
		name: null, // 姓名
		phoneNumber: null, // 联系方式
		gender: null,
	},
	ids: [],
});
let loading = ref<boolean>(false); // 加载状态
// 打开弹窗
const ruleFormRef = ref<RefType>();
const openDialog = (val: any) => {
	state.ids = val;
	console.log(val, '11');
	state.dialogVisible = true;
};
// 关闭弹窗
const closeDialog = () => {
	state.dialogVisible = false;
};
const close = () => {
	ruleFormRef.value?.resetFields();
	ruleFormRef.value?.resetFields();
};
// 新增
const onSubmit = throttle(async (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	await formEl.validate((valid: boolean) => {
		if (!valid) return;
		/*	loading.value = true;
		addAreaUser(state.ruleForm)
			.then(() => {
				ElMessage({
					message: '操作成功',
					type: 'success',
				});
				emit('updateList');
			})
			.catch(() => {})
			.finally(() => {
				loading.value = false;
				closeDialog();
			});*/
	});
}, 300);
// 暴露变量
defineExpose({
	openDialog,
	closeDialog,
});
</script>
