田源
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
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
/**
 * 根据所选人创建评审任务
 * @author lihang
 * @date 2022-1-20
 */
layui.define(['layer','element','BaseAction'],function(exports){
    var webUtil = $webUtil;
    var Class = function() {
        this.MODELNAME = "CreateAuditTask";
        this.moduleKey = "CreateAuditTask";
        this.getContent = function (id, options) {
            var that = this;
            that.id = id;
            var html = [
                '<div class="CreateAuditTask" id="CreateAuditTask_', id, ' lay-filter="CreateAuditTask_', id, '" style="display:block; text-align: center"></div>'
            ].join("");
            return html;
        };
        this.doAction = function (options) {
            var that = this;
            webUtil.copyConfig(that, that.moduleKey);
            that.id = options.id;
            var paramVOS={
                url:'auditTaskController/create',
                backPath:configData.compatibility ? path : configData.objectServicePath,
                method:'post',
            }
            $.extend(paramVOS,options.paramVOS);
            options.paramVOS=paramVOS;
 
            baseAction = layui['BaseAction'];
            baseAction.callPreEvent(options, that, function (options) {
                that.doAdd(options, function () {
                    baseAction.callPostEvent(options, that, options.callback);
                });
            });
        };
 
        this.doAdd=function (options,callback){
            var that = this;
            var paramVOS=$webUtil.paramLow(options.paramVOS);
            if (!paramVOS['form'] && !paramVOS['context']&& !paramVOS['content']) {
                $webUtil.showErrorMsg("按钮配置不正确");
                return false;
            }
            that.id=options.id;
            var selectData=options.dataStore;
            if(selectData.length<1){
                $webUtil.showErrorMsg("请选择一条需要修改的数据");
                return false;
            }
            if(!paramVOS.multi && selectData.length > 1){
                $webUtil.showErrorMsg("仅能选择一条数据来操作");
                return false;
            }
            if (paramVOS.state && selectData[0].lcstatus != paramVOS.state){
                $webUtil.showErrorMsg("只有待评审状态的工艺评审才可创建任务");
                return false;
            }
            if (!paramVOS.state && selectData[0].lcstatus != 'Editing'){
                $webUtil.showErrorMsg("只有待评审状态的工艺评审才可创建任务");
                return false;
            }
            if(paramVOS.checknotoperation) {
                var checknotedit=baseAction.checkNotOperation(paramVOS,options);
                if (checknotedit) {
                    $webUtil.showErrorMsg($webUtil.replaceFreeMarker(paramVOS.checknotopermsg,options.dataStore,options.sourceData,options.navData) || '当前数据不允许修改');
                    return false;
                }
            }
            var table = layui.table;
            if (paramVOS.form) {
                var filter = "CreateAuditTask_" + that.id;
                var form = layui.form;
                var content = ['<form id="', filter, '" lay-filter="', filter, '" class="layui-form" style="margin:15px 30px 50px 0;" ></form>'
                ].join('');
                var addSaveIndex = layer.open({
                    type: 1,
                    title: $webUtil.replaceFreeMarker(paramVOS.title,options.dataStore,options.sourceData),
                    btn: ['保存', '取消'],
                    //skin: 'layui-layer-lan',
                    content: content,
                    //area: ['1860px', '200px'],
                    maxWidth: $(window).width() - 100,
                    maxHeight: $(window).height() - 100,
                    closeBtn: 1,
                    shade: true,
                    shadeClose: true,
                    resize: true,
                    resizing: function (layero) {
                        form.doResize(filter);
                    },
                    success: function (layero,layerIndex,classP) {
                        $webUtil.get('webUIController/getFormDefineById', {
                            btmType: paramVOS.type,
                            id: paramVOS.form
                        }, function (result) {
                            if (result.success) {
                                var formCallback = function () {
                                    var baseAction = layui['BaseAction'];
                                    if ($('#' + filter + ' .layui-upload-drag').length > 0) {
                                        baseAction.renderUploadFile('#' + filter + ' .layui-upload-drag', paramVOS)
                                    }
                                    if (paramVOS.uploadattachment && paramVOS.uploadattachment == 'true') {
                                        //显示上传附件
                                        baseAction.renderUploadAttach(filter, paramVOS)
                                    }
                                    if ($('#' + filter + ' .webeditor').length > 0) {
                                        //编辑器
                                        var editId='editor_'+$('#' + filter + ' .webeditor').attr('name')
                                        baseAction.renderEditor(editId,'',paramVOS,function (){
                                            baseAction.relocationOpen(classP)
                                        });
                                    }
                                    baseAction.relocationOpen(classP)
 
 
                                    //获取选中的数据
                                    var sourceDataMap = {};
                                    layui.each(options.sourceData, function (i, item) {
                                        if(item.constructor === Object) return;
                                        sourceDataMap['sourceData["' + i + '"]'] = item;
                                    })
                                    $webUtil.ajax(paramVOS.getdatamethod, paramVOS.getdataurl, $.extend({
                                            btmname: paramVOS.type,
                                            formDefineId: paramVOS.form,
                                            oid: selectData[0].oid
                                        }, sourceDataMap),
                                        function (result) {
                                            if (result.success) {
                                                form.setValues(result.obj.data, filter);
                                                //文件
                                                if (result.obj.filePathFieldMap) {
                                                    var filepath = layui.$('#' + filter + ' .uploadDemoView input.uploadFileOid').attr('name');
                                                    layui.$('#' + filter + ' .uploadDemoView').removeClass('layui-hide').find('img').attr('src', paramVOS.uploadfilebackpath + 'vciFileDownloadController/downloadByFileOid?fileOid=' + result.obj.filePathFieldMap[filepath].oid + '&' + TOKEN_KEY + '=' + $webUtil.getToken());
                                                    layui.$('#' + filter + ' .uploadDemoView input.uploadFileOid').val(result.obj.filePathFieldMap[filepath].filePath);
                                                }
                                                //附件
                                                if (result.obj.attachmentFileVOs && result.obj.attachmentFileVOs.length > 0) {
                                                    var val = [];
                                                    layui.each(result.obj.attachmentFileVOs, function (i, attachmentFile) {
                                                        val.push(attachmentFile.oid)
                                                    })
                                                    $('#' + filter + ' [name="releaseFileOids"]').val(val.join(','))
                                                }
                                                if ($('#' + filter + ' .webeditor').length > 0) {
                                                    //编辑器
                                                    var initV=result.obj.data[$('#' + filter + ' .webeditor').attr('name')];
                                                    editor.html(initV);
                                                    $('#' + filter + ' .webeditor').val(initV);
                                                }
 
                                            }
                                        }, function (xhr, error) {
                                            $webUtil.showErrorMsg("获取数据出现了错误,可能是文件服务没有启动");
                                        }, paramVOS.getdatabackpath)
 
                                }
 
                                form.addItems(filter, result.obj.items, formCallback, {}, {
                                    defaultColumnOneRow: result.obj.columnOneRow
                                });
                            } else {
                                $webUtil.showErrorMsg(result.msg||'获取表单失败');
                            }
 
                        }, function (xhr, error) {
                            $webUtil.showErrorMsg("获取表单出现了错误,可能是文件服务没有启动");
                        }, paramVOS.backpath)
                    },
                    yes: function (layero) {
                        if (form.validata(filter)) {
 
                            var saveFn = function () {
                                var formValues = form.getDefaultValues(filter, true);
                                if (formValues.otherValue.releaseFileOids) {
                                    formValues.otherValue.releaseFileOids = formValues.otherValue.releaseFileOids.split(',');
                                }
                                if (!formValues.defaultValues.btmname) {
                                    formValues.defaultValues.btmname = paramVOS.type;
                                }
                                var datas = {
                                    formDefineId: paramVOS.form,
                                    preEvent: paramVOS.prepvent,
                                    afterEvent: paramVOS.afterevent,
                                    beforeServerEvent: paramVOS.beforeserverevent,
                                    afterServerEvent: paramVOS.afterserverevent,
                                    releaseFileOids: formValues.otherValue.releaseFileOids || [],
                                    data: formValues.otherValue
                                }
                                $.extend(datas, formValues.defaultValues);
                                datas.data.processreviewoid = selectData[0].oid;
                                if(paramVOS.postsourcedata){
                                    datas['sourceData']=options.sourceData
                                }
                                if(paramVOS.postselectdata){
                                    datas['selectData']=options.dataStore
                                }
                                $webUtil.manualAjax(paramVOS.method, paramVOS.url, JSON.stringify(datas.data), function (result) {
                                    if (result.success) {
                                        $webUtil.showMsgFromResult(result, paramVOS.successMsg|| paramVOS.title + '成功');
                                        that.refresh();
                                        if (options.callback) {
                                            options.callback()
                                        }
                                        if (paramVOS.saveafterevent) {
                                            var urlobj = $webUtil.getUrlParams(paramVOS.saveafterevent);
                                            layui.use(urlobj.jsPath, function () {
                                                var pathAction = layui[urlobj.jsPath];
                                                var id = 'saveBeforeEvent_' + id;
                                                pathAction[urlobj.methodName](paramVOS, id, selectData);
                                            })
                                        }
                                        if(callback){
                                            callback()
                                        }
                                        layer.close(addSaveIndex);
                                    } else {
                                        $webUtil.showErrorMsg(result.msg || paramVOS.title + '失败');
                                    }
                                }, function (xhr, error) {
                                    $webUtil.showErrorMsg("访问服务器出现了错误,可能服务器没有开启,或者连接失败");
                                }, paramVOS.backpath);
                            }
 
                            if (paramVOS.savebeforeevent) {
                                var urlobj = $webUtil.getUrlParams(paramVOS.savebeforeevent);
                                layui.use(urlobj.jsPath, function () {
                                    var pathAction = layui[urlobj.jsPath];
                                    var id = 'saveBeforeEvent_' + id;
                                    pathAction[urlobj.methodName]({
                                        paramVOS: paramVOS,
                                        id: id,
                                        dataStore: selectData,
                                        sourceData:options.sourceData,
                                        callback: saveFn
                                    });
                                })
                            } else {
                                saveFn()
                            }
                        }
                    },
                    btn2: function (layero) {
                        layer.close(addSaveIndex)
                    }
                });
            } else if (paramVOS.context||paramVOS.content) {
                layui.use('platform/objectService/VciUIContentViewer', function () {
                    var newTabClass = layui['platform/objectService/VciUIContentViewer'];
                    newTabClass.id = that.id;
                    newTabClass.multiCompent = true;
                    newTabClass.sourceData = {
                        btmType: paramVOS.type,
                        content: paramVOS.context,
                        dataOid:options.dataStore[0].oid,
                        actionData: {
                            selectData: options.sourceData,
                            dataStore:options.dataStore,
                            navData:options.navData,
                            isOpen: true,
                            paramVOS: paramVOS
                        }
                    };
 
                    var filter = "CreateAuditTask_" + that.id;
                    var content = ['<div id="', filter, '" lay-filter="', filter, '" style="margin:5px;" >',newTabClass.getContent(that.id),'</div>']
                    var addSaveIndex = layer.open({
                        type: 1,
                        title: $webUtil.replaceFreeMarker(paramVOS.title,options.dataStore,options.sourceData),
                        //skin: 'layui-layer-lan',
                        content: content.join(''),
                        area: [$(window).width() - 100+'px', $(window).height() - 100+'px'],
                        shade: true,
                        shadeClose: true,
                        resize: true,
                        resizing: function (layero) {
                        },
                        success: function (layero,layerIndex,classP) {
                            newTabClass.init(that.id, newTabClass.sourceData,function (){
                                //layui['BaseAction'].relocationOpen(classP)
                            })
                        },
                        cancel: function (layero) {
                            if (options.callback) {
                                options.callback()
                            }
                        }
                    });
                });
            }
        }
 
        this.refresh = function () {
            var that = this;
 
        };
 
        this.destory = function () {
            var that = this;
            var filter = "CreateAuditTask_" + that.id;
            $('#'+filter).remove()
        };
    };
    var cs = new Class();
    exports(cs.MODELNAME,cs);
});