useExamType.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { EnumDictName } from "@/common/enum";
  2. import { useDictStore } from "@/store/dictStore";
  3. import { useAppStore } from "@/store/appStore";
  4. import { DictItem, System } from "@/types";
  5. import { getExamMajors, getExamTypes, getGraduateYears, getProvinces } from "@/api/modules/system";
  6. import { StudentExamInfo, UserInfo } from "@/types/user";
  7. const dictStore = useDictStore();
  8. const appStore = useAppStore();
  9. export const useExamType = () => {
  10. const form = ref<Partial<Pick<StudentExamInfo, 'location' | 'examType' | 'endYear' | 'majorType'>>>({})
  11. const provinceList = ref<System.ProvinceItem[]>([]);
  12. const examTypeList = ref<DictItem[]>([]);
  13. const examMajorList = ref<DictItem[]>([]);
  14. const endYearList = ref<DictItem[]>([]);
  15. const loadProvinceData = async () => {
  16. const { rows } = await getProvinces();
  17. provinceList.value = rows;
  18. }
  19. const loadExamTypeData = async () => {
  20. if (form.value.location) {
  21. uni.$ie.showLoading();
  22. const { data } = await getExamTypes(form.value.location);
  23. examTypeList.value = data;
  24. uni.$ie.hideLoading();
  25. }
  26. }
  27. const loadExamMajorData = async () => {
  28. if (form.value.location && form.value.examType) {
  29. const { data } = await getExamMajors(form.value.location, form.value.examType);
  30. examMajorList.value = data;
  31. } else {
  32. examMajorList.value = [];
  33. }
  34. }
  35. const loadGraduateYearData = async () => {
  36. if (form.value.location && form.value.examType) {
  37. const { data } = await getGraduateYears(form.value.location, form.value.examType);
  38. endYearList.value = data;
  39. } else {
  40. endYearList.value = [];
  41. }
  42. }
  43. watch(() => form.value.location, (val) => {
  44. console.log('监听到省份数据', val)
  45. if (examTypeList.value.length) {
  46. form.value.examType = undefined;
  47. }
  48. if (examMajorList.value.length) {
  49. form.value.majorType = '';
  50. }
  51. if (endYearList.value.length) {
  52. form.value.endYear = undefined;
  53. }
  54. if (val) {
  55. loadExamTypeData();
  56. }
  57. loadGraduateYearData();
  58. });
  59. watch(() => form.value.examType, (val) => {
  60. if (val) {
  61. loadExamMajorData();
  62. loadGraduateYearData();
  63. }
  64. })
  65. loadProvinceData();
  66. return {
  67. form,
  68. provinceList,
  69. examTypeList,
  70. examMajorList,
  71. endYearList
  72. }
  73. }