<script setup lang="ts">
import { ref, reactive } from "vue";
import { ElMessageBox, ElMessage } from "element-plus";
import { getCopyTemplate } from "@/api/templateInfo";
const $emit = defineEmits(["addTemplateApi"]);
const dialogVisibleAdd = ref(false);
const copyTitle = ref("");
// 复制
const getCopyTemplateApi = async () => {
  const res = await getCopyTemplate(form);
  if (res.code === 200) {
    $emit("addTemplateApi");
  } else {
    ElMessage.error(res.msg);
  }
};
const copyMould = () => {
  return "复制来源:" + copyTitle.value;
};
const form = reactive({
  name: "",
  id: ""
});
const handleClose = () => {
  dialogVisibleAdd.value = !dialogVisibleAdd.value;
  ElMessage({
    message: "已关闭"
  });
};
// 添加部门保存
const saveDepartment = () => {
  dialogVisibleAdd.value = false;
  getCopyTemplateApi();
};
const open = (item: any) => {
  form.name = "";
  form.id = "";
  if (item) {
    copyTitle.value = item.tpName;
    form.name = item.tpName + "_副本";
    form.id = item.id;
  }
  dialogVisibleAdd.value = true;
};
defineExpose({
  open
});
</script>

<template>
  <div>
    <el-dialog v-model="dialogVisibleAdd" :title="copyMould()" width="500">
      <el-form :model="form" label-width="auto" style="max-width: 600px">
        <el-form-item label="名称">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="handleClose">取消</el-button>
          <el-button type="primary" @click="saveDepartment"> 确认 </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
