田源
2023-06-07 9412cc46c7d135d29dc6bf9b7ae36a3b6b17347c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<template>
  <avue-tree ref="tree" v-model="CloneTreeAvueform" v-loading="loading" :data="Treedata" :defaultExpandAll="false"
             :option="Treeoption"
             style="height: 80.5vh;padding-top: 5px;padding-bottom: 30px"
             @node-click=" nodeClick"
  ></avue-tree>
</template>
 
<script>
import {getTreeList} from "@/api/MasterData/master";
import {mapMutations, mapState} from "vuex";
import {TableData} from "@/api/GetItem";
 
export default {
  name: "MasterTree",
  props:{
    pageSize:{
      type:String,
      default:"10"
    },
    currentPage:{
      type:String,
      default:"1"
    },
    templateOid:{
      type:String,
      default:''
    },
  },
  data(){
    return{
      tableDataArray:[],
      codeClassifyOid:"",
      coderuleoid:"",
      CloneTreeAvueform:{},
      loading:false,
      Treedata:[],
      nodeClickList: "",
      Treeoption: {
        addBtn: false,
        editBtn: false,
        delBtn: false,
        defaultExpandAll: false,
        menu: false,
        lazy: true,
        // treeLoad:function (node,resolve){
        //   console.log(node)
        //   console.log(resolve)
        // }
        treeLoad:function (node, resolve){
          if(node.data != false){
            const parentId = (node.level === 0) ? 0 : node.data.oid;
            const parentBtmName = node.data.attributes.btmname
            getTreeList({parentOid:parentId,parentBtmName:parentBtmName}).then(res=>{
              resolve(res.data.map(item=>{
                return {
                  ...item,
                  label:item.text
                }
              }))
            })
          }
        },
      },
    }
  },
  created() {
    this.getTreeList()
 
  },
  computed:{
   },
  methods:{
    //获取数据
    getTreeList(){
      getTreeList({'conditionMap[id]': 'wupin'}).then(res=>{
        this.Treedata=res.data
        this.ModifyProperties(this.Treedata, 'text', 'label');
        this.codeClassifyOid=res.data[0].oid;
        this.coderuleoid=res.data[0].attributes.coderuleoid;
        this.$emit("codeClassifyOid", this.codeClassifyOid )
        this.$emit("coderuleoid", this.coderuleoid )
      }).catch(res=>{
        console.log(res)
      })
    },
 
    //定义一个修改数据属性名的方法
    ModifyProperties(obj, oldName, newName) {
      for (let key in obj) {
        if (key === oldName) {
          obj[newName] = obj[key];
          delete obj[key];
        }
        if (typeof obj[key] === 'object') {
          this.ModifyProperties(obj[key], oldName, newName);
        }
      }
    },
    //树点击事件
    nodeClick(data){
      this.nodeClickList = data;
      console.log(this.currentPage,this.pageSize)
      TableData({
        templateOid: this.templateOid,
        codeClassifyOid: this.codeClassifyOid,
        page: this.pageSize,
        limit:this.currentPage,
      }).then(res => {
        console.log(res)
        // this.page.total = res.data.total;
        // this.data = res.data.data;
        this.tableDataArray=res.data.data;
        this.$emit('tableDataArray',this.tableDataArray)
        console.log(this.tableDataArray)
      })
    }
  }
}
</script>
 
<style scoped>
 
</style>