tom
2023-12-06 9e968679ed2e6937aeb7b50a6c450d5d19251f42
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>商务区域</title>
        <script src="../../../js/vue/vue.js"></script>
        <script src="../../../js/vue/element-ui/lib/index.js"></script>
        <script src="../../../js/myelement.js"></script>
        <script src="../../../js/vue/page.js"></script>
        <script src="../setting.js"></script>
        
        <link href="../../../js/vue/element-ui/lib/theme-chalk/index.css" rel="stylesheet">
        <link href="../../../css/myelement.css" rel="stylesheet">
        <link href="../../../css/iconfont.css" rel="stylesheet">
        <link href="../../../css/page.css" rel="stylesheet">
    </head>
    
    <body>
        <div id="vbody">
            <div id="page_root">
                <div style="width: 100%; height: 100%; padding: 20px; box-sizing: border-box;">
                    <div :style="{width: '61%', height: tableHeight2 + 50+'px', float: 'left', border: '1px solid #ccc'}">
                        <div v-if="treeData.length > 0" style="height: 50px; border-bottom: 1px solid #aaa;">
                            <div class="topbar" style="float: left; line-height: 50px;">
                                <span>{{title}}</span>
                                <template v-if="page.isVersionActive">
                                    <span class="versionNo">版本号: {{currentVersion.label}}</span>
                                    <h-select :datalist="versionList" v-on:itemselect="onVersionSelect"></h-select>                            
                                </template>
                            </div>
                            <div style="float: right; margin: 10px;">
                                <el-button-group>
                                    <el-button v-if="buttons.coverup" @click="onCoverup">封版</el-button>
                                    <el-button v-if="buttons.download" icon="el-icon-download" @click="onDownload" >导出</el-button>
                                    <el-upload action="https://jsonplaceholder.typicode.com/posts/" class="z_upload_" style="float: right;">
                                        <el-button v-if="buttons.upload" size="mini" type="primary" icon="el-icon-upload2" style="display: flex;">导入</el-button>
                                    </el-upload>
                                </el-button-group>
                                
                                <el-button-group style="margin-left: 3px; ">
                                    <el-button icon="el-icon-refresh" @click="onRefreshTree">刷新</el-button>
                                    <el-button v-if="buttons.append" :disabled="buttons.append.disabled" icon="el-icon-plus"  @click="onNewTreeRecord">添加</el-button>
                                    <el-button v-if="buttons.edit" :disabled="buttons.edit.disabled" @click="isEditTreeData = !isEditTreeData">{{isEditTreeData ? '取消编辑' : '在线编辑'}}</el-button>
                                </el-button-group>
                            </div>
                        </div>
                        <div style=" padding: 20px;">
                            <el-input
                              placeholder="输入搜索字"
                              v-model="filterText">
                            </el-input>
                        </div>
                        <div v-if="treeData.length > 0 && istree" :style="{height: tableHeight2 - 68 +'px', padding: '0px 20px 20px 20px', 'box-sizing': 'border-box'}">
                            <div :style="{height: tableHeight2 - 80  +'px', 'overflow-y': 'auto', 'font-size': '14px'}">
                                <el-tree ref="tree" :data="treeData" :props="defaultProps" node-key="id"
                                :filter-node-method="filterNode" :default-expanded-keys="defaultExpandedKeys"
                                highlight-current
                                @node-click="editnode"
                                >
                                    <span class="custom-tree-node" slot-scope="{ node, data }">
                                        <span>{{ node.label }}</span>
                                        <span v-if="isEditTreeData">
                                            <el-button type="danger" size="mini" style="padding: 2px; font-size: 10px;" 
                                            @click="() => remove(node, data)">删除</el-button>
                                        </span>
                                    </span>
                                </el-tree>
                            </div>
                        </div>
                    </div>
                    
                    <div v-if="istree" :style="{width: '38%', height: tableHeight2 + 50+'px', float: 'right', border: '1px solid #ccc'}">
                        <div style="height: 50px; border-bottom: 1px solid #aaa;">
                            <div class="topbar" style="float: left; line-height: 50px;">
                                <span>详情</span>
                            </div>
                            <div v-if="isEditTreeData" style="float: right; margin: 10px;">
                                <el-button @click="saveRowNoe">保 存</el-button>
                            </div>
                        </div>
                        <div style="margin: 20px;">
                            <h-form
                                ref="form2"
                                :form-attr="formNodeAttr"
                                :table-fields="treeFields"
                                :disabled="!isEditTreeData"
                                :form-data="formnodeData"
                            >
                            </h-form>
                        </div>
                    </div>
                </div>
            </div>
            
            <div id="page_loading" style="position: absolute; top:0px; width: 100vw; height: 100vh;">
                <div class="spinner">
                  <div class="cube1"></div>
                  <div class="cube2"></div>
                </div>
            </div>
        </div>    
        
        <script type="text/javascript">
            var setting = getSetting("area_tree");
            var initlized = false;
            let id = 1000;
            new ListVue({
                el: "#vbody",
                data: {
                    dataname: "biztarget",
                    tabaleFieldsName: "area_",
                    
                    title: "商务区域",
                    page: setting.page,
                    buttons: setting.buttons,
                    
                    currentVersion: {
                        value: "2021-3",
                        label: "2021-3"
                    },
                    versionList: [
                      {
                        value: "2021-3",
                        label: "2021-3"
                      }, 
                      {
                        value: "2021-2",
                        label: "2021-2"
                      },
                      {
                        value: "2021-1",
                        label: "2021-1"
                      }
                    ],
                    
                    tableHeight2: 450,
                    isEditData:false,
                    isEditTreeData: false,
                    
                    formNodeAttr: {
                        istitle: false,
                        title: "业务区域",
                        columnnumber: 1,
                        labelwidth: "100px",
                        labelposition: "right",
                        align: "left",
                        border: "10px solid #c6c6c600"
                    },
                
                    treeFields: [],
                    
                    istree: false,
                    treeDataObj: {},
                    treeData: [],
                    defaultExpandedKeys: [],
                    defaultProps: {
                        children: 'children',
                        label: 'label'
                    },
                    saleManor: [],
                    filterText: '',
                    formnodeData: {},
                },
                created() {
                    
                },
                
                mounted() {
                    this.initData();
                    this.getTree();
                    this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
                        hideLoading();
                    });
                },
                watch: {
                  filterText(val) {
                    this.$refs.tree.filter(val);
                  }
                },
                methods:{
                    initData() {
                        //1. run only
                        if (initlized) { return; }
                        initlized = true;
                    },
                    onServerInitData(data) {
                        var me = this.data;
                        me.treeFields = data.tableFields;
                        
                        if(me.tableFields.length > 0) {
                            for(var i=0; i < me.tableFields.length; i++) {
                                let fieldObj_ = me.tableFields[i];
                                
                                me.tableFieldsObj[fieldObj_.field] = fieldObj_;
                            }
                        }
                    },
                    getTree() {
                        let me = this;
                        let filter_ = "1=1";
                        this.filterList = [];
                        
                        let param_ = {
                            isClientMode: false,
                            dataname: this.dataname,
                            filterList: this.filterList,
                            filter: filter_,
                            orderby: this.orderby,
                        }
                        Server.call("root/data/getEntitySet", param_, function(result) {
                            console.log(result);
                            me.total = 0;
                            me.saleManor = [];
                            if (result && result.data) {
                                var data_ = result.data.entityset;
                                me.saleManor = data_;
                            }
                            me.defaultExpandedKeys = [];
                            me.istree = false;
                            let treeDataList = me.saleManor;
                            treeDataList.map(e=>{
                                me.treeDataObj[e.id] = e;
                            });
                            let treeData_ = me.ArrayToTree(treeDataList, "name", "parentid");
                            treeData_.map(e=>{
                                me.defaultExpandedKeys.push(e.id);
                                if (e.children) {
                                    e.children.map(ec=>{
                                        
                                    });
                                }
                            });
                            me.treeData = treeData_;
                            me.istree = true;
                        });
                    },
                    ArrayToTree(array_, name, parentId, parId, disabled_field, isencode) {
                        if(!parentId) {
                            parentId = "parent_id";
                        }
                        if(!name) {
                            name = "label";
                        }
                        if(!parId) {
                            parId = "";
                        }
                        
                        let obj = {};
                        let result = [];
                        let list = JSON.parse(JSON.stringify(array_));
                        list.map(el => {
                            obj[el.id] = el;
                        })
                        let openId = "";
                        for (let i = 0, len = list.length; i < len; i++) {
                            let parentId_ = list[i][parentId];
                            //如果存在判断只读字段,并且该字段有值则设置该节点为只读
                            if (disabled_field) {
                                if(list[i][disabled_field]) {
                                    list[i].disabled = true;
                                }
                            }
                            
                            //设置显示字段
                            if (isencode) {
                                list[i].label = decodeURI(encodeURI( list[i][name]));//数据如果带“%”的需要编码再解码,否则会存在格式错误
                                list[i].name = decodeURI(encodeURI( list[i][name]));
                            }
                            else {
                                list[i].label = decodeURI(list[i][name]);
                                list[i].name = decodeURI(list[i][name]);
                            }
                            if (parentId_ == parId || !parentId_ || parentId_ == "null") {
                                if(!obj[list[i].id].children) {
                                    obj[list[i].id].children = null;
                                }
                                result.push(list[i]);
                                continue;
                            } else if (obj[parentId_]) {
                                if (!obj[parentId_].children) {
                                    obj[parentId_].children = [];
                                }
                                obj[parentId_].children.push(list[i]);
                            }
                        }
                        return result;
                    },
                    editnode(data, node, tree) {
                        this.operationtype = "edit";
                        this.selectnode = data;
                        let formnodeData_ = clone(data);
                        var parentname_ = [];
                        if (data.parentid) {
                            let parents_ = [];
                            parentname_.push(data.parentid);
                            parents_ = this.getparent(data.parentid, parentname_);
                        }
                        this.formnodeData = formnodeData_; 
                    },
                    saveRowNoe() {
                        let me = this;
                        var formData_ = this.formnodeData;
                        var operationtype_ = this.operationtype;
                        
                        if (operationtype_ == "edit") {//修改
                            var paramObj = {};
                            for (var k in formData_) {
                                paramObj[k] = formData_[k];
                            }
                            var param = paramObj;
                            param.isClientMode = false;
                            Server.call("root/data/updateEntity/" + this.dataname, param, function(result) {
                                console.log(result);
                                me.getTree();
                            });
                        }
                    },
                    
                    onNewTreeRecord() {
                        //1.
                        this.operationtype = "add";
                        
                        //2. get config and go
                        var config = new Config(), go = true;
                        
                        if (this.onAddTreeData) {
                             go = this.onAddTreeData.call(this, config);
                        }
                        
                        //3. popup
                        if (go) {
                            this.doPopup(config);
                        }
                    },
                    onAddTreeData(config) {
                        var me = this;
                        config.combine({
                            url: "../md/plan/area_edit.html",
                            sceneCode: "add",
                            data: {},
                            delta:  me.treeFields ? me.treeFields : {},
                            callback: function(obj) {
                                me.saveRowTree_popup(obj);
                            }
                        });
                        
                        return true;
                    },
                    remove(node, data) {
                        let me = this;
                        Root.confirm('确定删除-' + data.name + '-吗?', '删除提示', {
                          confirmButtonText: '删除',
                          cancelButtonText: '取消',
                          type: 'warning'
                        }).then(() => {
                            let param = {
                                id: data.id,
                                isClientMode: false,
                            }
                            Server.call("root/data/deleteEntity/"+ this.dataname, param, function(result) {
                                console.log(result);
                                Root.message({
                                    type: 'success',
                                    message: '删除成功!'
                                });
                                me.getTree();
                            });
                        }).catch(() => {
                            Root.message({
                                type: 'info',
                                message: '已取消删除'
                            });          
                        });
                    },
                    saveRowTree_popup: function(obj) {
                        var me = this;
                        var formData_ = obj.row;
                        var operationtype_ = this.operationtype;
                        
                        if (operationtype_ == "add") {//修改
                            var param = formData_;
                            param.isClientMode = false;
                            Server.call("root/data/insertEntity/" + this.dataname, param, function(result) {
                                console.log(result);
                                me.getTree();
                            });
                        }
                    },
                    
                    onVersionSelect(obj) {
                        this.currentVersion = obj;
                    },
                    onDownload() {
                        dealExportByPath("../../../template/area_tree.xlsx","商务区域");
                    },
                    onCoverup() {
                        Root.confirm('确定封版为新2021-3吗?', '封版提示', {
                          confirmButtonText: "封版",
                          cancelButtonText: '取消',
                          type: 'warning'
                        }).then(() => {
                            Root.message({
                                type: 'success',
                                message: '封版成功!'
                            });
                        }).catch(() => {
                            Root.message({
                                type: 'info',
                                message: '已取消'
                            });          
                        });
                    },
                    onRefreshTree() {
                        this.getTree();
                    },
                    filterNode(value, data) {
                        if (!value) return true;
                        return data.label.indexOf(value) !== -1;
                    },
                    getparent(parentid, parents) {
                        if (this.treeDataObj[parentid].parentid){
                            parents.unshift(this.treeDataObj[parentid].parentid);
                            this.getparent(this.treeDataObj[parentid].parentid, parents);
                        }
                        else {
                            return parents;
                        }
                    },
                }
            });
        </script>
        <style>
            .el-dialog__body{
                border-top: 1px solid #ccc;
                border-bottom: 1px solid #ccc;
                padding: 20px;
            }
            .custom-tree-node {
                flex: 1;
                display: flex;
                align-items: center;
                justify-content: space-between;
                font-size: 14px;
                padding-right: 8px;
              }
        </style>
    </body>
</html>