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

84 lines
2.1 KiB

  1. <!-- 选择部门 -->
  2. <template>
  3. <treeselect v-model="selected" :options="list" :show-count="true" :disabled="readonly" :multiple="multiple" :placeholder="$t('form.placeholderSelect')" @input="handleChange" />
  4. </template>
  5. <script>
  6. import Treeselect from "@riophae/vue-treeselect"
  7. import { deptTreeSelect } from "@/api/system/user"
  8. import "@riophae/vue-treeselect/dist/vue-treeselect.css"
  9. export default {
  10. name: "SelectDept",
  11. components: {Treeselect},
  12. props: {
  13. value: {
  14. type: [Number, String , Array],
  15. default: null,
  16. },
  17. readonly: {
  18. type: Boolean,
  19. default: false
  20. },
  21. multiple: {
  22. type: Boolean,
  23. default: false
  24. },
  25. },
  26. watch: {
  27. value: {
  28. immediate: true,
  29. handler(v) {
  30. if (!this.multiple) {
  31. this.selected = v ? parseInt(v) : null
  32. } else {
  33. if (v) {
  34. //默认传的,分割的字符串,有传数组再改造
  35. debugger
  36. let arr = (v+'').split(',')
  37. let s = []
  38. _.forEach(arr, a => {
  39. s.push(parseInt(a))
  40. })
  41. this.selected = s
  42. } else {
  43. this.selected = []
  44. }
  45. }
  46. }
  47. },
  48. },
  49. data() {
  50. return {
  51. selected: null,
  52. list: [],
  53. };
  54. },
  55. mounted() {
  56. this.getList()
  57. },
  58. methods: {
  59. getList() {
  60. this.list = []
  61. deptTreeSelect().then(response => {
  62. this.list = this.filterDisabledDept(JSON.parse(JSON.stringify(response.data)))
  63. })
  64. },
  65. // 过滤禁用的部门
  66. filterDisabledDept(deptList) {
  67. return deptList.filter(dept => {
  68. if (dept.disabled) {
  69. return false
  70. }
  71. if (dept.children && dept.children.length) {
  72. dept.children = this.filterDisabledDept(dept.children)
  73. }
  74. return true
  75. })
  76. },
  77. handleChange(val) {
  78. this.$emit('input', this.multiple ? (val && val.length > 0 ? val.join(',') : '') : (val || ''))
  79. this.$emit('change', this.multiple ? (val && val.length > 0 ? val.join(',') : '') : (val || ''))
  80. },
  81. }
  82. };
  83. </script>