classes-select.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <!-- 班次 -->
  3. <el-select
  4. v-model="selectVal"
  5. filterable
  6. style="width: 100%"
  7. v-bind="$attrs"
  8. v-on="$listeners"
  9. clearable
  10. >
  11. <el-option
  12. v-for="item in dictList"
  13. :key="item.id"
  14. :label="item.name"
  15. :value="item.id"
  16. ></el-option>
  17. </el-select>
  18. </template>
  19. <script>
  20. import { getteamtime } from '@/api/workforceManagement/classes';
  21. export default {
  22. model: {
  23. prop: 'value',
  24. event: 'updateVal'
  25. },
  26. props: {
  27. value: {
  28. type: [String, Number, Array],
  29. default: ''
  30. },
  31. init: {
  32. type: Boolean,
  33. default: true
  34. }
  35. },
  36. data () {
  37. return {
  38. selectName: 'classes'
  39. };
  40. },
  41. computed: {
  42. dictList () {
  43. return this.$store.state.selectCache[this.selectName] || [];
  44. },
  45. selectVal: {
  46. set (val) {
  47. this.$emit(
  48. 'selfChange',
  49. val,
  50. this.dictList.find((i) => i.id === val)
  51. );
  52. this.$emit('updateVal', val);
  53. },
  54. get () {
  55. return this.value;
  56. }
  57. }
  58. },
  59. created () {
  60. if (this.init) {
  61. this.getList();
  62. }
  63. },
  64. methods: {
  65. async getList () {
  66. if (this.dictList.length) return;
  67. const res = await getteamtime({
  68. pageNum: 1,
  69. size: -1
  70. });
  71. this.$store.commit('selectCache/ADD_SELECT', {
  72. name: this.selectName,
  73. dict: res.list
  74. });
  75. }
  76. }
  77. };
  78. </script>