1
lzhe
2024-10-10 d1b6cd8e5270b15546c94587fe2648453d525eee
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
<!--
 * @Author: lzhe lzhe@example.com
 * @Date: 2024-03-26 10:28:33
 * @LastEditors: lzhe lzhe@example.com
 * @LastEditTime: 2024-05-10 12:08:41
 * @FilePath: /smart-web/src/views/master/person/main/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div class="aposcope-main">
        <div class="aposcope-left">
            <div class="left-title">业务列表</div>
            <el-tree :data="tableData" node-key="id" default-expand-all :expand-on-click-node="false" :props="defalutProps" @node-click="handleNodeClick" ref="treeRef" highlight-current>
                 <template #default="{ node, data }">
                      <span>{{ node.label }}( {{ data.startCount }} )</span>
                  </template>
             </el-tree>
        </div>
        <div class="aposcope-right">
            <div class="right-top">
                业务描述:-
            </div>
            <div class="right-content">
                <div class="content-title">
                    <span class="ct-span">通知方式</span>
                    <el-icon @click="gojob"><Setting /></el-icon>
                </div>
                <el-row class="template-content-box">
                    <el-col :span="8" v-for="(item,index) in contentData">
                        <el-checkbox v-model="item.checked" label="选择" size="large" @change="checkboxChange($event,index,item)"/>
                        <div class="box-top">
                            <div class="box-top-name">{{item.notifyName}}</div>
                            <div class="box-top-title">{{item.notifyTemplateName}}</div>
                            <div class="box-top-btn">
                                <span @click="table_edit(item, index)"><el-icon><EditPen /></el-icon>编辑</span>
                                <span><el-icon><Delete /></el-icon>删除</span>
                            </div>
                        </div>
                    </el-col>
                </el-row>
                <div class="content-title">
                    <span class="ct-span">默认对象</span>
                </div>
                <div class="template-content-box">
                    <el-radio-group v-model="radio1" @change="radio1Change">
                        <el-radio :label="1">部门</el-radio>
                        <el-radio :label="2">员工</el-radio>
                    </el-radio-group>
                    <div class="content">
                        <el-button type="primary" plain @click="addOrganization" v-show="isaddOrganization">点击添加+</el-button>
                        <!-- 部门选择 -->
                        <span v-if="radio1 == 1" v-for="(item,index) in organizationLi" class="tagItem">{{item.name}}<el-icon @click="delOrganizationLi(index)" style="cursor: pointer;"><Close /></el-icon></span>
                        <el-select v-if="radio1 == 1" v-show="!isaddOrganization" v-model="organization" style="width: 20%" @change="organizationChange">
                            <el-option v-for="item in organizationList" :key="item.parentId" :label="item.name" :value="item.parentId"/>
                        </el-select>
                        <!-- 员工选择 -->
                        <span v-if="radio1 == 2" v-for="(item,index) in employeeLi" class="tagItem">{{item.name}}<el-icon @click="delEmployeeLi(index)" style="cursor: pointer;"><Close /></el-icon></span>
                        <el-select v-if="radio1 == 2" v-show="!isaddOrganization" v-model="employee" style="width: 20%" @change="employeeChange">
                            <el-option v-for="item in employeeList" :key="item.id" :label="item.organizationName + '-' + item.name" :value="item.id"/>
                        </el-select>
                    </div>
                    <div class="bottom-btn">
                        <el-button @click="resetData">重置</el-button>
                        <el-button type="primary" :loading="isSaveing" @click="saveSubmit">保存</el-button>
                    </div>
                 </div>
            </div>
        </div>
    </div>
    <save-dialog v-if="dialog.save" ref="saveDialog" @success="addbusinessSuccess" @closed="dialog.save=false"></save-dialog>
