<script setup lang="ts">
import { ref} from "vue";
import Form from "./form.vue";
import { useVModel } from "@vueuse/core";
import { httpCreate } from "/@/api/interest/handover";
import { ElMessage } from "element-plus";

const props = defineProps<{ visible: boolean, companyNo: string }>()
const emit = defineEmits(['refresh'])


const loading = ref(false)
const visible = useVModel(props, 'visible')

const initialData = {
  expire_date: '',
  hand_uid: '',
  resign_date: '',
  resign_uid: ''
}

const data = ref<Record<string, string>>({...initialData});

function handleClose(){
  visible.value = false
  data.value = {...initialData}
}

async function onSubmit(){
  loading.value = true
  const result = await httpCreate({  ...data.value, companyNo: props.companyNo})
  loading.value = false
  if(result.code === 0){ ElMessage.success('添加成功') } else { ElMessage.warning('添加失败')}
  visible.value = false
  emit('refresh')
}
</script>

<template>
  <ElDialog
    v-model="visible"
    title="添加离职交接"
    :close-on-click-modal="false"
    @close="handleClose"
    center
  >
    <Form 
      v-model:data="data" 
      :companyNo="companyNo" 
      @submit="onSubmit" 
      :modal="true" 
    />
  </ElDialog>
</template>
