华西海圻ELN前端工程
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.2 KiB

  1. <!-- 存储位置选择器 -->
  2. <template>
  3. <div>
  4. <el-select style="width:100%" v-model="selected" :placeholder="$t('form.placeholderSelect')" :disabled="readonly" :multiple="multiple" @change="handleChange" :filterable="filterable">
  5. <el-option v-for="item in list" :key="item.dictCode" :label="item.dictLabel" :value="item.dictLabel" />
  6. </el-select>
  7. </div>
  8. </template>
  9. <script>
  10. import { listData } from "@/api/system/dict/data"
  11. export default {
  12. name: "SelectCcwz",
  13. components: {},
  14. props: {
  15. value: {
  16. type: [Number, String , Array],
  17. default: '',
  18. },
  19. readonly: {
  20. type: Boolean,
  21. default: false
  22. },
  23. multiple: {
  24. type: Boolean,
  25. default: false
  26. },
  27. filterable: {
  28. type: Boolean,
  29. default: true
  30. },
  31. placeholder: {
  32. type: String,
  33. default: ''
  34. }
  35. },
  36. watch: {
  37. value: {
  38. immediate: true,
  39. handler(v) {
  40. if(!this.multiple){
  41. this.selected = v ? v : ''
  42. }else{
  43. if(v){
  44. //默认传的,分割的字符串,有传数组再改造
  45. let arr = v.split(',')
  46. let s = []
  47. _.forEach(arr,a=>{
  48. s.push(a)
  49. })
  50. this.selected = s
  51. }else{
  52. this.selected = []
  53. }
  54. }
  55. }
  56. },
  57. },
  58. data() {
  59. return {
  60. selected: '',
  61. list: [],
  62. queryParams: {
  63. pageNum: 1,
  64. pageSize: 9999,
  65. dictType: 'system_business_ccwz',
  66. status: 0
  67. },
  68. };
  69. },
  70. mounted() {
  71. this.getList()
  72. },
  73. methods: {
  74. getList() {
  75. this.list = []
  76. listData(this.queryParams).then(response => {
  77. this.list = response.rows
  78. })
  79. },
  80. handleChange(val) {
  81. this.$emit('input', this.multiple ? (val && val.length>0 ? val.join(','): ''):(val || ''))
  82. //默认传的,分割的字符串,有传数组再改造
  83. let _index = _.findIndex(this.list, function (a) {
  84. return a.dictLabel == val
  85. })
  86. console.log(_index)
  87. if (_index > -1) {
  88. this.$emit('change', this.list[_index])
  89. } else {
  90. this.$emit('change', null)
  91. }
  92. },
  93. }
  94. };
  95. </script>