DetailNameSelect.vue 1.7 KB

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