ludc
2023-10-24 92c558ebed31ac0aabdd5eb111912ae7efed54a2
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<template>
  <div class="app">
    <avue-tree ref="tree" v-model="CloneTreeAvueform" v-loading="loading" :data="Treedata" :defaultExpandAll="false" :option="Treeoption" @node-click="nodeClick" style="width: fit-content;">
      <template slot-scope="{ node }">
        <span style="display: inline-block;">{{ node.label }}</span>
      </template>
    </avue-tree>
  </div>
</template>
 
<script>
import {getTreeList} from "@/api/MasterData/master";
import {TableData, MasterTable} from "@/api/GetItem";
 
export default {
  name: "MasterTree",
  props: {
    pageSize: {
      type: String,
      default: "100"
    },
    currentPage: {
      type: String,
      default: "1"
    },
    templateOid: {
      type: String,
      default: ''
    },
  },
  data() {
    return {
      TreeValue:'',
      idData: '',
      masterVrBtnList: [],
      tableHeadFindData: [],
      tableHeadDataFateher: [],
      templateOids: "",
      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.getTreeLists()
  },
  computed: {},
  methods: {
    //获取数据
    getTreeLists() {
      const index = this.$route.query.id.indexOf('@');
      const result = this.$route.query.id.substring(0, index);
      this.idData = result
      // console.log(this.$route)
      getTreeList({'conditionMap[id]': this.idData}).then(res => {
        if(res){
          if(res.data.length === 0){
            this.$message.error("主数据分类查询为空!");
          }else{
            this.Treedata = res.data;
            const [firstProperty] = res.data;
            this.ModifyProperties(this.Treedata, 'text', 'label');
            this.codeClassifyOid = firstProperty.oid;
            this.coderuleoid = firstProperty.attributes.coderuleoid;
            this.$emit("coderuleoid", this.coderuleoid)
            this.$emit('Treedata', this.Treedata)
          }
        }
      }).catch(res => {
        // console.log(res)
        this.$message.error(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);
        }
      }
    },
    //表格刷新
    TableRend() {
      TableData({
        templateOid: this.templateOids,
        codeClassifyOid: this.nodeClickList.oid,
        page: this.currentPage,
        limit: this.pageSize,
      }).then(res => {
        this.tableDataArray = res.data.data;
        this.$emit('tableDataArray', this.tableDataArray)
        this.$emit('total', res.data.total)
      })
    },
    //表格头部
    TableHeadRend() {
      const index = this.$route.query.id.indexOf('@');
      const result = this.$route.query.id.substring(0, index);
      return new Promise((resolve, reject) => {
        MasterTable({
          codeClassifyOid: this.nodeClickList.oid,
          functionId: result,
        }).then(res => {
          const flagsToDeleteBtn = ["CODEIMPORTHISTORY", "CODEEXPORT", "CODEQUERY", "batchApplyCode"];
          //不同节点显示不同按钮
          if (!res.data.leaf) {
            this.masterVrBtnList = res.data.buttons.filter(obj => flagsToDeleteBtn.includes(obj.uniqueFlag));
          } else {
            this.masterVrBtnList = res.data.buttons
          }
          this.tableHeadDataFateher = res.data;
          this.templateOids = res.data.tableDefineVO.oid;
          const [List] = res.data.tableDefineVO.cols;
          List.forEach(item => {
            let columnItem = {
              label: item.title,
              prop: item.queryField,
              // type: this.columnType[item.type],
              sortable: item.sort,
              width: item.minWidth
            };
            this.tableHeadFindData.push(Object.assign(item, columnItem))
          })
          this.$emit('tableHeadDataFateher', this.tableHeadDataFateher);
          this.$emit('tableHeadFindData', this.tableHeadFindData);
          this.$emit('tableHeadBttoms', this.masterVrBtnList);
          resolve();
        }).catch(err => {
          reject(err)
        })
      })
    },
    //树点击事件
    async nodeClick(data) {
      try {
        // console.log(data)
        this.TreeValue=data.label.split(" ")[0].trim();
        // console.log('TreeValue',this.TreeValue)
        this.$emit('TreeValue',this.TreeValue)
        this.nodeClickList = data;
        this.tableHeadDataFateher = []
        this.tableHeadFindData = []
        await this.TableHeadRend(); // 先执行 TableHeadRend()
        this.TableRend(); // TableHeadRend() 方法完成后再执行 TableRend()
        this.$emit('nodeClick', this.templateOids)
        this.$emit("codeClassifyOid", this.nodeClickList.oid)
      } catch (error) {
        // 处理错误
        this.$message.error(error)
      }
    }
  }
}
</script>
 
<style lang="scss" scoped>
.app{
  overflow: auto;
  height: calc(100vh - 150px);
}
 .app::-webkit-scrollbar {
  height: 15px ; // 纵向滚动条 必写
  background: white;
  border: white;
  width: 10px;
 
}
// 滚动条的滑块
 .app::-webkit-scrollbar-thumb {
  background-color: #ececec;
  border-radius: 20px;
  border: #ececec;
}
</style>