1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <template>
- <el-select
- v-model="selected"
- class="room-select"
- :placeholder="placeholder"
- filterable
- :clearable="clearable"
- :disabled="disabled"
- @change="select"
- >
- <el-option
- v-for="(item, index) in optionList"
- :key="index"
- :value="item"
- :label="item"
- >
- </el-option>
- </el-select>
- </template>
- <script>
- import { roomQuery } from "../../modules/print/api";
- export default {
- name: "room-select",
- props: {
- disabled: { type: Boolean, default: false },
- placeholder: { type: String, default: "请选择" },
- value: { type: [Number, String], default: "" },
- clearable: { type: Boolean, default: true },
- printPlanId: { type: [String, Array], default: "" }
- },
- data() {
- return {
- optionList: [],
- selected: ""
- };
- },
- watch: {
- value: {
- immediate: true,
- handler(val) {
- this.selected = val;
- }
- },
- printPlanId(val, oldval) {
- if (val !== oldval) {
- this.search("");
- this.$emit("input", "");
- this.$emit("change", {});
- }
- }
- },
- async created() {
- this.search();
- },
- methods: {
- async search(query) {
- const res = await roomQuery({
- param: query,
- printPlanId: this.printPlanId
- });
- this.optionList = res;
- },
- select() {
- this.$emit("input", this.selected);
- this.$emit("change", this.selected);
- }
- }
- };
- </script>
|