1edeca30dfc82540b419466c6c0fd78c613a092e.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div style="overflow: hidden">
  3. <el-select v-model="treeLabel" placeholder="请选择" multiple collapse-tags>
  4. <el-option :value="opValue" class="filter-tree">
  5. <el-tree
  6. :data="data"
  7. check-strictly
  8. ref="treeCols"
  9. :props="defaultProps"
  10. :expand-on-click-node="false"
  11. node-key="adCode"
  12. default-expand-all
  13. :default-checked-keys="keyArr"
  14. lazy
  15. show-checkbox
  16. :load="loadAddvData"
  17. @check-change="handleCheckChange"></el-tree>
  18. </el-option>
  19. </el-select>
  20. </div>
  21. </template>
  22. <script>
  23. import { getAdXBaseData} from "../api/duChaAPI.js";
  24. export default {
  25. name:"addvSelectMul",
  26. props:[],
  27. components: {},
  28. data() {
  29. return {
  30. keyArr:[],
  31. mineStatus: [],
  32. opValue:"",
  33. treeLabel:[],
  34. treeValue:[],
  35. initTreeLoading:true,
  36. data: [],
  37. defaultProps:{
  38. children: 'children',
  39. label: 'adName',
  40. disabled: false,
  41. expandOnClickNode: false ,
  42. first:true,
  43. }
  44. };
  45. },
  46. //监听属性 类似于data概念
  47. computed: {
  48. organCode(){
  49. return localStorage.getItem('currentRlcode') ? localStorage.getItem('currentRlcode') : ''
  50. },
  51. organNm(){
  52. return localStorage.getItem('currentOrgNm') ? localStorage.getItem('currentOrgNm') : ''
  53. }
  54. },
  55. //监控data中的数据变化
  56. watch: {
  57. },
  58. //方法集合
  59. methods: {
  60. loadAddvData(node, resolve) {
  61. if(node.data.adGrad=="4"){
  62. resolve([]);
  63. return false;
  64. }
  65. if(!node.data.adCode){
  66. this.data = [{
  67. adCode: this.organCode,
  68. adFullName: this.organNm,
  69. adGrad: "1",
  70. adName: this.organNm,
  71. }];
  72. }else{
  73. getAdXBaseData(node.data.adCode).then((res)=>{
  74. if(res.data){
  75. resolve(res.data);
  76. }
  77. })
  78. }
  79. },
  80. setCheck(ids,nms){
  81. this.keyArr = ids;
  82. this.treeLabel = nms;
  83. },
  84. handleCheckChange(data, checked, node) {
  85. this.treeLabel = [];
  86. this.treeValue = [];
  87. this.$nextTick(()=>{
  88. let res = this.$refs.treeCols.getCheckedNodes(false, false); //这里两个true,1. 是否只是叶子节点 2. 是否包含半选节点(就是使得选择的时候不包含父节点)
  89. res.forEach(item => {
  90. this.treeLabel.push(item.adName);
  91. this.treeValue.push(item.adCode);
  92. });
  93. this.$refs.treeCols.setCheckedKeys(this.treeValue);
  94. this.$emit('changeAddv',{adNames:this.treeLabel.join(","),adCodes:this.treeValue.join(","),level:this.level})
  95. })
  96. }
  97. },
  98. //生命周期 - 创建完成(可以访问当前this实例)
  99. created() {
  100. },
  101. //生命周期 - 挂载完成(可以访问DOM元素)
  102. mounted() {
  103. },
  104. beforeCreate() {}, //生命周期 - 创建之前
  105. beforeMount() {}, //生命周期 - 挂载之前
  106. beforeUpdate() {}, //生命周期 - 更新之前
  107. updated() {}, //生命周期 - 更新之后
  108. beforeDestroy() {}, //生命周期 - 销毁之前
  109. destroyed() {}, //生命周期 - 销毁完成
  110. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  111. }
  112. </script>
  113. <style scoped>
  114. .filter-tree{
  115. height:auto;
  116. overflow-y:auto;
  117. max-height: 200px;
  118. padding: 0;
  119. background: white;
  120. }
  121. .el-select /deep/ .el-tag__close{
  122. display: none;
  123. }
  124. </style>