index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <el-dialog
  3. title="选择机构"
  4. :visible.sync="visibleInChild"
  5. :append-to-body="appendToBody"
  6. :before-close="close"
  7. >
  8. <div class="el-dialog-body-custom-height">
  9. <el-input
  10. v-model="filterText"
  11. placeholder="请输入过滤条件"
  12. style="margin: 10px 0px 10px 0px"
  13. />
  14. <el-tree
  15. ref="_selectOrgTree"
  16. :data="treeData"
  17. node-key="id"
  18. :props="defaultProps"
  19. :filter-node-method="filterNode"
  20. class="filter-tree"
  21. check-strictly
  22. :show-checkbox="multipleSelect"
  23. />
  24. </div>
  25. <div slot="footer" class="dialog-footer">
  26. <el-button icon="el-icon-close" @click="visibleInChild = false"
  27. >取消</el-button
  28. >
  29. <el-button icon="el-icon-check" type="primary" @click="confirm"
  30. >确定</el-button
  31. >
  32. </div>
  33. </el-dialog>
  34. </template>
  35. <script>
  36. import { getAction } from '@/api/manage';
  37. import { Message } from 'element-ui';
  38. export default {
  39. name: 'SelectOrg',
  40. props: {
  41. visible: {
  42. type: Boolean,
  43. default: false
  44. },
  45. multipleSelect: {
  46. type: Boolean,
  47. default: false
  48. },
  49. type: {
  50. type: String,
  51. default: ''
  52. },
  53. appendToBody: {
  54. type: Boolean,
  55. default: false
  56. }
  57. },
  58. data() {
  59. return {
  60. filterText: '',
  61. treeData: [],
  62. defaultProps: {
  63. children: 'children',
  64. label: 'label',
  65. isLeaf: 'isLeaf',
  66. data: 'data'
  67. }
  68. };
  69. },
  70. watch: {
  71. filterText(val) {
  72. this.$refs._selectOrgTree.filter(val);
  73. }
  74. },
  75. computed: {
  76. visibleInChild: {
  77. get() {
  78. return this.visible;
  79. },
  80. set(val) {
  81. this.$emit('update:visible', val);
  82. }
  83. }
  84. },
  85. methods: {
  86. close() {
  87. this.visibleInChild = false;
  88. },
  89. filterNode(value, data) {
  90. if (!value) return true;
  91. return data.label.indexOf(value) !== -1;
  92. },
  93. getTreeData() {
  94. getAction('/sys/org/getSelectTreeData', { type: this.type }).then(
  95. (res) => {
  96. const { data } = res;
  97. this.treeData = data;
  98. }
  99. );
  100. },
  101. confirm() {
  102. if (this.multipleSelect) {
  103. let checkedNodes = this.$refs._selectOrgTree.getCheckedNodes();
  104. if (!checkedNodes || checkedNodes.length == 0) {
  105. Message.error('请先选择机构');
  106. return;
  107. }
  108. this.$emit('selectOrgFinished', checkedNodes);
  109. } else {
  110. let curNode = this.$refs._selectOrgTree.getCurrentNode();
  111. if (!curNode) {
  112. Message.error('请先选择机构');
  113. return;
  114. }
  115. this.$emit('selectOrgFinished', curNode);
  116. }
  117. this.visibleInChild = false;
  118. }
  119. }
  120. };
  121. </script>