PlaceSelect.vue 1.4 KB

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