PlaceSelect.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <el-select
  3. v-model="selected"
  4. class="place-select"
  5. placeholder="请选择"
  6. :style="styles"
  7. filterable
  8. :clearable="clearable"
  9. :disabled="disabled"
  10. @change="select"
  11. >
  12. <el-option
  13. v-for="(item, index) in optionList"
  14. :key="index"
  15. :value="item"
  16. :label="item"
  17. >
  18. </el-option>
  19. </el-select>
  20. </template>
  21. <script>
  22. import { placeQuery } from "../../modules/print/api";
  23. export default {
  24. name: "place-select",
  25. props: {
  26. disabled: { type: Boolean, default: false },
  27. value: { type: [Number, String], default: "" },
  28. styles: { type: String, default: "" },
  29. clearable: { type: Boolean, default: true },
  30. printPlanId: { type: [String, Array], default: "" }
  31. },
  32. data() {
  33. return {
  34. optionList: [],
  35. selected: ""
  36. };
  37. },
  38. watch: {
  39. value: {
  40. immediate: true,
  41. handler(val) {
  42. this.selected = val;
  43. }
  44. },
  45. printPlanId(val, oldval) {
  46. if (val !== oldval) {
  47. this.search("");
  48. this.$emit("input", "");
  49. this.$emit("change", {});
  50. }
  51. }
  52. },
  53. async created() {
  54. this.search();
  55. },
  56. methods: {
  57. async search(query) {
  58. const res = await placeQuery({
  59. param: query,
  60. printPlanId: this.printPlanId
  61. });
  62. this.optionList = res;
  63. },
  64. select() {
  65. this.$emit("input", this.selected);
  66. this.$emit("change", this.selected);
  67. }
  68. }
  69. };
  70. </script>