dtree.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <div>
  3. <!-- <div class="head-container" style="margin-top: -7px"><el-input v-model="deptName" placeholder="请输入部门名称" clearable prefix-icon="el-icon-search" style="margin-bottom: 10px" /></div>
  4. <div class="head-container" style="height: calc(100vh - 203px); overflow-y: auto">
  5. <el-tree :data="deptOptions" :props="defaultProps" :current-node-key="value" :expand-on-click-node="false" :default-expanded-keys="idArr" :filter-node-method="filterNode" ref="tree" node-key="id" highlight-current @node-click="handleNodeClick" />
  6. </div> -->
  7. <el-cascader ref="cascader" v-model="value" :options="deptOptions" :props="{ value: 'id', label: 'label', checkStrictly: true }" :show-all-levels="false" @change="handleChange"></el-cascader>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. name: 'dtree',
  13. props: {
  14. value: {
  15. type: Number
  16. },
  17. dataTypeSelect: {
  18. type: Number,
  19. default: 1
  20. }
  21. },
  22. data() {
  23. return {
  24. loading: true,
  25. deptName: undefined,
  26. deptOptions: [],
  27. idArr: [],
  28. defaultProps: {
  29. children: 'children',
  30. label: 'label'
  31. }
  32. };
  33. },
  34. watch: {
  35. // 根据名称筛选部门树
  36. deptName(val) {
  37. this.$refs.tree.filter(val);
  38. }
  39. },
  40. mounted() {
  41. //部门列表
  42. this.ajax({ url: '/system/user/deptTree' }).then((response) => {
  43. this.deptOptions = response.data;
  44. });
  45. },
  46. methods: {
  47. // 筛选节点
  48. filterNode(value, data) {
  49. if (!value) return true;
  50. return data.label.indexOf(value) !== -1;
  51. },
  52. // 节点单击事件
  53. handleNodeClick(data) {
  54. this.$emit('input', data.id);
  55. this.$emit('handleQuery');
  56. },
  57. //选择
  58. handleChange(value) {
  59. if (value.length > 0) {
  60. this.$refs.cascader.dropDownVisible = false
  61. this.$emit('input', value[value.length - 1]);
  62. this.$emit('handleQuery');
  63. }
  64. }
  65. }
  66. };
  67. </script>