deptTree.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <div class="treebox">
  3. <el-tree show-checkbox ref="tree" @check-change="handleCheckChange" :data="treeList" node-key="o"
  4. :default-checked-keys="defaultListc" :default-expanded-keys="defaultList"></el-tree>
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. props: ["defaultList","type"],
  10. data() {
  11. return {
  12. treeList: [],
  13. opt: [],
  14. defaultProps: {
  15. children: 'children',
  16. label: 'label'
  17. },
  18. defaultListc:[]
  19. };
  20. },
  21. methods: {
  22. getTree(v) {
  23. this.$http({
  24. url: "/sysmgr/csysdept/queryAllList",
  25. method: "post",
  26. headers: {
  27. "Content-Type": "application/json",
  28. },
  29. data: {
  30. parentorgid: v
  31. },
  32. }).then((res) => {
  33. this.treeList = res.data;
  34. });
  35. },
  36. handleCheckChange(v) {
  37. let opt = [];
  38. let list = this.$refs.tree.getCheckedNodes();
  39. for (let i = 0; i < list.length; i++) {
  40. if(this.type == 1){
  41. opt.push({
  42. deptCode: list[i].o,
  43. deptName: list[i].ou
  44. })
  45. }else{
  46. opt.push({
  47. deptId: list[i].o,
  48. deptName: list[i].ou
  49. })
  50. }
  51. }
  52. this.$emit("treeCheck",opt)
  53. },
  54. },
  55. mounted() {},
  56. created() {
  57. this.getTree();
  58. this.defaultListc = this.defaultList;
  59. },
  60. watch:{
  61. type(){
  62. this.defaultListc = this.defaultList;
  63. }
  64. }
  65. };
  66. </script>
  67. <style scoped lang="scss">
  68. .treebox {
  69. border: 1px solid #ddd;
  70. }
  71. </style>