ScanTaskSelect.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <el-select
  3. v-model="selected"
  4. class="scan-task-select"
  5. :placeholder="placeholder"
  6. remote
  7. :remote-method="search"
  8. :clearable="clearable"
  9. :disabled="disabled"
  10. @change="select"
  11. >
  12. <el-option
  13. v-for="item in optionList"
  14. :key="item.id"
  15. :value="item.id"
  16. :label="item.name"
  17. >
  18. </el-option>
  19. </el-select>
  20. </template>
  21. <script>
  22. import { commonScanTaskQuery } from "../../modules/base/api";
  23. export default {
  24. name: "scan-task-select",
  25. props: {
  26. disabled: { type: Boolean, default: false },
  27. placeholder: { type: String, default: "请选择学期" },
  28. value: { type: [Number, String], default: "" },
  29. clearable: { type: Boolean, default: true },
  30. paperArchivesId: { type: String, 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. paperArchivesId(val, oldval) {
  46. if (val !== oldval) {
  47. this.search("");
  48. this.$emit("input", "");
  49. this.$emit("change", {});
  50. }
  51. }
  52. },
  53. created() {
  54. this.search();
  55. },
  56. methods: {
  57. async search() {
  58. this.optionList = [];
  59. let data = {};
  60. if (this.paperArchivesId) data.paperArchivesId = this.paperArchivesId;
  61. const res = await commonScanTaskQuery(data);
  62. this.optionList = res;
  63. },
  64. select() {
  65. this.$emit("input", this.selected);
  66. this.$emit(
  67. "change",
  68. this.optionList.find(item => item.id === this.selected)
  69. );
  70. }
  71. }
  72. };
  73. </script>