OrgCourseSelect.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 in optionList"
  13. :key="item.basicCourseId"
  14. :value="item.basicCourseId"
  15. :label="`${item.courseName}(${item.courseCode})`"
  16. >
  17. <span>{{ `${item.courseName}(${item.courseCode})` }}</span>
  18. </el-option>
  19. </el-select>
  20. </template>
  21. <script>
  22. import { courseQueryByOrg } from "../../modules/base/api";
  23. export default {
  24. name: "org-course-select",
  25. props: {
  26. disabled: { type: Boolean, default: false },
  27. placeholder: { type: String, default: "请选择" },
  28. value: { type: [Number, String], default: "" },
  29. clearable: { type: Boolean, default: true },
  30. filterParam: {
  31. type: Object,
  32. default() {
  33. return {};
  34. },
  35. },
  36. },
  37. data() {
  38. return {
  39. optionList: [],
  40. selected: "",
  41. };
  42. },
  43. watch: {
  44. value: {
  45. immediate: true,
  46. handler(val) {
  47. this.selected = val;
  48. },
  49. },
  50. filterParam(val, oldval) {
  51. if (JSON.stringify(val) !== JSON.stringify(oldval)) {
  52. this.search();
  53. this.$emit("input", "");
  54. this.$emit("change", {});
  55. }
  56. },
  57. },
  58. methods: {
  59. async search() {
  60. this.optionList = [];
  61. if (!this.filterParam.examId || !this.filterParam.belongOrgId) return;
  62. const res = await courseQueryByOrg(this.filterParam);
  63. this.optionList = res || [];
  64. },
  65. select() {
  66. this.$emit("input", this.selected);
  67. this.$emit(
  68. "change",
  69. this.optionList.find((item) => item.basicCourseId === this.selected)
  70. );
  71. },
  72. },
  73. };
  74. </script>