Ldc
2024-04-07 0652600959e5e3b5796fb6e8da129704ca95347a
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
/**
流程中转移负责人
**/
layui.define(['layer','table','form','tree','element'],function(exports){
    var Assign = function(){
        this.MODULENAME = "flowable/vciFlowableAssign";
        this.id = "vciFlowableAssign";
        this.moduleKey = "vciFlowableAssign";
        this.backPath = configData.compatibility ? path : configData.processServicePath ;
        this.taskOid = "";//任务的主键
        this.processTaskTitle = "";//任务的标题
        this.config = {};
        this.url = {
            treeDept:'departmentQueryController/refTree',
            dataGridMyDept:'userQueryController/refDataGridByCurrentDepartment',
            dataGridAllUser:'userQueryController/refDataGrid',//全部的用户
            dataGridThisTaskInTemplate:'workflowDefineController/listProcessUserByTask',//流程模板中定义的候选人
            dataGridSystemVar:'',//系统变量中的用户
            setAssign:'workflowCommandController/transferPrincipal'//转派
        };
    };
    Assign.prototype.getContent = function(){
        //兼容的方法,实际无内容
        return "";
    };
    Assign.prototype.init = function(id,options){
        //初始化
        var that = this;
        $webUtil.copyConfig(that,that.moduleKey);
        that.config[id] = options;
        if($webUtil.isNull(options.taskOid)){
            $webUtil.showErrorMsg("没有流程待办任务的主键");
            return false;
        }
        if($webUtil.isNull(options.processTaskTitle)){
            $webUtil.showErrorMsg("没有流程待办任务的名称");
            return false;
        }
        var tabId = "tab_user_for_task_" + id;
        options.tabId = tabId;
        var table = layui.table;
        var tree = layui.tree;
        var startAssign = layer.open({
            type:1,
            title:'为【' + options.processTaskTitle + '】任务设置处理人',
            btn:['确定','取消'],
            //skin:'layui-layer-lan',
            content:'<div lay-filter="' + tabId + '" class="layui-tab layui-tab-card" lay-allowClose="false">'+
                        '<ul class="layui-tab-title" lay-allowClose="false">' +
                            '<li lay-id="samedept_' + tabId + '" lay-unallowclose="true" class="layui-this">同部门用户</li>' +
                            '<li lay-id="alluser_' + tabId + '" lay-unallowclose="true" >所有的用户</li>' +
                            '<li lay-id="intemplate_' + tabId + '" lay-unallowclose="true" >本任务的流程模板中定义的候选人 </li>' +
//                            '<li lay-id="systemvar_' + tabId + '" lay-unallowclose="true">系统变量</li>' +
                        '</ul>' +
                        '<div class="layui-tab-content">' + 
                            '<div class="layui-tab-item layui-show">' +
                                '<div layui-filter="samedept_toolbar_' + tabId + '" class="layui-btn-container"></div>' + 
                                '<table id="samedept_table_' + tabId + '" lay-filter="alluser_table_' + tabId + '"></table>'+
                            '</div>' + 
                            '<div class="layui-tab-item">' +
                                '<div class="layui-vci-tree" style="width:250px;border-right:1px solid #ff;float: left;background-color:#ffffff;overflow-y: auto;">' +
                                    '<label class="layui-icon layui-icon-tree" style="line-height: 20px;color:red;font-size:20px;">部门</label>' +
                                    '<ul layui-filter="alluser_tree_' + tabId + '"><ul>' + 
                                '</div>' +
                                '<div style="display:block;margin-top:0px;margin-left:255px;">' + 
                                    '<div layui-filter="alluser_toolbar_' + tabId + '" class="layui-btn-container"></div>' + 
                                    '<table id="alluser_table_' + tabId + '" lay-filter="alluser_table_' + tabId + '"></table>'+
                                '</div>' + 
                            '</div>' +
                            '<div class="layui-tab-item">' + 
                                 '<ul layui-filter="intemplate_' + tabId + '"><ul>'+
                            '</div>' +
                            //目前暂时不添加系统变量,后续平台完善后,应该加上同岗位,同职务,同职级,直属领导,我的下属这些系统变量
//                            '<div class="layui-tab-item">' +
//                                '<div class="layui-vci-tree" style="width:200px;border-right:1px solid #ff;float: left;background-color:#ffffff;overflow-y: auto;">' +
//                                    '<label class="layui-icon layui-icon-tree" style="line-height: 20px;color:red;font-size:20px;">系统变量</label>' +
//                                    '<ul layui-filter="systemvar_tree_' + tabId + '"><ul>' + 
//                                '</div>' +
//                                '<div style="display:block;margin-top:0px;margin-left:205px;">' + 
//                                    '<div layui-filter="systemvar_toolbar_' + tabId + '" class="layui-btn-container"></div>' +
//                                    '<table id="systemvar_table_' + tabId + '" lay-filter="systemvar_table_' + tabId + '"></table>' + 
//                                '</div>' + 
//                            '</div>' +
                        '</div>' +
                    '</div>',
            area:[$webUtil.getDialogScreenWidth({width:900}) + 'px',$webUtil.getDialogScreenHeight({fullScreen:true}) + 'px'],
            closeBtn:1,
            shade:true,
            shadeClose:true,
            yes:function(index,layero){
                var userId = that.getSelectUser(id);
                if(!userId){
                    return false;
                }
                $webUtil.post(that.url.setAssign,{taskOid:options.taskOid,userId:userId},function(result){
                    if(result.success){
                        $webUtil.showMsgFromResult(result,"转派成功");
                         layer.close(startAssign);
                         if(that.okCallback){
                             that.okCallback();
                         }
                    }else{
                        $webUtil.showErrorMsg(result.msg);
                    }
                },function(xhr,err){
                    $webUtil.showErrorMsg("设置转移负责人出现了错误,您可以稍后再试");
                },that.backPath);
            },
            cancel:function(index,layero){
                 layer.close(startAssign);
            },
            success:function(layero) {
                //1.初始化选项卡
                //同部门的用户
                that.initSameDeptUser(id);
                //全部用户
                that.initAllUser(id);
                //模板中定义的候选人
                that.initTemplatUser(id);
                //系统变量的暂时不调用
                
                //监控选项卡点击,默认就是第一个选项卡
                options.selectTabIndex = 0;
                layui.element.on('tab(' + options.tabId + ')', function(data){
                    options.selectTabIndex = data.index;
                });
            }
        });
    };
    Assign.prototype.initSameDeptUser = function(id){
        var that = this;
        var options = that.config[id];
        //相同部门的用户
        var table = layui.table;
        table.render({
            elem:'#samedept_table_' + options.tabId,
            id:'samedept_table_' + options.tabId,
            url:configData.frameworkPath + that.url.dataGridMyDept,
            page:{
                limit:30,
                page:1
            },
            cols:[that.getUserColumns()]
        });
        $webUtil.createSearchHtml({
            name:'姓名',
            id:'用户账号(用户名)'
        },$('[layui-filter="samedept_toolbar_' + options.tabId + '"]'),'samedept_table_' + options.tabId);
    };
    Assign.prototype.initAllUser = function(id){
        var that = this;
        var options = that.config[id];
        var table = layui.table;
        var tree = layui.tree;
        //初始化全部用户的列表,使用部门展示
        var deptTreeUI = $('[layui-filter="alluser_tree_' +  options.tabId + '"]');
        tree.init("alluser_tree_" + options.tabId , deptTreeUI,{
            showSearch:true,
            url:that.url.treeDept,
            backPath:configData.frameworkPath,
            extraParams: {
                showAllDept:true
            },
            click: function (item, elem, options) {
                that.showUsersForDept(id,item.oid);
            }
        });
        //列表并行初始化,是因为第一个节点默认的就是全部用户
        table.render({
            elem:'#alluser_table_' + options.tabId,
            id:'alluser_table_' + options.tabId,
            url:configData.frameworkPath + that.url.dataGridAllUser,
            page:{
                limit:30,
                page:1
            },
            cols:[that.getUserColumns()]
        });
        $webUtil.createSearchHtml({
            name:'姓名',
            id:'用户账号(用户名)'
        },$('[layui-filter="alluser_toolbar_' + options.tabId + '"]'),'alluser_table_' + options.tabId);
    };
    Assign.prototype.showUsersForDept = function(id,deptOid){
        //根据部门显示用户
        var that = this;
        var table = layui.table;
        if(deptOid == "#ALLDEPT#"){
            deptOid  = "";
        }
        var options = that.config[id];
        table.reload('alluser_table_' + options.tabId ,{
            where:{
                "conditionMap['pkDepartment']":deptOid
            }
        });
    };
    Assign.prototype.initTemplatUser = function(id){
        var that = this;
        var options = that.config[id];
        var tree = layui.tree;
        //初始化流程模板中定义的用户
        $webUtil.get(that.url.dataGridThisTaskInTemplate,{taskOid:options.taskOid},function(result){
            if(result.success){
                var thisNodeUsers = result.obj.departments;
                if(thisNodeUsers){
                    layui.each(thisNodeUsers,function(_userIndex,_userItem){
                        if(_userItem.type == "role"){
                            _userItem.name = _userItem.name + "(角色)";
                        } else if(_userItem.type == "dept"){
                            _userItem.name = _userItem.name + "(部门)";
                        }
                        if(_userItem.secret && _userItem.secret*1>0 && _userItem.secretText){
                            _userItem.name += "[" + _userItem.secretText + "]";
                        }
                        if(!$webUtil.isNull(_userItem.id)){
                            _userItem.name = _userItem.id+' '+_userItem.name;
                        }
                        if(_userItem.children && _userItem.children.length > 0){
                            layui.each(_userItem.children,function(_childrenUserIndex,_childrenUserItem){
                                if(_childrenUserItem.secret && _childrenUserItem.secret*1>0 && _childrenUserItem.secretText){
                                    _childrenUserItem.name += "[" + _childrenUserItem.secretText + "]";
                                }
                                if(!$webUtil.isNull(_childrenUserItem.id)){
                                    _childrenUserItem.name = _childrenUserItem.id+' '+_childrenUserItem.name;
                                }
                            });
                        }
                    });
                }
                 var treeUL = $('[layui-filter="intemplate_' +options.tabId + '"]');
                 tree.init("tree_" + that.tabId, treeUL, {
                     nodes:thisNodeUsers,
                     showSearch:true,
                     onlyLeaf:false,//只能选择叶子节点
                     onlyLeafText:'请选择用户,不要选择角色和部门(树上的叶子节点才是用户类型)',
                     click: function (item, elem, options) {
                         that.config[id].selectTreeItem = item;
                     }
                 });
            }else{
                 $('[layui-filter="intemplate_' +options.tabId + '"]').html("获取流程模板中设置的候选人出错,但是您仍然可以使用其他方式选择用户");
            }
        },function(xhr,error){
             $('[layui-filter="intemplate_' +options.tabId + '"]').html("获取流程模板中设置的候选人出错,但是您仍然可以使用其他方式选择用户");
        },that.backPath,false);
    };
    Assign.prototype.initSystemVarUser = function(){
        var that = this;
        var table = layui.table;
        var tree = layui.tree;
         //系统变量--还未完成
        var systemTreeUI = $('[layui-filter="systemvar_tree_' + that.tabId + '"]');
        tree.init("systemvar_tree_" + that.tabId, systemTreeUI, {
            nodes:[{
                oid:'CURRENT',
                text:'相同部门下的用户',
                leaf:true
            },{
                oid:'CURREN',
                text:'相同角色下的用户',
                leaf:true
            },{
                oid:'CURREeNT',
                text:'我的主管领导',
                leaf:true
            }],
            click: function (item, elem, options) {
                that.showUsersForSystem(item.id);
            }
        });
        table.render({
            elem:'#systemvar_table_' + that.tabId,
            id:'systemvar_table_' + that.tabId,
            url:that.backPath + that.url.dataGridSystemVar,
            page:{
                limit:30,
                page:1
            },
            cols:[that.getUserColumns()]
        });
        $webUtil.createSearchHtml({
            name:'姓名',
            id:'用户账号(用户名)'
        },$('[layui-filter="systemvar_toolbar_' + that.tabId + '"]'),'systemvar_table_' + that.tabId);
    };
    Assign.prototype.getUserColumns = function(){
        //用户的展示列表
        var table = layui.table;
        return [table.getIndexColumn(),table.getCheckColumn(),{
            field:'id',
            title:'用户账号(用户名)',
            sort:true,
            width:170
        },{
            field:'name',
            title:'姓名',
            sort: true,
            width:150
        },{
            field:'secretGradeText',
            title:'密级',
            width:100,
            hidden:!configData.controllerSecret
        }];
    };
    Assign.prototype.getSelectUser = function(id){
        var that = this;
        var options = that.config[id];
        if(options.selectTabIndex == 0){
            //说明是第一个
            var userId = $webUtil.getOidFromGrid("samedept_table_" + options.tabId,true,true,'id');
            if(!userId){
                return false;
            }
            return userId;
        }else if(options.selectTabIndex == 1){
            var userId = $webUtil.getOidFromGrid("alluser_table_" + options.tabId,true,true,'id');
            if(!userId){
                return false;
            }
            return userId;
        }else{
            if(!options.selectTreeItem){
                //选择树的节点
                $webUtil.showErrorMsg("没有选择用户");
                return false;
            }
            if(!options.selectTreeItem.leaf && options.selectTreeItem.children && options.selectTreeItem.children.length>0){
                $webUtil.showErrorMsg("在【本任务的流程模板中定义的候选人】选项卡中只能选择用户");
                return false;
            }
            return options.selectTreeItem.id;
        }
    };
    var sp = new Assign();
    exports(sp.MODULENAME,sp);
});