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
/**
 * 链接类型的添加
 * @author wangting
 * @date 2021-3-16
 */
layui.define(['layer','element','BaseAction'],function(exports){
    var webUtil = $webUtil;
    var Class = function() {
        this.MODELNAME = "BaseLinkAddAction";
        this.moduleKey = "BaseLinkAddAction";
 
        this.getContent = function (id) {
            var that = this;
            that.id = id;
            var html = [
                '<div class="addOrEdit" id="addOrEdit_', id, ' lay-filter="addOrEdit_', 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: 'uiDataController/linkAddSave',
                backPath: configData.compatibility ? path : configData.objectServicePath,
                method: 'post',
                uploadFileUrl: 'vciFileUploadController/uploadFile',
                uploadFileBackPath: configData.compatibility ? path : configData.fileServicePath,
                direction:false
            }
            $.extend(paramVOS, options.paramVOS);
            options.paramVOS = paramVOS;
 
            var 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;
            }
            if (!paramVOS['linktype']) {
                $webUtil.showErrorMsg("按钮配置无linktype");
                return false;
            }
            var selectData = options.dataStore;
 
            var table = layui.table;
            if (paramVOS.form) {
                var filter = "addOrEdit_" + options.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: paramVOS.title,
                    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.linktype,
                            id: paramVOS.form
                        }, function (result) {
                            if (result.success) {
                                var formCallback = function () {
                                    var initValues = form.getValues(filter,true);
                                    if (paramVOS.initvalue) {
                                        var urlobj = $webUtil.getUrlParams('?' + paramVOS.initvalue, {}, '#', ';');
                                        initValues = urlobj.params;
                                    }
                                    var treeInitKeyMap = {
                                        "f_oid":(paramVOS.foid||paramVOS.f_oid||options.sourceData.oid),
                                        "f_btwname":(paramVOS.fbtmname || paramVOS.f_btmname || paramVOS.f_btwname||options.sourceData.btmname),
                                        "t_oid":(paramVOS.toid || paramVOS.t_oid),
                                        "t_btwname":(paramVOS.tbtmname || paramVOS.t_btmname),
                                        "foid":(paramVOS.foid||paramVOS.f_oid||options.sourceData.oid),
                                        "fbtwname":(paramVOS.fbtmname || paramVOS.f_btmname || paramVOS.f_btwname||options.sourceData.btmname),
                                        "toid":(paramVOS.toid || paramVOS.t_oid),
                                        "tbtwname":(paramVOS.tbtmname || paramVOS.t_btmname)
                                    }
                                    for(var key in treeInitKeyMap){
                                        var value = treeInitKeyMap[key];
                                        if(value && $webUtil.isNotNull(value)){
                                            initValues[key] = $webUtil.replaceFreeMarker(value,selectData,options.sourceData);
                                        }
                                    }
                                    form.setValues(initValues,filter);
                                    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)
 
                                }
 
                                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)) {
                            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, id, selectData);
                                })
                            }
                            var formValues = form.getDefaultValues(filter, true,form.linkDefaultKeys);
                            if(formValues.otherValue.releaseFileOids){
                                formValues.otherValue.releaseFileOids=formValues.otherValue.releaseFileOids.split(',');
                            }
                            if (!formValues.defaultValues.linkType) {
                                formValues.defaultValues.linkType = paramVOS.linktype||paramVOS.type;
                            }
                            var datas = {
                                formDefineId: paramVOS.form,
                                preEvent: paramVOS.preevent,
                                afterEvent: paramVOS.afterevent,
                                beforeServerEvent: paramVOS.beforeserverevent,
                                afterServerEvent: paramVOS.afterserverevent,
                                releaseFileOids: formValues.otherValue.releaseFileOids||[],
                                data: formValues.otherValue
                            }
                            $.extend(datas, formValues.defaultValues,formValues.otherValue);
                            $webUtil.manualAjax(paramVOS.method, paramVOS.url, JSON.stringify(datas), function (result) {
                                if (result.success) {
                                    $webUtil.showMsgFromResult(result, 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);
                        }
                    },
                    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,
                        actionData: {
                            selectData: options.sourceData,
                            isOpen: true,
                            paramVOS: paramVOS
                        }
                    };
                    var filter = "addOrEdit_" + 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: paramVOS.title,
                        //skin: 'layui-layer-lan',
                        content: content.join(''),
                        shade: true,
                        shadeClose: true,
                        area: [$(window).width() - 100+'px', $(window).height() - 100+'px'],
                        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 = "addOrEdit_" + that.id;
            $('#' + filter).remove()
        };
    };
    var cs = new Class();
    exports(cs.MODELNAME,cs);
});