CourseSelect.vue 2.2 KB

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