index.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <div>
  3. <el-select
  4. :value="value"
  5. filterable
  6. remote
  7. reserve-keyword
  8. :placeholder="placeholder"
  9. :remote-method="remoteMethod"
  10. :loading="loading"
  11. @change="changeValue"
  12. >
  13. <el-option
  14. v-for="(item, index) in options"
  15. :key="index"
  16. :label="item.userName"
  17. :value="item.userId"
  18. >
  19. </el-option>
  20. </el-select>
  21. </div>
  22. </template>
  23. <script>
  24. const placeholder = {
  25. setTeachers: "请选择老师",
  26. setEducations: "请选乐团主管",
  27. };
  28. import { throttle, slice } from "lodash";
  29. import selects from "@/store/modules/selects";
  30. export default {
  31. props: ["commit", "number","value"],
  32. data() {
  33. return {
  34. options: [],
  35. list: [],
  36. loading: false,
  37. constant: this.number || 50,
  38. placeholder:placeholder[this.commit]
  39. };
  40. },
  41. async mounted() {
  42. await this.$store.dispatch(this.commit);
  43. this.list = this.selects[this.enumer[this.commit]];
  44. this.options =
  45. this.list.length <= this.constant
  46. ? this.list
  47. : slice(this.list, 0, this.constant);
  48. // console.log(this.options)
  49. },
  50. methods: {
  51. remoteMethod(query) {
  52. // throttle
  53. throttle(this.getOptions,800)(query)
  54. },
  55. getOptions(query) {
  56. this.options = this.list.filter(item=>{
  57. return item.userName.toLowerCase().indexOf(query.toLowerCase())>-1
  58. })
  59. },
  60. changeValue(val){
  61. this.$emit("input", val);
  62. }
  63. },
  64. computed: {
  65. enumer() {
  66. return {
  67. setTeachers: "teachers",
  68. setEducations: "educations",
  69. };
  70. },
  71. }
  72. };
  73. </script>
  74. <style lang="scss" scoped>
  75. </style>