<!--
@ 作者:袁纪菲
@ 时间: 2024-4-22
@ 备注: 添加奖惩记录
-->
<script lang="ts" setup>
import { RewardsAndPunishmentsCont } from "@/api/hr/people/type";
import { addRewardsAndPunishmentsCont } from "@/api/hr/people/index";
import { rewardlevel } from "@/api/hr/people/datacont";
const props = defineProps({
  addisshow: {
    type: Boolean,
    default: false,
  },
  keyval: {
    type: String,
    default: "",
  },
});
const addLoading = ref(false);
const emits = defineEmits(["update:addisshow", "restdata"]);
const addJcjlFormRef = ref(ElForm);
const jcjlFormData = reactive<RewardsAndPunishmentsCont>({});
/**
 * 弹窗显示控制
 */
const addshow = computed({
  get: () => props.addisshow,
  set: (val) => {
    emits("update:addisshow", val);
  },
});
/**
 * 表单验证规则
 */
const addJcjlRules = reactive({
});
/**
 * 关闭弹窗
 */
const clostAddBoxJcjl = () => {
  emits("update:addisshow", false);
  initJcjlData();
}
/**
 * 初始化数据
 */
const initJcjlData = () => {
  addJcjlFormRef.value.resetFields();
  addLoading.value = false;
}
/**
 * 提交数据
 */
const submitAddJcjl = ()=> {
  addJcjlFormRef.value.validate((isValid: boolean) => {
    if (isValid) {
      let listAry = new Array();
      listAry.push(jcjlFormData);
      addRewardsAndPunishmentsCont({ id: props.keyval, list: listAry })
        .then(() => {
          ElMessage.success("新增成功");
          clostAddBoxJcjl();
          emits("restdata");
        })
        .finally(() => {
          addLoading.value = false;
        });
    }
  });
}
</script>
<template>
  <el-dialog
    v-model="addshow"
    width="500"
    title="添加奖惩记录"
    append-to-body
    :before-close="clostAddBoxJcjl"
  >
    <el-form
      ref="addJcjlFormRef"
      :model="jcjlFormData"
      :rules="addJcjlRules"
      label-width="140px"
    >
      <el-form-item label="奖惩级别" prop="level">
        <el-select v-model="jcjlFormData.level" placeholder="请选择奖惩级别">
					<el-option 
					v-for="item in rewardlevel" 
					:key="item.id" 
					:label="item.name"
					:value="item.id" />
				</el-select>
      </el-form-item>
      <el-form-item label="奖惩类型" prop="type">
        <el-input v-model="jcjlFormData.type" placeholder="请输入奖惩类型" />
      </el-form-item>
      <el-form-item label="奖惩内容" prop="content">
        <el-input v-model="jcjlFormData.content" type="textarea" placeholder="请输入奖惩内容" />
      </el-form-item>
      <el-form-item label="奖惩时间" prop="time">
        <el-date-picker
					v-model="jcjlFormData.time"
					type="date"
					placeholder="请选择奖惩时间"
					format="YYYY-MM-DD"
					value-format="YYYY-MM-DD"
					style="width: 100%;"
					size="default"
				/>
      </el-form-item>
      <el-form-item label="奖惩单位" prop="company">
        <el-input v-model="jcjlFormData.company" placeholder="请输入奖惩单位" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" :loading="addLoading" @click="submitAddJcjl"
          >确 定</el-button
        >
        <el-button @click="clostAddBoxJcjl">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<style lang="scss" scoped></style>
