648540858
2023-02-10 f2c6210539cfc5f423a773b4d897c37a9066f821
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
<template>
<div id="getCatalog" >
 
  <el-dialog title="选择要添加到的节点" v-if="showDialog"  width="50%" :append-to-body="true" :close-on-click-modal="false" :visible.sync="showDialog" :destroy-on-close="true" @close="close()" center>
    <div>
      <el-tree class="el-scrollbar"
               ref="tree"
               id="catalogTree"
               empty-text="未知节点"
               node-key="id"
               default-expand-all
               :highlight-current="false"
               :expand-on-click-node="false"
               :props="props"
               :load="loadNode"
               @node-click="nodeClickHandler"
               lazy>
       <span class="custom-tree-node" slot-scope="{ node, data }" style="width: 100%">
         <el-radio v-if="node.data.type === 0 || node.data.type === -1" style="margin-right: 0" v-model="chooseId" :label="node.data.id">{{''}}</el-radio>
         <span v-if="node.data.type === -1 && node.level === 1" style="font-size: 12px" class="iconfont icon-ziyuan"></span>
         <span v-if="node.data.type === 0 && node.level === 1" class="el-icon-s-home"></span>
         <span v-if="node.data.type === 0 && node.level > 1"  class="el-icon-folder-opened"></span>
         <span v-if="node.data.type === 1" class="iconfont icon-shexiangtou"></span>
         <span v-if="node.data.type === 2" class="iconfont icon-zhibo"></span>
        <span style=" padding-left: 1px">{{ node.label }}</span>
        <span>
          <i style="margin-left: 5rem; color: #9d9d9d; padding-right: 20px" v-if="node.data.id === defaultCatalogIdSign">默认</i>
        </span>
      </span>
      </el-tree>
    </div>
    <div style="float: right; height: 13rem">
      <el-button type="primary" size="mini" @click="submit()" >确认</el-button>
      <el-button @click="close()" size="mini">取消</el-button>
    </div>
  </el-dialog>
 
</div>
</template>
 
 
<script>
 
export default {
    name: 'getCatalog',
    beforeCreate(){
 
    },
    created() {
        this.chooseId = this.defaultCatalogId;
        this.defaultCatalogIdSign = this.defaultCatalogId;
        this.initData();
        setTimeout(()=>{
          if (this.catalogIdChange)this.catalogIdChange(this.defaultCatalogId);
        }, 100)
 
    },
    props: ['platformId'],
    data() {
        return {
          props: {
            label: 'name',
            children: 'children',
            isLeaf: 'leaf'
          },
          platformName: null,
          defaultCatalogId: null,
          catalogIdResult: null,
          showDialog: false,
          defaultCatalogIdSign: null,
          chooseNode: null,
          chooseId: "",
          catalogTree: null,
          contextmenuShow: false,
 
        };
    },
    methods: {
        openDialog(catalogIdResult) {
          console.log(this.chooseId)
          this.showDialog = true
          this.catalogIdResult = catalogIdResult
        },
        initData: function () {
            this.getCatalog();
        },
 
        getCatalog: function(parentId, callback) {
            let that = this;
            this.$axios({
                    method:"get",
                    url:`./api/platform/catalog`,
                    params: {
                        platformId: that.platformId,
                        parentId: parentId
                    }
                })
                .then((res)=> {
                  if (res.data.code === 0) {
                    if (typeof(callback) === 'function') {
                      callback(res.data.data)
                    }
                  }
                })
                .catch(function (error) {
                    console.log(error);
                });
 
        },
        loadNode: function(node, resolve){
          if (node.level === 0) {
            this.$axios({
              method:"get",
              url:`./api/platform/info/` + this.platformId,
            })
              .then((res)=> {
                if (res.data.code === 0) {
                  this.platformName = res.data.data.name;
                  this.defaultCatalogId = res.data.data.catalogId;
                  this.defaultCatalogIdSign = res.data.data.catalogId;
                  this.chooseId = res.data.data.catalogId;
                  resolve([
                   {
                      name: this.platformName,
                      id:   res.data.data.deviceGBId,
                      type:  0
                    }
                  ]);
                }
              })
              .catch(function (error) {
                console.log(error);
              });
          }
          if (node.level >= 1){
            this.getCatalog(node.data.id, resolve)
          }
        },
        nodeClickHandler: function (data, node, tree){
         this.chooseId = data.id;
        },
        close: function() {
          this.chooseId = null;
          this.showDialog = false;
        },
        submit: function() {
          console.log(this.chooseId)
          if (this.chooseId === null) {
            this.$message({
              showClose: true,
              message: '未选择任何节点,',
              type: 'warning'
            });
            return;
          }
          if (this.catalogIdResult)this.catalogIdResult(this.chooseId)
          this.showDialog = false;
        },
    }
};
</script>
 
<style>
#catalogTree{
  display: inline-block;
}
</style>