123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <template>
- <el-select
- v-model="selected"
- class="place-select"
- placeholder="请选择"
- :style="styles"
- 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 { placeQuery } from "../../modules/print/api";
- export default {
- name: "place-select",
- props: {
- disabled: { type: Boolean, default: false },
- value: { type: [Number, String], default: "" },
- styles: { type: 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 placeQuery({
- param: query,
- printPlanId: this.printPlanId
- });
- this.optionList = res;
- },
- select() {
- this.$emit("input", this.selected);
- this.$emit("change", this.selected);
- }
- }
- };
- </script>
|