</template>
<script>
    import * as ElementPlusIconsVue from '@element-plus/icons-vue'
    let icons = []
    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
        icons.push(key)
    }
    import saveDialog from './editbusiness'
    export default {
        name: "business",
        data(){
            return {
                businessKey: "",
                isSaveing: false,
                employeeLi: [],
                organizationLi: [],
                isaddOrganization: true,
                organizationList: [],
                employeeList: [],
                organization: "",
                employee: "",
                radio1: 1,
                checked1: true,
                tableData: [],
                contentData: [],
                dialog: {
                    save: false
                },
                defalutProps: {
                    label: 'label',
                      children: 'children',
                    isLeaf: 'hasChildren',
                    disabled: 'disabled'
                },
                lastLevelId: "",
                current: "1",
                size: "15",
            }
        },
        created(){
            
        },
        mounted(){
            this.getTreeList();
            this.getgroupType();
            this.getEmployeeList();
        },
        components: {
            ...ElementPlusIconsVue,saveDialog
        },
        methods: {
            gojob() {
                window.open('http://116.63.148.72:8080/xxl-job-admin');
            },
            checkboxChange(e,index,item) {
                var obj = {
                    businessKey: item.businessKey,
                    notifyType: item.notifyType,
                    status: e?"1":"0"
                }
                this.$HTTP.put("/api/blade-notify/business-notify/changeStatus",obj).then(res=> {
                    if(res.code == 200) {
                        this.getbusiness();  //刷新列表
                    }
                })
            },
            saveSubmit() {
                var empIds = [];
                var orgIds = [];
                this.employeeLi.forEach(item=> {
                    empIds.push(item.id);
                })
                this.organizationLi.forEach(item=> {
                    orgIds.push(item.id);
                })
                var obj = {
                    businessKey: this.businessKey,empIds,orgIds
                }
                this.$HTTP.post("/api/blade-notify/business-notify",obj).then(res=> {
                    if(res.code == 200) {
                        this.$message.success("保存成功");
                    }
                })
            },
            resetData() {
                this.employeeLi = [];
                this.organizationLi = [];
            },
            radio1Change(val) {
                if(val == 1) {
                    this.getgroupType();
                }else if(val == 2) {
                    this.getEmployeeList();
                }
            },
            addOrganization() {
                this.isaddOrganization = false;
            },
            organizationChange(val) {
                var flag = this.organizationLi.some(function(item) {
                    return item.parentId === val;
                });
                this.organizationList.forEach(item=> {
                    if(item.parentId == val && !flag) {
                        this.organizationLi.push(item);
                    }
                })
            },
            employeeChange(val) {
                var flag = this.employeeLi.some(function(item) {
                    return item.id === val;
                });
                this.employeeList.forEach(item=> {
                    if(item.id == val && !flag) {
                        this.employeeLi.push(item);
                    }
                })
            },
            delOrganizationLi(index) {
                this.organizationLi.splice(index,1);
            },
            delEmployeeLi(index) {
                this.employeeLi.splice(index,1);
            },
            getgroupType() {
                this.$HTTP.get("/api/blade-cps/organization/list?groupType=group_organization&groupCategory=1").then(res=> {
                    if(res.code == 200) {
                        this.organizationList = res.data;
                    }
                })
            },
            getEmployeeList() {
                this.$HTTP.get("/api/blade-cps/employee/get/list?organizationCode=00001&status=1").then(res=> {
                    if(res.code == 200) {
                        this.employeeList = res.data;
                    }
                })
            },
            table_edit(row){
                if(row.notifyName == "钉钉") {
                    var url = `/api/blade-notify/notifier/template/dingTalk/dingTalkMessage/config/metadata`;
                }else if(row.notifyName == "企业微信") {
                    var url = `/api/blade-notify/notifier/template/weiXinQY/qyTextMessage/config/metadata`;
                }else if(row.notifyName == "站内信") {
                    var url = `/api/blade-notify/notifier/template/internalMessage/systemDefault/config/metadata`;
                }else if(row.notifyName == "邮件") {
                    var url = `/api/blade-notify/notifier/template/email/embedded/config/metadata`;
                }
                this.dialog.save = true
                this.$HTTP.get(url).then(res=> {
                    if(res.code == 200) {
                        this.dialog.save = true;
                        this.$nextTick(() => {
                            var obj = Object.assign(row,res.data);
                            this.$refs.saveDialog.open('edit').setData(obj);
                        })
                    }
                })
            },
            getbusiness() {
                this.$HTTP.get(`/api/blade-notify/business-notify?businessKey=${this.businessKey}`).then(res=> {
                    if(res.code == 200) {
                        res.data.businessNotifyDTOList.forEach(item=> {
                            item.checked = (item.status == '0'?false: true);
                        })
                        this.contentData = res.data.businessNotifyDTOList;
                        this.employeeLi = res.data.defaultObject.empList || []; //部门反显
                        this.organizationLi = res.data.defaultObject.orgList || []; //员工反显
                        if(this.organizationLi !=  null ) {
                            this.isaddOrganization = false;
                        }
                    }
                })
            },
            handleNodeClick(data) {
                if(data.businessKey) {
                    this.businessKey = data.businessKey;
                    this.getbusiness();
                }
            },
            getLastLevelIds(tree) {  
                if (tree.length === 0) return ""; // 如果没有根节点,返回空 
                const lastLevelIds = []; 
                const lastLevelCodes = [];
                function traverseTree(node) {  
                    if(!node.children) {
                        lastLevelCodes.push(node);
                    }
                    if (node.children) {  
                        node.children.forEach(traverseTree); // 递归遍历子节点  
                    } else {  
                        lastLevelIds.push(node.id);
                    }
                }      
                // 只遍历第一个根节点  
                traverseTree(tree[0]);  
                return {lastLevelCodes,lastLevelId:lastLevelIds[0]}; // 返回lastLevelCodes:没有code的数组。lastLevelId:有code的第一个id
            },
            getTreeList() {
                this.$HTTP.get("/api/blade-notify/business-notify/tree").then(res=> {
                    if(res.code == 200) {
                        this.tableData = res.data;
                        this.lastLevelId = this.getLastLevelIds(this.tableData).lastLevelId;
                        this.$nextTick(()=>{
                            this.$refs.treeRef.setCurrentKey(this.lastLevelId);  //第一个节点的第一个子节点最后一级默认选中
                        })
                        this.businessKey = this.getLastLevelIds(this.tableData).lastLevelCodes[0].businessKey;
                        this.getbusiness();
                    }
                })
            },
            // table_del(row) {
            //     this.$confirm(`确定将选择数据删除?`, '', {
            //         type: 'warning'
            //     }).then(() => {
            //         var arr = [row.id]
            //         this.$HTTP.delete("/api/blade-cps/workstation-wcs-feedback",arr).then(res=> {
            //             if(res.code == 200) {
            //                 this.$message.success("操作成功");
            //                 this.getlist();
            //             }
            //         })
            //     }).catch(() => {
 
            //     })
            // },
            addbusinessSuccess() {
                this.getbusiness();
            }
        }
    }
