田源
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
layui.define(['layer','table','vciWebComboxStore'],function(exports){
    /**
     * 数据表格--使用平台里的表单定义
     * weidy@2018-03-08
     */
    var VciDataGrid = function(){
            this.table = null;
            this.tableDefinedUrl='webUIController/getTableDefine';//默认的地址
            this.elemTableMap = {};//table元素绑定的表格主键
            this.elemFilterMap = {};//元素和filter映射
            this.tableConfigData = {};//从后台获取的的表格配置内容
            this.selectMode = null;
    };
    VciDataGrid.prototype.init = function(){
        var that = this;
        that.table = layui.table;
        if(that.selectMode == null){
            that.selectMode = that.table.selectMode.single;
        }
    };
    VciDataGrid.prototype.showGridByUrl = function(filter){//从后台获取表格信息
        var that = this;
        var config = that.getConfig(filter);
        var tableConfigData;
        var requestData = {};
        if(!config.extraParams && config.where){
            config.extraParams = config.where;
        }
        if(config.extraParams){
            for(var key in config.extraParams){
                requestData["conditionMap['" + key + "']"] = config.extraParams[key];
            }
        }
        var copyParam = ['btmType','tableCode'];//btmtype,表格所属类别-可以是业务类型,也可以链接类型,tableCode是表格的英文名称
        for(var i= 0 ; i < copyParam.length ; i ++){
            requestData[copyParam[i]] = config[copyParam[i]];
        }
        requestData['isMuti'] = $webUtil.getBoolean(config.isMuti);
        if(config && config.isLoaded && config.tableId == that.elemTableMap[config.elemId]){
            //说明加载过,而且该内容还在原处
            that.table.reload(config.tableId,{});
        }else{
            if(config.tableId != that.elemTableMap[config.elemId]){
                that.destroy(that.elemFilterMap[config.elemId]);//如果这个元素被其他的表格占用,则将原表格去掉
            }
            if($webUtil.isNotNull(config.tableCode) && $webUtil.isNotNull(config.btmType) && that.tableConfigData[config.tableCode + "_" + config.btmType]){
                //说明这个配置信息已经从后台获取过
                //可以定义表格了
                var tableConfigData = that.tableConfigData[config.tableCode + "_" + config.btmType] ;
                tableConfigData['filter'] = filter;
                tableConfigData['elem'] = config.elemId;
                tableConfigData['id'] = config.tableId;
                tableConfigData['url'] = ((config.url.indexOf('http:') == -1)?path +config.url :  config.url);
                tableConfigData['height'] =  config.height ? config.height : 475;
                tableConfigData['where'] = requestData;
                if($webUtil.getBoolean(config.isMuti) && "page" in tableConfigData){
                    delete tableConfigData.page;
                    // tableConfigData['page'] = {
                    //     limit: -1,
                    //     page: 1
                    // }
                }
                tableConfigData['done'] = function(res,cur,count){
                    if(config.done){
                        config.done(res,cur,count);
                    }
                };
                that.table.render(tableConfigData);
                that.elemTableMap[config.elemId] = config.tableId;
                that.elemFilterMap[config.elemId] = filter;
                config.isLoaded = true;
                that.setConfig(filter,config);
            }else{
 
                if($webUtil.isNotNull(config.tableCode) && $webUtil.isNotNull(config.btmType)) {
                    //说明是使用平台的表格
                    $webUtil.post($webUtil.isNotNull(config.tableDefinedUrl)?config.tableDefinedUrl:that.tableDefinedUrl, requestData, function (result) {
                        if (result.success) {
                            var queryScheme = result.querySchema;
                            if ($webUtil.isNotNull(queryScheme) && $webUtil.isNull(config.queryScheme)) {
                                config.queryScheme = queryScheme;
                            }
                            requestData['queryScheme'] = config.queryScheme;
                            requestData['btmType'] = config.btmType;
                            var cols = [];
                            if (result.showIndex) {
                                cols.push({field: 'LAY_TABLE_INDEX', type: 'numbers', title: '序号'});
                            }
                            if (result.showCheckbox) {
                                cols.push({field: 'LAY_CHECKED', type: 'checkbox'});
                            }
                            var referColumn = "";
                            if (result.columns) {
                                layui.each(result.columns, function (_index, record) {
                                    var col = record;
                                    if (col.field.indexOf(".") > -1) {
                                        referColumn += col.field + ",";
                                        var tempField = col.field;
                                        if(tempField.indexOf(".")>-1){
                                            tempField = tempField.substring(tempField.indexOf(".") + 1);
                                        }
                                        col.field = col.field.replace(".", "_");
                                        col.templet = function(d){
                                            return d[tempField];
                                        }
                                    }
                                    if ($webUtil.isNotNull(col.enumCode)) {
                                        //是枚举的内容
                                        var vciWebComboxStore = layui.vciWebComboxStore;
                                        vciWebComboxStore.newCombox(col.enumCode, {
                                            data: col.enumMap
                                        });
                                        col.templet = function (d, thisItem) {
                                            var vciWebComboxStore = layui.vciWebComboxStore;
                                            return vciWebComboxStore.getComboxText(thisItem.enumCode, d[thisItem.field]);
                                        };
                                    }
                                    cols.push(col);
                                });
                            }
                            requestData['referColumn'] = referColumn;
                            var pageObject = false;
                            if (result.limit > 0) {
                                pageObject = {
                                    limit: result.limit,
                                    page: 1
                                };
                            }
                            //可以定义表格了
                             tableConfigData = {
                                filter: filter,
                                elem: config.elemId,
                                id: config.tableId,
                                oid: config.old,//主键的字段,默认为oid
                                url: config.url,
                                page: pageObject,
                                selectMode:that.selectMode,
                                where: requestData,
                                done: function (res, cur, count) {
                                    if (config.done) {
                                        config.done(res, cur, count);
                                    }
                                },
                                cols: [cols]
                            };
                            if(config.height){
                                tableConfigData.height = config.height;
                            }
                            that.table.render(tableConfigData);
                            that.tableConfigData[config.tableCode + "_" + config.btmType] = tableConfigData;
                            that.elemTableMap[config.elemId] = config.tableId;
                            that.elemFilterMap[config.elemId] = filter;
                            config.isLoaded = true;
                            that.setConfig(filter, config);
                        } else {
                            $webUtil.showErrorMsg(result.msg);
                        }
                    });
                }
            }
        }
    };
    VciDataGrid.prototype.setConfig=function(filter,options){
        var that = this;
        if(!that.vciGridConfig){
            that.vciGridConfig = {};
        }
        that.vciGridConfig[filter] = options;
    };
    VciDataGrid.prototype.getConfig=function(filter){
        var that = this;
        if(!that.vciGridConfig){
            that.vciGridConfig = {};
        }
        if((filter) in that.vciGridConfig){
            return that.vciGridConfig[filter];
        }
    };
 
    VciDataGrid.prototype.doResize = function(filter){
        
    };
 
    VciDataGrid.prototype.destroy = function(filter){
        //销毁
        var that = this;
        var config = that.getConfig(filter);
        if(!config){
            return;
        }
        if(config && $(config.elemId)){
            $(config.elemId).remove();
        }
        if(!that.vciGridConfig){
            that.vciGridConfig = {};
        }
        if(that.elemFilterMap[config.elemId]){
            delete that.elemFilterMap[config.elemId];
        }
        if(that.elemTableMap[config.elemId]){
            delete that.elemTableMap[config.elemId];
        }
        if(that.tableConfigData[config.tableCode + "_" + config.btmType]){
            delete that.tableConfigData[config.tableCode + "_" + config.btmType];
        }
        if((filter) in that.vciGridConfig){
            delete that.vciGridConfig[filter];
        }
    };
    var dg = new VciDataGrid();
    exports('vciWebDataGrid',dg);
});