<!--
@ 作者: 袁纪菲
@ 时间: 2024-4-22
@ 备注: 添加人才盘点
-->
<script lang="ts" setup>
import { TalentinventoryCont } from "@/api/hr/people/type";
import { addTalentinventoryCont } from "@/api/hr/people/index";

const props = defineProps({
  addisshow: {
    type: Boolean,
    default: false,
  },
  keyval: {
    type: String,
    default: "",
  },
});
const addLoading = ref(false);
const emits = defineEmits(["update:addisshow", "restdata"]);
const addrcpdFormRef = ref(ElForm);
const rcpdFormData = reactive<TalentinventoryCont>({});
/**
 * 弹窗显示控制
 */
const addshow = computed({
  get: () => props.addisshow,
  set: (val) => {
    emits("update:addisshow", val);
  },
});
/**
 * 表单验证规则
 */
const addrcpdRules = reactive({});
/**
 * 关闭弹窗
 */
const clostAddBoxrcpd = () => {
  emits("update:addisshow", false);
  initrcpdData();
};
/**
 * 初始化数据
 */
const initrcpdData = () => {
  addrcpdFormRef.value.resetFields();
  addLoading.value = false;
};
/**
 * 提交数据
 */
const submitAddrcpd = () => {
  addrcpdFormRef.value.validate((isValid: boolean) => {
    if (isValid) {
      let listAry = new Array();
      listAry.push(rcpdFormData);
      addTalentinventoryCont({ id: props.keyval, list: listAry })
        .then(() => {
          ElMessage.success("新增成功");
          clostAddBoxrcpd();
          emits("restdata");
        })
        .finally(() => {
          addLoading.value = false;
        });
    }
  });
};
</script>
<template>
  <el-dialog
    v-model="addshow"
    width="500"
    title="添加人才盘点"
    append-to-body
    :before-close="clostAddBoxrcpd"
  >
    <el-form
      ref="addrcpdFormRef"
      :model="rcpdFormData"
      :rules="addrcpdRules"
      label-width="140px"
    >
      <el-form-item label="职业生涯规划" prop="career">
        <el-input v-model="rcpdFormData.career" type="textarea" placeholder="请填写职业生涯规划" />
      </el-form-item>
      <el-form-item label="期望获得的帮助" prop="expecthelp">
        <el-input v-model="rcpdFormData.expecthelp" type="textarea" placeholder="请填写期望从组织获得的帮助" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" :loading="addLoading" @click="submitAddrcpd"
          >确 定</el-button
        >
        <el-button @click="clostAddBoxrcpd">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<style></style>
