PlaceSelect.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <el-select
  3. v-model="selected"
  4. class="place-select"
  5. :placeholder="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. placeholder: { type: String, default: "请选择" },
  28. value: { type: [Number, String], default: "" },
  29. styles: { type: String, default: "" },
  30. clearable: { type: Boolean, default: true },
  31. printPlanId: { type: [String, Array], default: "" }
  32. },
  33. data() {
  34. return {
  35. optionList: [],
  36. selected: ""
  37. };
  38. },
  39. watch: {
  40. value: {
  41. immediate: true,
  42. handler(val) {
  43. this.selected = val;
  44. }
  45. },
  46. printPlanId(val, oldval) {
  47. if (val !== oldval) {
  48. this.search("");
  49. this.$emit("input", "");
  50. this.$emit("change", {});
  51. }
  52. }
  53. },
  54. async created() {
  55. this.search();
  56. },
  57. methods: {
  58. async search(query) {
  59. const res = await placeQuery({
  60. param: query,
  61. printPlanId: this.printPlanId
  62. });
  63. this.optionList = res;
  64. },
  65. select() {
  66. this.$emit("input", this.selected);
  67. this.$emit("change", this.selected);
  68. }
  69. }
  70. };
  71. </script>