| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import { EnumDictName } from "@/common/enum";
- import { useDictStore } from "@/store/dictStore";
- import { useAppStore } from "@/store/appStore";
- import { DictItem, System } from "@/types";
- import { getExamMajors, getExamTypes, getGraduateYears, getProvinces } from "@/api/modules/system";
- import { StudentExamInfo, UserInfo } from "@/types/user";
- const dictStore = useDictStore();
- const appStore = useAppStore();
- export const useExamType = () => {
- const form = ref<Partial<Pick<StudentExamInfo, 'location' | 'examType' | 'endYear' | 'majorType'>>>({})
- const provinceList = ref<System.ProvinceItem[]>([]);
- const examTypeList = ref<DictItem[]>([]);
- const examMajorList = ref<DictItem[]>([]);
- const endYearList = ref<DictItem[]>([]);
- const loadProvinceData = async () => {
- const { rows } = await getProvinces();
- provinceList.value = rows;
- }
- const loadExamTypeData = async () => {
- if (form.value.location) {
- uni.$ie.showLoading();
- const { data } = await getExamTypes(form.value.location);
- examTypeList.value = data;
- uni.$ie.hideLoading();
- }
- }
- const loadExamMajorData = async () => {
- if (form.value.location && form.value.examType) {
- const { data } = await getExamMajors(form.value.location, form.value.examType);
- examMajorList.value = data;
- } else {
- examMajorList.value = [];
- }
- }
- const loadGraduateYearData = async () => {
- if (form.value.location && form.value.examType) {
- const { data } = await getGraduateYears(form.value.location, form.value.examType);
- endYearList.value = data;
- } else {
- endYearList.value = [];
- }
- }
- watch(() => form.value.location, (val) => {
- console.log('监听到省份数据', val)
- if (examTypeList.value.length) {
- form.value.examType = undefined;
- }
- if (examMajorList.value.length) {
- form.value.majorType = '';
- }
- if (endYearList.value.length) {
- form.value.endYear = undefined;
- }
- if (val) {
- loadExamTypeData();
- }
- loadGraduateYearData();
- });
- watch(() => form.value.examType, (val) => {
- if (val) {
- loadExamMajorData();
- loadGraduateYearData();
- }
- })
- loadProvinceData();
- return {
- form,
- provinceList,
- examTypeList,
- examMajorList,
- endYearList
- }
- }
|