CollegeSelect.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <el-select
  3. v-model="selected"
  4. class="college-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.id"
  14. :value="item.id"
  15. :label="item.name"
  16. >
  17. </el-option>
  18. </el-select>
  19. </template>
  20. <script>
  21. import {
  22. unitQueryByType
  23. // organizationFindByTypeList
  24. } from "../../modules/base/api";
  25. export default {
  26. name: "college-select",
  27. props: {
  28. disabled: { type: Boolean, default: false },
  29. placeholder: { type: String, default: "请选择" },
  30. value: { type: [Number, String], default: "" },
  31. clearable: { type: Boolean, default: true },
  32. semesterId: { type: String, default: "" },
  33. cascader: { type: Boolean, default: false }
  34. },
  35. data() {
  36. return {
  37. optionList: [],
  38. selected: ""
  39. };
  40. },
  41. watch: {
  42. value: {
  43. immediate: true,
  44. handler(val) {
  45. this.selected = val;
  46. }
  47. },
  48. semesterId(val, oldval) {
  49. if (val !== oldval) {
  50. this.search("");
  51. this.$emit("input", "");
  52. this.$emit("change", {});
  53. }
  54. }
  55. },
  56. created() {
  57. this.search();
  58. },
  59. methods: {
  60. async search() {
  61. this.optionList = [];
  62. if (this.cascader && !this.semesterId) return;
  63. if (this.cascader) {
  64. const res = await unitQueryByType(
  65. {
  66. semesterId: this.semesterId
  67. },
  68. "COLLEGE"
  69. );
  70. this.optionList = res;
  71. } else {
  72. // const res = await organizationFindByTypeList({ orgType: "COLLEGE" });
  73. const res = await unitQueryByType({}, "COLLEGE");
  74. this.optionList = res;
  75. }
  76. },
  77. select() {
  78. this.$emit("input", this.selected);
  79. this.$emit(
  80. "change",
  81. this.optionList.find(item => item.id === this.selected)
  82. );
  83. }
  84. }
  85. };
  86. </script>