DictSelection.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <el-select
  3. v-model="selectVal"
  4. style="width: 100%"
  5. v-bind="$attrs"
  6. v-on="$listeners"
  7. filterable
  8. >
  9. <el-option
  10. v-for="item in dictList"
  11. :key="item[valueName]"
  12. :value="item[valueName]"
  13. :label="ChinEng ? item[labelName] + '-' + item[valueName] : item[labelName]"
  14. ></el-option>
  15. </el-select>
  16. </template>
  17. <script>
  18. import dictEnum from '@/enum/dict';
  19. import { mapActions, mapGetters } from 'vuex';
  20. export default {
  21. model: {
  22. prop: 'value',
  23. event: 'updateVal'
  24. },
  25. props: {
  26. value: {
  27. type: [String, Number, Array],
  28. default: ''
  29. },
  30. dictName: {
  31. type: String,
  32. required: true
  33. },
  34. labelName: {
  35. type: String,
  36. default: 'dictValue'
  37. },
  38. valueName: {
  39. type: String,
  40. default: 'dictCode'
  41. },
  42. ChinEng: {
  43. Boolean,
  44. default: false
  45. }
  46. },
  47. data () {
  48. return {};
  49. },
  50. computed: {
  51. ...mapGetters(['dict', 'getDict']),
  52. dictList () {
  53. return this.dict[dictEnum[this.dictName]] || [];
  54. },
  55. selectVal: {
  56. set (val) {
  57. this.$emit('updateVal', val);
  58. // change获取选中项所有数据
  59. this.$emit('itemChange', this.getDict(this.dictName, val));
  60. },
  61. get () {
  62. return this.value;
  63. }
  64. }
  65. },
  66. created () {
  67. if (this.dictName) {
  68. this.requestDict(this.dictName);
  69. }
  70. },
  71. methods: {
  72. ...mapActions('dict', ['requestDict'])
  73. }
  74. };
  75. </script>