<!--
@ 作者: 秦东
@ 时间: 2023-06-18 15:48:51
@ 备注: 编辑双职工
-->
<script lang='ts' setup>
import { doubleWorkCont } from '@/api/hr/people/type'
import { editDoubleWorkCont } from '@/api/hr/people/index'
const props = defineProps({
	editisshow:{
		type:Boolean,
		default:false
	},
	keyval:{
		type:String,
		default:""
	},
	datacont:{
		type:Object,
		default(){
			return {}
		}
	}
});
const editLoading = ref(false)
const emits = defineEmits(["update:editisshow","restdata"]);		//操作父级数据
const editSzgFormRef = ref(ElForm);	//编辑表单
const szgFormData = reactive<doubleWorkCont>({id:""});
/**
 * 弹窗显示控制
 */
 const editshow = computed({
	get: () => props.editisshow,
	set: (val) => {
		emits("update:editisshow", val);
	},
});
/**
 * 表单验证规则
 */
 const editszgRules = reactive({
	name: [{ required: true, message: "请输入姓名", trigger: "blur" }],	
	mobilephone: [{ required: true, message: "请输入联系电话", trigger: "blur" }],	
	company: [{ required: true, message: "请输入公司", trigger: "blur" }],
	department: [{ required: true, message: "请输入所在部门", trigger: "blur" }],
});
/**
 * 关闭弹窗
 */
function clostEditBoxSzg(){
	emits("update:editisshow", false);
	initJjlxrData()
}
/**
 * 初始化数据
 */
 function initJjlxrData(){
	editSzgFormRef.value.resetFields();
	editLoading.value = false;
}
/**
 * 提交数据
 */
 function submitEditSzg(){
	// console.log("提交数据",szgFormData)
	// editLoading.value = true;
	editSzgFormRef.value.validate((isValid: boolean) => {
		if (isValid) {
			editDoubleWorkCont(szgFormData)
				.then(() =>{
					ElMessage.success("编辑成功");
					clostEditBoxSzg();
					emits('restdata');
				})
				.finally(() =>{editLoading.value = false;})
		}
	});
}
/**
 * 监听数据
 */
 watch(() => props.editisshow,() => {
	// console.log("watch--------->",props.editisshow,props.datacont)
	if(props.editisshow){
		szgFormData.id= props.datacont.id.toString();
		szgFormData.name = props.datacont.name;
		szgFormData.mobilephone = props.datacont.tel;
		szgFormData.company = props.datacont.company;
		szgFormData.department = props.datacont.department;
		szgFormData.position = props.datacont.position;
	}
	
})
</script>
<template>
	<el-dialog
        v-model="editshow"
        width="500"
        title="编辑双职工"
        append-to-body
		:before-close="clostEditBoxSzg"
    >
		<el-form
			ref="editSzgFormRef"
			:model="szgFormData"
			:rules="editszgRules"
			label-width="140px"                                                                                                                                                        
		>
			<el-form-item label="姓名" prop="name">
				<el-input v-model="szgFormData.name" placeholder="请输入姓名" />
			</el-form-item>
			<el-form-item label="联系电话" prop="mobilephone">
				<el-input v-model="szgFormData.mobilephone" placeholder="请输入联系电话" />
			</el-form-item>
			<el-form-item label="公司" prop="company">
				<el-input v-model="szgFormData.company" placeholder="请输入公司" />
			</el-form-item>
			<el-form-item label="所在部门" prop="department">
				<el-input v-model="szgFormData.department" placeholder="请输入所在部门" />
			</el-form-item>
			<el-form-item label="职务">
				<el-input v-model="szgFormData.position" placeholder="请输入职务" />
			</el-form-item>
			
		</el-form>
		<template #footer>
			<div class="dialog-footer">
				<el-button type="primary" :loading="editLoading" @click="submitEditSzg" >确 定</el-button>
				<el-button @click="clostEditBoxSzg">取 消</el-button>
			</div>
		</template>
	</el-dialog>
</template>
<style  lang='scss' scoped>

</style>
