PrintRoomSelect.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <el-select
  3. v-model="selected"
  4. class="print-room-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 { organizationFindByTypeList } from "../../modules/base/api";
  22. export default {
  23. name: "print-room-select",
  24. props: {
  25. disabled: { type: Boolean, default: false },
  26. placeholder: { type: String, default: "请选择" },
  27. value: { type: [Number, String], default: "" },
  28. clearable: { type: Boolean, default: true },
  29. },
  30. data() {
  31. return {
  32. optionList: [],
  33. selected: "",
  34. };
  35. },
  36. watch: {
  37. value: {
  38. immediate: true,
  39. handler(val) {
  40. this.selected = val;
  41. },
  42. },
  43. },
  44. created() {
  45. this.search();
  46. },
  47. methods: {
  48. async search() {
  49. const res = await organizationFindByTypeList({
  50. orgType: "PRINTING_HOUSE",
  51. });
  52. this.optionList = res;
  53. },
  54. select() {
  55. this.$emit("input", this.selected);
  56. this.$emit(
  57. "change",
  58. this.optionList.find((item) => item.id === this.selected)
  59. );
  60. },
  61. },
  62. };
  63. </script>