ExamRoomSelect.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <el-select
  3. v-model="selected"
  4. class="size-select"
  5. placeholder="请选择"
  6. @change="select"
  7. :style="styles"
  8. filterable
  9. remote
  10. :remote-method="search"
  11. clearable
  12. >
  13. <el-option
  14. v-for="item in optionList"
  15. :key="item.roomCode"
  16. :label="item.roomName"
  17. :value="item.roomCode"
  18. >
  19. <span>{{ item.roomName }}</span>
  20. </el-option>
  21. </el-select>
  22. </template>
  23. <script>
  24. import { object2QueryString } from "@/utils/utils";
  25. export default {
  26. name: "ExamRoomSelect",
  27. props: {
  28. value: [String, Array],
  29. styles: { type: String },
  30. },
  31. data() {
  32. return {
  33. optionList: [],
  34. selected: "",
  35. };
  36. },
  37. async created() {
  38. this.search();
  39. },
  40. watch: {
  41. value: {
  42. immediate: true,
  43. handler(val) {
  44. this.selected = val;
  45. },
  46. },
  47. },
  48. methods: {
  49. async search(query) {
  50. const res = await this.$http.post(
  51. "/api/admin/sys/examRoom/query?" +
  52. object2QueryString({ roomName: query })
  53. );
  54. // console.log(res.data);
  55. this.optionList = res.data.data;
  56. },
  57. select() {
  58. this.$emit("input", this.selected);
  59. this.$emit("change", this.selected);
  60. },
  61. },
  62. };
  63. </script>
  64. <style></style>