<script setup lang="ts">
import { toRaw } from 'vue';
import { jsonClone } from '@sa/utils';
import { useNaiveForm } from '@/hooks/common/form';
import { $t } from '@/locales';

defineOptions({
  name: 'SchoolRecruitMajorHistorySearch'
});

interface Emits {
  (e: 'search'): void;
}

const emit = defineEmits<Emits>();

const { formRef, validate, restoreValidation } = useNaiveForm();

const model = defineModel<Api.Art.SchoolRecruitMajorHistorySearchParams>('model', { required: true });

const defaultModel = jsonClone(toRaw(model.value));

function resetModel() {
  Object.assign(model.value, defaultModel);
}

async function reset() {
  await restoreValidation();
  resetModel();
  emit('search');
}

async function search() {
  await validate();
  emit('search');
}
</script>

<template>
  <NCard :bordered="false" size="small" class="card-wrapper">
    <NCollapse>
      <NCollapseItem :title="$t('common.search')" name="art-school-recruit-major-history-search">
        <NForm ref="formRef" :model="model" label-placement="left" :label-width="80">
          <NGrid responsive="screen" item-responsive>
            <NFormItemGi
              span="24 s:12 m:6"
              label="对应招录专业ID"
              label-width="auto"
              path="recruitMajorId"
              class="pr-24px"
            >
              <NInput v-model:value="model.recruitMajorId" placeholder="请输入对应招录专业ID" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="学校ID" label-width="auto" path="schoolId" class="pr-24px">
              <NInput v-model:value="model.schoolId" placeholder="请输入学校ID" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="学校代码" label-width="auto" path="schoolCode" class="pr-24px">
              <NInput v-model:value="model.schoolCode" placeholder="请输入学校代码" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="院校代码" label-width="auto" path="collegeCode" class="pr-24px">
              <NInput v-model:value="model.collegeCode" placeholder="请输入院校代码" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="学校名称" label-width="auto" path="schoolName" class="pr-24px">
              <NInput v-model:value="model.schoolName" placeholder="请输入学校名称" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="专业ID" label-width="auto" path="majorId" class="pr-24px">
              <NInput v-model:value="model.majorId" placeholder="请输入专业ID" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="专业代码" label-width="auto" path="majorCode" class="pr-24px">
              <NInput v-model:value="model.majorCode" placeholder="请输入专业代码" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="专业名称" label-width="auto" path="majorName" class="pr-24px">
              <NInput v-model:value="model.majorName" placeholder="请输入专业名称" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="招生代码" label-width="auto" path="enrollCode" class="pr-24px">
              <NInput v-model:value="model.enrollCode" placeholder="请输入招生代码" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="专业类型" label-width="auto" path="majorType" class="pr-24px">
              <NSelect v-model:value="model.majorType" placeholder="请选择专业类型" :options="[]" clearable />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="专业类别子级" label-width="auto" path="majorTypeSub" class="pr-24px">
              <NInput v-model:value="model.majorTypeSub" placeholder="请输入专业类别子级" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="主考科目" label-width="auto" path="mainExamSubject" class="pr-24px">
              <NInput v-model:value="model.mainExamSubject" placeholder="请输入主考科目" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="年份" label-width="auto" path="year" class="pr-24px">
              <NInput v-model:value="model.year" placeholder="请输入年份" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="科类(文/理)" label-width="auto" path="subjectType" class="pr-24px">
              <NSelect v-model:value="model.subjectType" placeholder="请选择科类(文/理)" :options="[]" clearable />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="批次" label-width="auto" path="batchName" class="pr-24px">
              <NInput v-model:value="model.batchName" placeholder="请输入批次" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="录取方式(文*x+专*y)"
              label-width="auto"
              path="admissionFormula"
              class="pr-24px"
            >
              <NInput v-model:value="model.admissionFormula" placeholder="请输入录取方式(文*x+专*y)" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="录取概率规则运算符"
              label-width="auto"
              path="probabilityOperator"
              class="pr-24px"
            >
              <NInput v-model:value="model.probabilityOperator" placeholder="请输入录取概率规则运算符" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="省控线" label-width="auto" path="controlScore" class="pr-24px">
              <NInput v-model:value="model.controlScore" placeholder="请输入省控线" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="录取线" label-width="auto" path="admissionScore" class="pr-24px">
              <NInput v-model:value="model.admissionScore" placeholder="请输入录取线" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="招生人数" label-width="auto" path="planEnroll" class="pr-24px">
              <NInput v-model:value="model.planEnroll" placeholder="请输入招生人数" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="实际投档人数" label-width="auto" path="filedAmount" class="pr-24px">
              <NInput v-model:value="model.filedAmount" placeholder="请输入实际投档人数" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="录取数" label-width="auto" path="admitAmount" class="pr-24px">
              <NInput v-model:value="model.admitAmount" placeholder="请输入录取数" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="一志愿录取数"
              label-width="auto"
              path="firstChoiceAdmitAmount"
              class="pr-24px"
            >
              <NInput v-model:value="model.firstChoiceAdmitAmount" placeholder="请输入一志愿录取数" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="最低分数差" label-width="auto" path="minScoreDiff" class="pr-24px">
              <NInput v-model:value="model.minScoreDiff" placeholder="请输入最低分数差" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="学费(元/年)" label-width="auto" path="tuitionFee" class="pr-24px">
              <NInput v-model:value="model.tuitionFee" placeholder="请输入学费(元/年)" />
            </NFormItemGi>
            <NFormItemGi :show-feedback="false" span="24" class="pr-24px">
              <NSpace class="w-full" justify="end">
                <NButton @click="reset">
                  <template #icon>
                    <icon-ic-round-refresh class="text-icon" />
                  </template>
                  {{ $t('common.reset') }}
                </NButton>
                <NButton type="primary" ghost @click="search">
                  <template #icon>
                    <icon-ic-round-search class="text-icon" />
                  </template>
                  {{ $t('common.search') }}
                </NButton>
              </NSpace>
            </NFormItemGi>
          </NGrid>
        </NForm>
      </NCollapseItem>
    </NCollapse>
  </NCard>
</template>

<style scoped></style>
