simpleSelect.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <!-- <uni-data-select v-model="select" :localdata="options" :disabled="readonly" @change="change"></uni-data-select> -->
  3. <zxz-uni-data-select v-model="select" :localdata="options" :disabled="readonly" :multiple="multiple" @change="change"></zxz-uni-data-select>
  4. </template>
  5. <script>
  6. import {
  7. getAllChildren
  8. } from '@/api/system'
  9. import * as staticAll from './options.js'
  10. import { getDict2 } from '@/utils/dict.js'
  11. export default {
  12. name: "simpleSelect",
  13. props: {
  14. value: {
  15. type: [String, Number, Array],
  16. required: false,
  17. default: null,
  18. },
  19. data: {
  20. type: [String, Number, Array],
  21. required: true
  22. },
  23. loadType: {
  24. type: String,
  25. required: false,
  26. default: "local"
  27. },
  28. field: {
  29. type: String,
  30. required: false,
  31. default: "default"
  32. },
  33. multiple: {
  34. type: Boolean,
  35. required: false,
  36. default: false,
  37. },
  38. ext: {
  39. type: Object,
  40. required: false,
  41. default: () => ({}),
  42. },
  43. readonly: {
  44. type: Boolean,
  45. required: false,
  46. default: false,
  47. }
  48. },
  49. computed: {
  50. isLocal() {
  51. return this.loadType === 'local'
  52. },
  53. isDict() {
  54. return this.loadType === 'dict'
  55. },
  56. isStatic() {
  57. return this.loadType === 'static'
  58. }
  59. },
  60. data() {
  61. return {
  62. select: this.value,
  63. options: [],
  64. };
  65. },
  66. watch: {
  67. value(n, o) {
  68. this.select = n
  69. },
  70. data(n, o) {
  71. this.init()
  72. }
  73. },
  74. mounted() {
  75. this.init()
  76. },
  77. methods: {
  78. init() {
  79. this.options = []
  80. if (this.isDict) {
  81. this.loadDict()
  82. } else if (this.isLocal) {
  83. this.options = this.data
  84. } else if (this.isStatic) {
  85. this.loadStatic()
  86. }
  87. },
  88. loadDict() {
  89. getDict2(this.data, true).then(list => {
  90. this.options = list.map(d => {
  91. const ret = {
  92. text: d.enumname,
  93. raw: d,
  94. }
  95. if (this.field === 'default') {
  96. ret.value = d.enumid
  97. } else if (this.field.startsWith('raw.')) {
  98. const [
  99. _,
  100. f
  101. ] = this.field.split('\.')
  102. ret.value = d[f]
  103. }
  104. return ret
  105. })
  106. })
  107. },
  108. loadStatic() {
  109. const opts = staticAll[this.data]
  110. this.options = opts
  111. },
  112. change(n) {
  113. this.$emit('input', this.select)
  114. if(this.multiple) {
  115. const o = this.options.filter(d => this.select.includes(d.value))
  116. this.$emit('on-change', this.select, o)
  117. }else {
  118. console.log('change', this.options, n);
  119. this.$emit('on-change', this.select, n)
  120. }
  121. }
  122. }
  123. }
  124. </script>
  125. <style>
  126. </style>