QuestionTeacherSelect.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <el-select
  3. v-model="selected"
  4. class="question-teacher-select"
  5. 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. value: { type: [Number, String], default: "" },
  27. styles: { type: String, default: "" },
  28. clearable: { type: Boolean, default: true },
  29. courseCode: { type: String, default: "" },
  30. schoolId: { type: String, default: "" }
  31. },
  32. data() {
  33. return {
  34. optionList: [],
  35. selected: ""
  36. };
  37. },
  38. watch: {
  39. value: {
  40. immediate: true,
  41. handler(val) {
  42. this.selected = val;
  43. }
  44. },
  45. courseCode(val, oldval) {
  46. if (val !== oldval) {
  47. this.search("");
  48. this.$emit("input", "");
  49. this.$emit("change", {});
  50. }
  51. },
  52. schoolId(val, oldval) {
  53. if (val !== oldval) {
  54. this.search("");
  55. this.$emit("input", "");
  56. this.$emit("change", {});
  57. }
  58. }
  59. },
  60. async created() {
  61. this.search();
  62. },
  63. methods: {
  64. async search(query) {
  65. const res = await questionTeatherQuery({
  66. param: query,
  67. courseCode: this.courseCode,
  68. schoolId: this.schoolId
  69. });
  70. this.optionList = res;
  71. },
  72. select() {
  73. this.$emit("input", this.selected);
  74. this.$emit(
  75. "change",
  76. this.optionList.find(item => item.id === this.selected)
  77. );
  78. }
  79. }
  80. };
  81. </script>