6619a3a7e431d2013c64b5e604d2d398a92c2b0d.svn-base 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <a-select :value="arrayValue" @change="onChange" mode="multiple" :placeholder="placeholder">
  3. <a-select-option
  4. v-for="(item,index) in selectOptions"
  5. :key="index"
  6. :getPopupContainer="getParentContainer"
  7. :value="item.value">
  8. {{ item.text || item.label }}
  9. </a-select-option>
  10. </a-select>
  11. </template>
  12. <script>
  13. //option {label:,value:}
  14. import { getAction } from '@api/manage'
  15. export default {
  16. name: 'JSelectMultiple',
  17. props: {
  18. placeholder:{
  19. type: String,
  20. default:'',
  21. required: false
  22. },
  23. value:{
  24. type: String,
  25. required: false
  26. },
  27. readOnly:{
  28. type: Boolean,
  29. required: false,
  30. default: false
  31. },
  32. options:{
  33. type: Array,
  34. default:()=>[],
  35. required: false
  36. },
  37. triggerChange:{
  38. type: Boolean,
  39. required: false,
  40. default: false
  41. },
  42. spliter:{
  43. type: String,
  44. required: false,
  45. default: ','
  46. },
  47. popContainer:{
  48. type:String,
  49. default:'',
  50. required:false
  51. },
  52. dictCode:{
  53. type:String,
  54. required:false
  55. },
  56. },
  57. data(){
  58. return {
  59. arrayValue:!this.value?[]:this.value.split(this.spliter),
  60. dictOptions: [],
  61. }
  62. },
  63. computed:{
  64. selectOptions(){
  65. return this.dictOptions.length > 0 ? this.dictOptions : this.options
  66. },
  67. },
  68. watch:{
  69. value (val) {
  70. if(!val){
  71. this.arrayValue = []
  72. }else{
  73. this.arrayValue = this.value.split(this.spliter)
  74. }
  75. }
  76. },
  77. mounted(){
  78. if (this.dictCode) {
  79. this.loadDictOptions()
  80. }
  81. },
  82. methods:{
  83. onChange (selectedValue) {
  84. if(this.triggerChange){
  85. this.$emit('change', selectedValue.join(this.spliter));
  86. }else{
  87. this.$emit('input', selectedValue.join(this.spliter));
  88. }
  89. },
  90. getParentContainer(node){
  91. if(!this.popContainer){
  92. return node.parentNode
  93. }else{
  94. return document.querySelector(this.popContainer)
  95. }
  96. },
  97. // 根据字典code查询字典项
  98. loadDictOptions(){
  99. getAction(`/sys/dict/getDictItems/${this.dictCode}`,{}).then(res=>{
  100. if (res.success) {
  101. this.dictOptions = res.result.map(item => ({value: item.value, label: item.text}))
  102. } else {
  103. console.error('getDictItems error: : ', res)
  104. this.dictOptions = []
  105. }
  106. })
  107. },
  108. },
  109. }
  110. </script>