田源
2024-04-07 2ac55ce0edf4870a29691b56bfad59f4830a11a2
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
/**
 * Created by weidy on 2018/5/22
 * 流程代理
 */
layui.define(['layer','table','form'],function(exports){
    var WorkFlowProxy = function(){
        this.moduleKey = "vciWebProProxy";
        this.id = "vciWebProProxy_table";
        this.backPath = configData.compatibility ? path : configData.processServicePath;//默认流程和项目的路径是一样的
        this.userBackPath = path;//用户的后台路径,默认和项目路径是一样的
        this.url = {
            getProxy :'webProcessCommandController/getProxy',
            startProxy: 'webProcessCommandController/startProxy',
            endProxy:'webProcessCommandController/endProxy',
            referUser:'userQueryController/refDataGrid'//queryUserTree'
        };
        this.columns = [];
    };
    WorkFlowProxy.prototype.getContent = function(){//获取基础的html
        var that = this;
        return  ['<div layui-filter="toolbar_',that.id, '" class="layui-btn-container">',//主列表的按钮
            '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_startProxy"><i class="layui-icon layui-icon-logo"></i>添加代理</button>',
            '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_endProxy"><i class="layui-icon layui-icon-haoyouqingqiu"></i>停止代理</button>',
            '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_refresh"><i class="layui-icon layui-icon-refresh-2"></i>刷新</button>',
            '</div>',
            '<table id="table_', that.id , '" lay-filter="',that.id , '"></table>'].join("");//主列表
    };
    WorkFlowProxy.prototype.init = function(){//初始化
        var that = this;
        $webUtil.copyConfig(that,that.moduleKey);
        //显示表格信息
        that.checkColumns();
        var table =layui.table;
        table.render({
            elem: "#table_" + that.id,
            id: that.id,
            backPath:that.backPath,
            url:that.url.getProxy,
            height:150,
            cols:[that.columns],
            done:function(res,cur,count){
                that.proxyCount = count;
            }
        });
        that.bindButtonListener();
    };
    WorkFlowProxy.prototype.checkColumns=function(){
         var that = this;
         var table = layui.table;
         if(!that.columns || that.columns.length == 0){
             that.columns = [table.getIndexColumn(),{
                 field:'tasksName',
                 title:'代理人账号',
                 width:150
             },{
                 field:'userName',
                 title:'代理人',
                 width:220
             },{
                 field:'startTime',
                 title:'开始日期',
                 width:135
             },{
                 field:'endTime',
                 title:'结束日期',
                 width:135
             },{
                 field:'isTrue',
                 title:'启用状态',
                 width:150,
                 templet:function(d){
                     if(d.isTrue == 1){
                         return "启用";
                     }else{
                         return "停用";
                     }
                 }
             }]
         }
    };
    WorkFlowProxy.prototype.bindButtonListener=function(){
        var that =this;
        $("[layui-filter='toolbar_" + that.id + "_startProxy']").click(function(){
            if(that.proxyCount>0){
                $webUtil.showConfirmMsg("已经设置过代理人,只能设置一个代理人,继续操作将会覆盖原来的设置。是否继续?",function(){
                    that.showStartProxy();
                });
            }else{
                that.showStartProxy();
            }
        });
        $("[layui-filter='toolbar_" + that.id + "_refresh']").click(function(){
           that.refresh();
        });
        $("[layui-filter='toolbar_" + that.id + "_endProxy']").click(function(){
            that.endProxy();
        });
    };
    WorkFlowProxy.prototype.refresh = function(){
        var that =this;
        var table = layui.table;
        table.reload(that.id);
    };
    /**
     * 设置流程代理人窗口
     * 需要选择一个用户
     * 然后选择开始日期
     */
    WorkFlowProxy.prototype.showStartProxy = function(){
        var that = this;
        var formId = "start_process_proxy_form" ;
        var form = layui.form;
        var table = layui.table;
        var startProxyIndex = layer.open({
            type:1,
            title:'设置流程代理人',
            btn:['确定','取消'],
            skin:'layui-layer-lan',
            content:'<form id="' + formId + '" lay-filter="' + formId + '" class="layui-form" ></form>',
            area:[620 +'px', 300 + 'px'],
            closeBtn:2,
            shade:true,
            shadeClose:true,
            resize:true,
            resizing:function(layero){
                form.doResize();
            },
            yes:function(index,layero){
                if(form.validata(formId)){
                    //校验通过
                    var values = form.getValues(formId);
                    delete values.name;
                    $webUtil.post(that.url.startProxy,values,function(result){
                        if(result.success){
                            $webUtil.showMsg("设置流程代理人成功");
                            layer.close(startProxyIndex);
                            that.refresh();
                        }else{
                            $webUtil.showErrorMsg(result.msg);
                        }
                    },function(result){},that.backPath);
                }
            },
            btn2:function(index,layero){
                layer.close(startProxyIndex);
                that.refresh();
            },
            cancel:function(index,layero){
                that.refresh();
            },
            success:function(layero) {
                var formItems = [{
                    type: 'refer',
                    name: 'userId',
                    text: '流程代理人',
                    required: true,
                    labelWidth: 120,
                    textWidth: 400,
                    showField:'userName',
                    referConfig:{
                        type:'refer/SmUserRefer',
                        valueField:'id'
                    }
                }, {
                    type: 'date',
                    name: 'startTime',
                    text: '开始时间',
                    textWidth: 400,
                    required:true,
                    labelWidth: 120,
                    value:$webUtil.getSystemVar($webUtil.systemValueKey.currentDate),
                    min:$webUtil.getSystemVar($webUtil.systemValueKey.currentDate)
                },{
                    type:'date',
                    name:'endTime',
                    text:'结束时间',
                    textWidth:400,
                    required:true,
                    labelWidth:120,
                    min:$webUtil.getSystemVar($webUtil.systemValueKey.currentDate)
                }];
                form.addItems(formId,formItems,function() {
                    //form.setValues({
                    //startTime: $webUtil.getSystemVar($webUtil.systemValueKey.currentDate)
                    //});
                    form.on('select(' + formId + ')', function (data) {
                        if (data.name == 'startTime') {
                            var values = form.getValues(formId);
                            if (values.endTime <= data.value) {
                                form.setValues({endTime: ''}, formId);
                            }
                        } else if (data.name == 'endTime') {
                            var values = form.getValues(formId);
                            if (values.startTime >= data.value) {
                                form.setValues({startTime: ''}, formId);
                            }
                        }
                    })
                },{},{
                    defaultColumnOneRow:1,
                    inDialog:true
                });
            }
        });
    };
    /**
     * 停止代理,会将设置的代理的信息直接删除
     */
    WorkFlowProxy.prototype.endProxy =function(){
        var that =this;
        $webUtil.showConfirmMsg("是否停止代理流程",function(){
            $webUtil.post(that.url.endProxy,{},function(result){
                if(result.success){
                    $webUtil.showMsg("停止代理流程成功");
                    that.refresh();
                }else{
                    $webUtil.showErrorMsg(result.msg);
                }
            },function(result){},that.backPath);
        });
    };
 
    var sp = new WorkFlowProxy();
    exports("process/vciWebProProxy",sp);
});