ClassSelect.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <el-select
  3. v-model="selected"
  4. class="class-select"
  5. :placeholder="placeholder"
  6. filterable
  7. :clearable="clearable"
  8. :disabled="disabled"
  9. @change="select"
  10. >
  11. <el-option
  12. v-for="item in optionList"
  13. :key="item.name"
  14. :value="item.name"
  15. :label="item.name"
  16. >
  17. </el-option>
  18. </el-select>
  19. </template>
  20. <script>
  21. import { commonCollegeMajorClassQuery } from "../../modules/base/api";
  22. export default {
  23. name: "class-select",
  24. props: {
  25. disabled: { type: Boolean, default: false },
  26. placeholder: { type: String, default: "请选择" },
  27. value: { type: [Number, String], default: "" },
  28. clearable: { type: Boolean, default: true },
  29. majorName: { type: String, default: "" },
  30. examId: { type: String, default: "" },
  31. cascader: { type: Boolean, default: false },
  32. },
  33. data() {
  34. return {
  35. optionList: [],
  36. selected: "",
  37. };
  38. },
  39. watch: {
  40. value: {
  41. immediate: true,
  42. handler(val) {
  43. this.selected = val;
  44. },
  45. },
  46. majorName(val, oldval) {
  47. if (val !== oldval) {
  48. this.search();
  49. this.$emit("input", "");
  50. this.$emit("change", {});
  51. }
  52. },
  53. examId(val, oldval) {
  54. if (val !== oldval) {
  55. this.search();
  56. this.$emit("input", "");
  57. this.$emit("change", {});
  58. }
  59. },
  60. },
  61. async created() {
  62. this.search();
  63. },
  64. methods: {
  65. async search() {
  66. this.optionList = [];
  67. if (!this.examId) return;
  68. if (this.cascader && !this.majorName) return;
  69. const res = await commonCollegeMajorClassQuery({
  70. majorName: this.majorName,
  71. examId: this.examId,
  72. dictionaryEnum: "CLAZZ",
  73. });
  74. this.optionList = res;
  75. },
  76. select() {
  77. this.$emit("input", this.selected);
  78. this.$emit(
  79. "change",
  80. this.optionList.find((item) => item.name === this.selected)
  81. );
  82. },
  83. },
  84. };
  85. </script>