QuestionTeacherUserSelect.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <el-select
  3. v-model="selected"
  4. class="question-teacher-user-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 { questionTeatherUserQuery } from "../../modules/base/api";
  22. export default {
  23. name: "question-teacher-user-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. },
  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. },
  53. async created() {
  54. this.search();
  55. },
  56. methods: {
  57. async search(query) {
  58. if (!this.courseCode) return;
  59. const res = await questionTeatherUserQuery({
  60. param: query,
  61. courseCode: this.courseCode
  62. });
  63. this.optionList = res;
  64. },
  65. select() {
  66. this.$emit("input", this.selected);
  67. this.$emit(
  68. "change",
  69. this.optionList.find(item => item.id === this.selected)
  70. );
  71. }
  72. }
  73. };
  74. </script>