华西海圻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.

113 lines
2.6 KiB

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