<template>
  <my-modal
    v-model:open="visible"
    title="设置导入参数"
    :width="400"
    @ok="submit"
  >
    <qm-low-form
      :params="params"
      :fields="fields"
      :label-width="80"
      :rules="rules"
      ref="form"
    >
    </qm-low-form>
  </my-modal>
</template>
<script name="SetImportParamsDialog" lang="ts" setup>
import { ref } from "vue";
import { useUserStore } from "@/store";
import { saveStuImportSet } from "@/ap/baseDataConfig";
const visible = defineModel();
const userStore = useUserStore();
const form = ref();
const emit = defineEmits(["success"]);
const params = ref({
  year: "",
  yearHalf: "",
});
const fields = ref([
  {
    prop: "year",
    label: "考试年度",
    colSpan: 24,
    type: "select",
    attrs: {
      options: [
        { value: "2020", label: "2020" },
        { value: "2021", label: "2021" },
        { value: "2022", label: "2022" },
        { value: "2023", label: "2023" },
        { value: "2024", label: "2024" },
        { value: "2025", label: "2025" },
        { value: "2026", label: "2026" },
        { value: "2027", label: "2027" },
        { value: "2028", label: "2028" },
        { value: "2029", label: "2029" },
      ],
    },
  },
  {
    prop: "yearHalf",
    label: "考次",
    colSpan: 24,
    type: "select",
    attrs: {
      options: [
        { value: 1, label: "上半年" },
        { value: 2, label: "下半年" },
      ],
    },
  },
]);
const rules = {
  year: { required: true, message: "请选择考试年度" },
  yearHalf: { required: true, message: "请选择考次" },
};
const submit = () => {
  form.value.formRef.validate().then(() => {
    saveStuImportSet({
      ...params.value,
      examId: userStore.curExam?.id as number,
    }).then((res: any) => {
      window.$message.success("操作成功");
      visible.value = false;
      emit("success");
    });
  });
};
</script>
<style lang="less" scoped></style>