</script>
<style scoped>
.aposcope-main {
    display: flex;
    min-height: 100%;
    margin: 8px;
}
.aposcope-left {
    width: 240px;
    margin-right: 8px;
    padding: 4px;
    background-color: #fff;
}
.aposcope-right {
    flex: 1;
    padding: 8px;
    background-color: #fff;
}
.left-title {
    font-size: 16px;
    text-align: center;
    height: 38px;
    line-height: 38px;
    border-bottom: 1px solid #e2e2e2;
    background-color: #409eff;
    color: #fff;
    border-radius: 2px 2px 0 0;
}
.right-content {
    text-align: centefter;
}
.right-top {
    width: 100%;
    padding: 8px 16px;
    background-color: #409eff;
    color: #fff;
    font-size: 13px;
    line-height: 18px;
}
.content-title {
    display: flex;
    justify-content: space-between;
    margin: 24px 0 0 0;
    padding: 0 20px 0 10px;
    border-left: 6px solid #409eff;
}
.ct-span {
    color: #101010;
    font-size: 13px;
    font-weight: 700;
}
.content-title i {
    font-size: 20px;
    color: #409eff;
    cursor: pointer;
}
.template-content-box {
    padding: 12px 0px 24px 20px;
}
.box-top {
    height: 117px;
    border-radius: 2px;
    background: #fff;
    margin-right: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.16);
    position: relative;
}
.content {
    padding: 10px;
    border: 1px solid #409eff;
    width: 500px;
    height: 200px;
    overflow: auto;
}
.box-top-name {
    font-weight: 700;
    font-size: 18px;
    text-align: left;
    color: #333;
    display: block;
    margin-top: -30px;
    margin-left: 56px;
}
.box-top-title {
    font-size: 14px;
    text-align: left;
    color: #333;
    display: block;
    margin-top: -30px;
    margin-left: 56px;
    padding: 0 20px 0 33px;
    margin: 20px 0 10px 24px;
}
.box-top-btn {
    position: absolute;
    font-size: 14px;
    right: 12px;
    bottom: 12px;
    cursor: pointer;
}
.box-top-btn span:nth-child(1) {
    margin-right: 12px;
}
.tagItem {
    margin: 10px 10px 10px 0;
    background-color: #409eff;
    color: #fff;
    border-color: #409eff;
    display: inline-block;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 4px;
}
.bottom-btn {
    margin-top: 20px;
    text-align: center;
}
</style>