QuestionTeacherSelect.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <el-select
  3. v-model="selected"
  4. class="question-teacher-select"
  5. :placeholder="placeholder"
  6. :style="styles"
  7. filterable
  8. :clearable="clearable"
  9. :disabled="disabled"
  10. @change="select"
  11. >
  12. <el-option
  13. v-for="item in optionList"
  14. :key="item.id"
  15. :value="item.id"
  16. :label="item.name"
  17. ></el-option>
  18. </el-select>
  19. </template>
  20. <script>
  21. import { questionTeatherQuery } from "../../modules/exam/api";
  22. export default {
  23. name: "question-teacher-select",
  24. props: {
  25. disabled: { type: Boolean, default: false },
  26. placeholder: { type: String, default: "请选择" },
  27. value: { type: [Number, String], default: "" },
  28. styles: { type: String, default: "" },
  29. clearable: { type: Boolean, default: true },
  30. courseCode: { type: String, default: "" },
  31. schoolId: { type: String, default: "" }
  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. courseCode(val, oldval) {
  47. if (val !== oldval) {
  48. this.search("");
  49. this.$emit("input", "");
  50. this.$emit("change", {});
  51. }
  52. },
  53. schoolId(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(query) {
  66. const res = await questionTeatherQuery({
  67. param: query,
  68. courseCode: this.courseCode,
  69. schoolId: this.schoolId
  70. });
  71. this.optionList = res;
  72. },
  73. select() {
  74. this.$emit("input", this.selected);
  75. this.$emit(
  76. "change",
  77. this.optionList.find(item => item.id === this.selected)
  78. );
  79. }
  80. }
  81. };
  82. </script>