DeptTree.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div class="dialog-container">
  3. <el-dialog
  4. :visible.sync="visible"
  5. :close-on-press-escape="true"
  6. :close-on-click-modal="false"
  7. :show-close="false"
  8. custom-class="custom-dialog"
  9. title="接收单位"
  10. >
  11. <el-input v-model="treeFilter" placeholder="输入关键字进行过滤" />
  12. <el-tree
  13. ref="tree"
  14. class="filter-tree"
  15. :data="treeData"
  16. :props="treeProps"
  17. :node-key="nodeKey"
  18. :default-expanded-keys="defaultExpandedKeys"
  19. show-checkbox
  20. :expand-on-click-node="false"
  21. check-strictly
  22. check-on-click-node
  23. :filter-node-method="filterNode"
  24. />
  25. <div slot="footer">
  26. <el-button @click="visible = false">取消</el-button>
  27. <el-button type="primary" @click="save">确定</el-button>
  28. </div>
  29. </el-dialog>
  30. </div>
  31. </template>
  32. <script>
  33. import { isNull } from '@/utils/convert'
  34. export default {
  35. name: 'EmbeddedTree',
  36. props: {
  37. checkedKeys: {
  38. type: Array,
  39. default() {
  40. return []
  41. }
  42. },
  43. treeData: {
  44. type: Array,
  45. default() {
  46. return []
  47. }
  48. }
  49. },
  50. data() {
  51. return {
  52. visible: false,
  53. // tree
  54. treeProps: {
  55. children: 'children',
  56. label: 'shortName'
  57. },
  58. treeFilter: '',
  59. nodeKey: 'orgCode',
  60. defaultExpandedKeys: [],
  61. // others
  62. loading: false
  63. }
  64. },
  65. watch: {
  66. treeFilter(val) {
  67. this.$refs['tree'].filter(val)
  68. }
  69. },
  70. methods: {
  71. filterNode(value, data) {
  72. if (!value) return true
  73. return data[this.treeProps.label].indexOf(value) !== -1
  74. },
  75. open() {
  76. this.visible = true
  77. if (!isNull(this.treeData)) {
  78. this.defaultExpandedKeys = [this.treeData[0][this.nodeKey]]
  79. }
  80. if (!isNull(this.checkedKeys)) {
  81. this.$refs['tree'].setCheckedKeys(this.checkedKeys)
  82. }
  83. },
  84. save() {
  85. const checkedNodes = this.$refs['tree'].getCheckedNodes()
  86. if (!isNull(checkedNodes)) {
  87. this.$emit('updateValue', checkedNodes)
  88. this.visible = false
  89. } else {
  90. this.$message({
  91. type: 'warning',
  92. message: '请选择接收单位!'
  93. })
  94. }
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .dialog-container {
  101. ::v-deep {
  102. .custom-dialog {
  103. width: 500px !important;
  104. }
  105. }
  106. }
  107. </style>