<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: 'SchoolRecruitMajorSearch'
});

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

const emit = defineEmits<Emits>();

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

const model = defineModel<Api.Art.SchoolRecruitMajorSearchParams>('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-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="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="schoolName" class="pr-24px">
              <NInput v-model:value="model.schoolName" 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="专业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="dataStatus"
              class="pr-24px"
            >
              <NSelect
                v-model:value="model.dataStatus"
                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="专业类型" 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="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="admissionWayShort"
              class="pr-24px"
            >
              <NInput v-model:value="model.admissionWayShort" placeholder="请输入录取方式缩写" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="对外录取方式"
              label-width="auto"
              path="admissionWayExternal"
              class="pr-24px"
            >
              <NInput v-model:value="model.admissionWayExternal" placeholder="请输入对外录取方式" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="对外录取方式运算符"
              label-width="auto"
              path="admissionWayExternalOp"
              class="pr-24px"
            >
              <NInput v-model:value="model.admissionWayExternalOp" placeholder="请输入对外录取方式运算符" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="内部录取方式"
              label-width="auto"
              path="admissionWayInternal"
              class="pr-24px"
            >
              <NInput v-model:value="model.admissionWayInternal" placeholder="请输入内部录取方式" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="内部录取方式运算符"
              label-width="auto"
              path="admissionWayInternalOp"
              class="pr-24px"
            >
              <NInput v-model:value="model.admissionWayInternalOp" 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="mainExamSubject" class="pr-24px">
              <NInput v-model:value="model.mainExamSubject" placeholder="请输入主考科目" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="学制(年)" label-width="auto" path="schoolingYears" class="pr-24px">
              <NInput v-model:value="model.schoolingYears" placeholder="请输入学制(年)" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="院校限制说明"
              label-width="auto"
              path="enrollLimitDesc"
              class="pr-24px"
            >
              <NInput v-model:value="model.enrollLimitDesc" 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
              span="24 s:12 m:6"
              label="文化分数限制"
              label-width="auto"
              path="cultureScoreLimit"
              class="pr-24px"
            >
              <NInput v-model:value="model.cultureScoreLimit" placeholder="请输入文化分数限制" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="专业分数限制"
              label-width="auto"
              path="majorScoreLimit"
              class="pr-24px"
            >
              <NInput v-model:value="model.majorScoreLimit" placeholder="请输入专业分数限制" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="语文成绩限制"
              label-width="auto"
              path="chineseScoreLimit"
              class="pr-24px"
            >
              <NInput v-model:value="model.chineseScoreLimit" placeholder="请输入语文成绩限制" />
            </NFormItemGi>
            <NFormItemGi
              span="24 s:12 m:6"
              label="英语成绩限制"
              label-width="auto"
              path="englishScoreLimit"
              class="pr-24px"
            >
              <NInput v-model:value="model.englishScoreLimit" 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>
