<template>
  <el-form ref="form" label-width="84px">
    <el-form-item label="案件名称">
      <el-input
        v-model="bindExample.caseTitle"
        maxlength="50"
        placeholder="请输入案件名称"
      />
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { Example, setExample, addExample } from "@/app/criminal/store/example";
import { ElMessage } from "element-plus";
import { QuiskExpose } from "@/helper/mount";

const props = defineProps<{ example?: Example }>();
const bindExample = ref<Example>(props.example ? { ...props.example } : ({} as Example));

defineExpose<QuiskExpose>({
  async submit() {
    if (!bindExample.value.caseTitle || !bindExample.value.caseTitle.trim()) {
      ElMessage.error("案件名称不能为空");
      throw "案件名称不能为空";
    }
    await (bindExample.value.caseId
      ? setExample(bindExample.value.caseTitle, bindExample.value.caseId)
      : addExample(bindExample.value.caseTitle));
  },
});
</script>
