Statement.js 50.1 KB
Newer Older
U
unknown 已提交
1 2 3 4 5
MWF.xApplication.query = MWF.xApplication.query || {};
MWF.xApplication.query.Query = MWF.xApplication.query.Query || {};
MWF.xDesktop.requireApp("query.Query", "Viewer", null, false);
MWF.xApplication.query.Query.Statement = MWF.QStatement = new Class({
    Extends: MWF.QViewer,
U
unknown 已提交
6
    options: {
U
unknown 已提交
7
        "lazy": false,
U
unknown 已提交
8 9 10
        "moduleEvents": ["queryLoad", "postLoad", "postLoadPageData", "postLoadPage", "selectRow", "unselectRow",
            "queryLoadItemRow", "postLoadItemRow", "queryLoadCategoryRow", "postLoadCategoryRow", "export", "exportRow"]
    },
11
    initialize: function (container, json, options, app, parentMacro) {
U
unknown 已提交
12 13 14 15 16 17 18 19
        //本类有三种事件,
        //一种是通过 options 传进来的事件,包括 loadView、openDocument、select
        //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
        //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件

        this.setOptions(options);

        this.path = "../x_component_query_Query/$Viewer/";
20
        this.cssPath = "../x_component_query_Query/$Viewer/" + this.options.style + "/css.wcss";
U
unknown 已提交
21 22 23 24 25 26
        this._loadCss();
        this.lp = MWF.xApplication.query.Query.LP;

        this.app = app;

        this.container = $(container);
U
unknown 已提交
27

U
unknown 已提交
28
        this.json = json || {};
U
unknown 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42

        this.parentMacro = parentMacro;

        this.originalJson = Object.clone(json);

        this.viewJson = null;
        this.filterItems = [];
        this.searchStatus = "none"; //none, custom, default


        this.items = [];
        this.selectedItems = [];
        this.hideColumns = [];
        this.openColumns = [];
U
unknown 已提交
43
        this.parameter = {};
U
unknown 已提交
44 45 46

        this.gridJson = null;

47 48
        if (this.options.isload) {
            this.init(function () {
U
unknown 已提交
49 50 51 52 53
                this.load();
            }.bind(this));
        }

    },
54 55
    init: function (callback) {
        if (this.json.view) {
U
unknown 已提交
56
            this.viewJson = JSON.decode(this.json.view);
U
unknown 已提交
57
            this.statementJson = this.json;
U
unknown 已提交
58
            this.statementJson.viewJson = this.viewJson;
U
unknown 已提交
59
            if (callback) callback();
60
        } else {
U
unknown 已提交
61 62 63 64 65 66 67 68 69
            this.getView(callback);
        }
    },
    loadMacro: function (callback) {
        MWF.require("MWF.xScript.Macro", function () {
            this.Macro = new MWF.Macro.ViewContext(this);
            if (callback) callback();
        }.bind(this));
    },
70
    createActionbarNode: function () {
U
unknown 已提交
71
        this.actionbarAreaNode.empty();
72 73 74
        if (typeOf(this.json.showActionbar) === "boolean" && this.json.showActionbar !== true) return;
        if (typeOf(this.viewJson.actionbarHidden) === "boolean") {
            if (this.viewJson.actionbarHidden === true || !this.viewJson.actionbarList || !this.viewJson.actionbarList.length) return;
U
unknown 已提交
75 76 77 78
            this.actionbar = new MWF.xApplication.query.Query.Statement.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
            this.actionbar.load();
        }
    },
79
    _loadPageNode: function () {
U
unknown 已提交
80
        this.viewPageAreaNode.empty();
81
        if (!this.paging) {
U
unknown 已提交
82
            var json;
83
            if (!this.viewJson.pagingList || !this.viewJson.pagingList.length) {
U
unknown 已提交
84 85 86 87
                json = {
                    "firstPageText": this.lp.firstPage,
                    "lastPageText": this.lp.lastPage
                };
88
            } else {
U
unknown 已提交
89 90 91 92
                json = this.viewJson.pagingList[0];
            }
            this.paging = new MWF.xApplication.query.Query.Statement.Paging(this.viewPageAreaNode, json, this, {});
            this.paging.load();
93
        } else {
U
unknown 已提交
94 95 96
            this.paging.reload();
        }
    },
U
unknown 已提交
97 98 99 100 101 102
    // _initPage: function(){
    //     var i = this.count/this.json.pageSize;
    //     this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
    //     this.currentPage = this.options.defaultPage || 1;
    //     this.options.defaultPage = null;
    // },
103 104
    lookup: function (data, callback) {
        if (this.lookuping) return;
U
unknown 已提交
105
        this.lookuping = true;
U
unknown 已提交
106 107
        // this.getLookupAction(function(){
        //     if (this.json.application){
U
unknown 已提交
108

U
unknown 已提交
109
        var d = Object.clone( data || {} );
U
unknown 已提交
110 111 112
        // d.count = this.json.count;
        // this.lookupAction.bundleView(this.json.id, d, function(json){
        //     this.bundleItems = json.data.valueList;
U
unknown 已提交
113

U
unknown 已提交
114
        // this._initPage();
U
unknown 已提交
115

U
unknown 已提交
116
        debugger;
117 118
        this.loadParameter(d);
        this.loadFilter(d);
U
unknown 已提交
119 120 121 122

        this.currentPage = this.options.defaultPage || 1;
        this.options.defaultPage = null;

123 124
        if (this.noDataTextNode) this.noDataTextNode.destroy();
        this.loadCurrentPageData(function (json) {
U
unknown 已提交
125
            if (this.count || (json.data && json.data.length )) {
U
unknown 已提交
126 127
                this.fireEvent("postLoad"); //用户配置的事件
                this.lookuping = false;
128 129
                if (callback) callback(this);
            } else {
U
unknown 已提交
130
                this.viewPageAreaNode.empty();
131
                if (this.viewJson.noDataText) {
U
unknown 已提交
132
                    var noDataTextNodeStyle = this.css.noDataTextNode;
133
                    if (this.viewJson.viewStyles && this.viewJson.viewStyles["noDataTextNode"]) {
U
unknown 已提交
134 135
                        noDataTextNodeStyle = this.viewJson.viewStyles["noDataTextNode"];
                    }
136
                    this.noDataTextNode = new Element("div", {
U
unknown 已提交
137
                        "styles": noDataTextNodeStyle,
138 139
                        "text": this.viewJson.noDataText
                    }).inject(this.contentAreaNode);
U
unknown 已提交
140 141 142 143 144 145 146
                }
                // if (this.loadingAreaNode){
                //     this.loadingAreaNode.destroy();
                //     this.loadingAreaNode = null;
                // }
                this.fireEvent("postLoad"); //用户配置的事件
                this.lookuping = false;
147
                if (callback) callback(this);
U
unknown 已提交
148 149 150
            }


151
        }.bind(this), true, "all");
U
unknown 已提交
152 153

        // }.bind(this));
U
unknown 已提交
154 155 156
        // }
        // }.bind(this));
    },
157
    loadFilter: function (data) {
U
unknown 已提交
158
        debugger;
U
unknown 已提交
159
        this.filterList = [];
160
        (data.filterList || []).each(function (d) {
161 162 163 164 165 166 167
            var pName = d.path.replace(/\./g, "_");

            var parameterName = pName;
            var suffix = 1;
            while( this.parameter[parameterName] ){
                parameterName = pName + "_" + suffix;
                suffix++;
168
            }
169

U
unknown 已提交
170
            var value = d.value;
U
unknown 已提交
171 172 173
            // if( d.code && d.code.code ){
            //     value = this.Macro.exec( d.code.code, this);
            // }
174 175 176 177 178 179 180 181 182 183 184
            if (d.comparison === "like" || d.comparison === "notLike") {
                if (value.substr(0, 1) !== "%") value = "%" + value;
                if (value.substr(value.length - 1, 1) !== "%") value = value + "%";
                this.parameter[parameterName] = value; //"%"+value+"%";
            } else {
                if (d.formatType === "dateTimeValue" || d.formatType === "datetimeValue") {
                    value = "{ts '" + value + "'}"
                } else if (d.formatType === "dateValue") {
                    value = "{d '" + value + "'}"
                } else if (d.formatType === "timeValue") {
                    value = "{t '" + value + "'}"
U
unknown 已提交
185 186
                } else if (d.formatType === "numberValue"){
                    value = parseFloat(value);
U
unknown 已提交
187
                }
188
                this.parameter[parameterName] = value;
U
unknown 已提交
189 190 191
            }
            d.value = parameterName;

192 193
            if( !d.logic )d.logic = "and";

194
            this.filterList.push(d);
U
unknown 已提交
195 196
        }.bind(this))
    },
197
    loadParameter: function () {
U
unknown 已提交
198
        this.parameter = {};
U
unknown 已提交
199
        debugger;
U
unknown 已提交
200
        var parameter = this.json.parameter ? Object.clone(this.json.parameter) : {};
U
unknown 已提交
201
        //系统默认的参数
202
        (this.viewJson.parameterList || []).each(function (f) {
U
unknown 已提交
203
            var value = f.value;
204 205 206
            if (parameter && parameter[f.parameter]) {
                value = parameter[f.parameter];
                delete parameter[f.parameter];
U
unknown 已提交
207
            }
208
            if (typeOf(value) === "date") {
U
unknown 已提交
209 210
                value = value.format("db");
            }
211 212 213
            if (f.valueType === "script") {
                value = this.Macro.exec(f.valueScript ? f.valueScript.code : "", this);
            } else {
U
unknown 已提交
214
                var user = layout.user;
215
                switch (f.value) {
U
unknown 已提交
216
                    case "@person":
U
unknown 已提交
217
                        value = user.distinguishedName;
U
unknown 已提交
218 219
                        break;
                    case "@identityList":
220 221
                        value = user.identityList.map(function (d) {
                            return d.distinguishedName;
U
unknown 已提交
222
                        });
U
unknown 已提交
223 224
                        break;
                    case "@unitList":
225 226
                        o2.Actions.load("x_organization_assemble_express").UnitAction.listWithPerson({"personList": [user.distinguishedName]}, function (json) {
                            value = json.unitList;
U
unknown 已提交
227
                        }, null, false);
U
unknown 已提交
228 229
                        break;
                    case "@unitAllList":
230 231
                        o2.Actions.load("x_organization_assemble_express").UnitAction.listWithIdentitySupNested({"personList": [user.distinguishedName]}, function (json) {
                            value = json.unitList;
U
unknown 已提交
232
                        }, null, false);
U
unknown 已提交
233 234 235 236 237
                        break;
                    case "@year":
                        value = (new Date().getFullYear()).toString();
                        break;
                    case "@season":
U
unknown 已提交
238
                        var m = new Date().format("%m");
239
                        if (["01", "02", "03"].contains(m)) {
U
unknown 已提交
240
                            value = "1"
241
                        } else if (["04", "05", "06"].contains(m)) {
U
unknown 已提交
242
                            value = "2"
243
                        } else if (["07", "08", "09"].contains(m)) {
U
unknown 已提交
244
                            value = "3"
245
                        } else {
U
unknown 已提交
246 247
                            value = "4"
                        }
U
unknown 已提交
248 249 250 251 252 253 254 255
                        break;
                    case "@month":
                        value = new Date().format("%Y-%m");
                        break;
                    case "@time":
                        value = new Date().format("db");
                        break;
                    case "@date":
U
unknown 已提交
256
                        value = new Date().format("%Y-%m-%d");
U
unknown 已提交
257 258 259 260
                        break;
                    default:
                }
            }
261 262 263 264 265 266
            if (f.formatType === "dateTimeValue" || f.formatType === "datetimeValue") {
                value = "{ts '" + value + "'}"
            } else if (f.formatType === "dateValue") {
                value = "{d '" + value + "'}"
            } else if (f.formatType === "timeValue") {
                value = "{t '" + value + "'}"
U
unknown 已提交
267
            }
268
            this.parameter[f.parameter] = value;
U
unknown 已提交
269 270
        }.bind(this));
        //传入的参数
271
        for (var p in parameter) {
U
unknown 已提交
272
            var value = parameter[p];
273 274
            if (typeOf(value) === "date") {
                value = "{ts '" + value.format("db") + "'}"
U
unknown 已提交
275
            }
276
            this.parameter[p] = value;
U
unknown 已提交
277
        }
U
unknown 已提交
278
    },
279
    loadCurrentPageData: function (callback, async, type) {
U
unknown 已提交
280 281
        //是否需要在翻页的时候清空之前的items ?

U
unknown 已提交
282 283
        debugger;

284
        if (this.pageloading) return;
U
unknown 已提交
285 286
        this.pageloading = true;

U
unknown 已提交
287 288 289 290 291 292
        if( this.io ){
            this.items.each(function(item){
                this.io.unobserve(item.node);
            }.bind(this))
        }

U
unknown 已提交
293 294 295
        this.items = [];

        var p = this.currentPage;
U
unknown 已提交
296
        var d = {
297 298
            "filterList": this.filterList,
            "parameter": this.parameter
U
unknown 已提交
299
        };
U
unknown 已提交
300

301
        while (this.viewTable.rows.length > 1) {
U
unknown 已提交
302 303
            this.viewTable.deleteRow(-1);
        }
U
unknown 已提交
304 305 306 307 308 309
        if( this.viewTable.rows.length>0 && !this.viewTable.rows[0].hasClass("viewTitleLine") ){
            this.viewTable.deleteRow(0);
        }

        this.contentAreaNode.scrollTo(0, 0);

U
unknown 已提交
310 311
        //this.createLoadding();

U
unknown 已提交
312
        this.loadViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
U
unknown 已提交
313
            this.options.statementId || this.options.statementName || this.json.statementId || this.json.statementName,
314
            type || "data", p, this.json.pageSize, d, function (json) {
U
unknown 已提交
315

316 317
                if (type === "all" || type === "count") {
                    if (typeOf(json.count) === "number") {
U
unknown 已提交
318
                        this.count = json.count;
319 320
                        var i = this.count / this.json.pageSize;
                        this.pages = (i.toInt() < i) ? i.toInt() + 1 : i;
U
unknown 已提交
321 322 323 324
                    }
                }

                this.gridJson = json.data;
U
unknown 已提交
325
                this.setSelectedableFlag();
U
unknown 已提交
326

U
unknown 已提交
327
                this.fireEvent("postLoadPageData");
U
unknown 已提交
328

U
unknown 已提交
329 330 331 332
                // if (this.viewJson.group.column){
                //     this.gridJson = json.data.groupGrid;
                // }else{
                //     this.gridJson = json.data.grid;
U
unknown 已提交
333
                this.loadData();
U
unknown 已提交
334 335
                // }
                if (this.gridJson.length) this._loadPageNode();
336
                if (this.loadingAreaNode) {
U
unknown 已提交
337 338 339
                    this.loadingAreaNode.destroy();
                    this.loadingAreaNode = null;
                }
U
unknown 已提交
340

U
unknown 已提交
341
                this.pageloading = false;
U
unknown 已提交
342

U
unknown 已提交
343 344
                this.fireEvent("loadView"); //options 传入的事件
                this.fireEvent("postLoadPage");
U
unknown 已提交
345

346 347
                if (callback) callback(json);
            }.bind(this), null, async === false ? false : true);
U
unknown 已提交
348
    },
349 350
    getView: function (callback) {
        this.getViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.get(this.json.statementId || this.json.statementName, function (json) {
U
unknown 已提交
351
            debugger;
U
unknown 已提交
352
            var viewData = JSON.decode(json.data.view);
353
            if (!this.json.pageSize) this.json.pageSize = viewData.pageSize || "20";
U
unknown 已提交
354
            this.viewJson = viewData.data;
U
unknown 已提交
355 356 357
            this.json.application = json.data.query;
            //this.json = Object.merge(this.json, json.data);
            this.statementJson = json.data;
U
unknown 已提交
358
            this.statementJson.viewJson = this.viewJson;
U
unknown 已提交
359 360 361
            if (callback) callback();
        }.bind(this));
    },
U
unknown 已提交
362

363 364 365
    loadData: function () {
        if (this.getSelectFlag() === "multi" && this.viewJson.allowSelectAll) {
            if (this.selectTitleCell && this.selectTitleCell.retrieve("selectAllLoaded")) {
U
unknown 已提交
366
                this.setUnSelectAllStyle();
367
            } else {
U
unknown 已提交
368 369
                this.createSelectAllNode();
            }
370
        } else if (this.selectAllNode) {
U
unknown 已提交
371 372 373
            this.clearSelectAllStyle();
        }

374
        if (this.gridJson.length) {
U
unknown 已提交
375
            // if( !this.options.paging ){
376
            this.gridJson.each(function (line, i) {
U
unknown 已提交
377
                this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, line, null, i, null, this.options.lazy));
U
unknown 已提交
378 379 380 381
            }.bind(this));
            // }else{
            //     this.loadPaging();
            // }
382
        } else {
U
unknown 已提交
383 384 385
            if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
        }
    },
386 387 388 389 390
    loadDataByPaging: function () {
        if (this.isItemsLoading) return;
        if (!this.isItemsLoaded) {
            var from = Math.min(this.pageNumber * this.options.perPageCount, this.gridJson.length);
            var to = Math.min((this.pageNumber + 1) * this.options.perPageCount + 1, this.gridJson.length);
U
unknown 已提交
391
            this.isItemsLoading = true;
392
            for (var i = from; i < to; i++) {
U
unknown 已提交
393
                this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, this.gridJson[i], null, i, null, this.options.lazy));
U
unknown 已提交
394 395
            }
            this.isItemsLoading = false;
396 397
            this.pageNumber++;
            if (to == this.gridJson.length) this.isItemsLoaded = true;
U
unknown 已提交
398 399
        }
    },
400
    getFilter: function () {
U
unknown 已提交
401
        var filterData = [];
402 403 404
        if (this.searchStatus === "custom") {
            if (this.filterItems.length) {
                this.filterItems.each(function (filter) {
405
                    if( !filter.data.logic )filter.data.logic = "and";
U
unknown 已提交
406 407 408 409
                    filterData.push(filter.data);
                }.bind(this));
            }
        }
410
        if (this.searchStatus === "default") {
U
unknown 已提交
411
            var key = this.viewSearchInputNode.get("value");
412 413 414
            if (key && key !== this.lp.searchKeywork) {
                this.viewJson.customFilterList.each(function (entry) {
                    if (entry.formatType === "textValue") {
U
unknown 已提交
415 416 417 418
                        var d = {
                            "path": entry.path,
                            "value": key,
                            "formatType": entry.formatType,
U
unknown 已提交
419
                            "logic": "or",
U
unknown 已提交
420 421 422 423
                            "comparison": "like"
                        };
                        filterData.push(d);
                    }
424
                    if (entry.formatType === "numberValue") {
U
unknown 已提交
425
                        var v = key.toFloat();
426
                        if (!isNaN(v)) {
U
unknown 已提交
427 428 429 430
                            var d = {
                                "path": entry.path,
                                "value": v,
                                "formatType": entry.formatType,
U
unknown 已提交
431
                                "logic": "or",
U
unknown 已提交
432 433 434 435 436 437 438 439 440 441
                                "comparison": "like"
                            };
                            filterData.push(d);
                        }
                    }
                }.bind(this));
            }
        }
        return (filterData.length) ? filterData : null;
    },
442
    viewSearchCustomAddToFilter: function () {
U
unknown 已提交
443 444
        var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
        var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
445 446 447 448 449
        if (pathIdx === -1) {
            MWF.xDesktop.notice("error", {
                "x": "left",
                "y": "top"
            }, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
U
unknown 已提交
450 451
            return false;
        }
452 453 454 455 456
        if (comparisonIdx === -1) {
            MWF.xDesktop.notice("error", {
                "x": "left",
                "y": "top"
            }, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
U
unknown 已提交
457 458 459 460
            return false;
        }
        var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
        var entry = pathOption.retrieve("entry");
461
        if (entry) {
U
unknown 已提交
462 463 464 465 466 467
            var pathTitle = entry.title;
            var path = entry.path;
            var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
            var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
            var value = "";

468
            if (entry.valueType === "script" && entry.valueScript && entry.valueScript.code) {
U
unknown 已提交
469
                var idx = this.viewSearchCustomValueNode.selectedIndex;
470
                if (idx !== -1) {
U
unknown 已提交
471
                    var v = this.viewSearchCustomValueNode.options[idx].get("value");
472
                    value = entry.formatType === "booleanValue" ? (v === "true") : v;
U
unknown 已提交
473
                }
474 475
            } else {
                switch (entry.formatType) {
U
unknown 已提交
476 477 478 479 480 481 482 483
                    case "numberValue":
                        value = this.viewSearchCustomValueNode.get("value");
                        break;
                    case "dateTimeValue":
                        value = this.viewSearchCustomValueNode.get("value");
                        break;
                    case "booleanValue":
                        var idx = this.viewSearchCustomValueNode.selectedIndex;
484
                        if (idx !== -1) {
U
unknown 已提交
485
                            var v = this.viewSearchCustomValueNode.options[idx].get("value");
486
                            value = (v === "true");
U
unknown 已提交
487 488 489 490 491 492 493
                        }
                        break;
                    default:
                        value = this.viewSearchCustomValueNode.get("value");
                }
            }

494 495 496 497 498
            if (value === "") {
                MWF.xDesktop.notice("error", {
                    "x": "left",
                    "y": "top"
                }, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
U
unknown 已提交
499 500 501 502 503 504 505 506 507 508
                return false;
            }

            this.filterItems.push(new MWF.xApplication.query.Query.Statement.Filter(this, {
                "logic": "and",
                "path": path,
                "title": pathTitle,
                "comparison": comparison,
                "comparisonTitle": comparisonTitle,
                "value": value,
509
                "formatType": (entry.formatType == "datetimeValue") ? "dateTimeValue" : entry.formatType
U
unknown 已提交
510 511 512 513
            }, this.viewSearchCustomFilterContentNode));

            this.searchCustomView();
        }
U
unknown 已提交
514
    },
U
unknown 已提交
515
    //搜索相关结束
516
    getStatementInfor: function () {
U
unknown 已提交
517 518 519
        debugger;
        return this.statementJson;
    },
520
    getPageInfor: function () {
U
unknown 已提交
521
        return {
522 523 524
            pages: this.pages,
            perPageCount: this.json.pageSize,
            currentPageNumber: this.currentPage
U
unknown 已提交
525
        };
U
unknown 已提交
526
    },
527
    switchStatement: function (json) {
U
unknown 已提交
528
        this.switchView(json);
U
unknown 已提交
529
    },
530 531 532 533
    setFilter: function (filter, parameter, callback) {
        if (this.lookuping || this.pageloading) return;
        if (!filter) filter = [];
        if (!parameter) parameter = {};
U
unknown 已提交
534 535
        this.json.filter = filter;
        this.json.parameter = parameter;
536 537
        if (this.viewAreaNode) {
            this.createViewNode({"filterList": this.json.filter.clone()}, callback);
U
unknown 已提交
538
        }
U
unknown 已提交
539 540 541 542 543 544 545 546 547 548 549 550 551
    },


    // getExportTotalCount: function(){
    //     return this.count || 0;
    // },
    // getExportMaxCount: function(){
    //     return 2000;
    // },
    exportView: function(){

        // var excelName = this.statementJson.name + "(" + start + "-" + end + ").xlsx";

552
        var excelName = this.statementJson.name;
U
unknown 已提交
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568

        var p = this.currentPage;
        var d = {
            "filterList": this.filterList,
            "parameter": this.parameter
        };

        this.createLoadding();

        debugger;

        var exportArray = [];

        var titleArray = [];
        var colWidthArr = [];
        var dateIndexArray = [];
569
        var numberIndexArray = [];
U
unknown 已提交
570 571
        var idx = 0;
        Object.each(this.entries, function (c, k) {
U
unknown 已提交
572
            if (this.hideColumns.indexOf(k) === -1 && c.exportEnable !== false) {
U
unknown 已提交
573 574 575
                titleArray.push(c.displayName);
                colWidthArr.push(c.exportWidth || 200);
                if( c.isTime )dateIndexArray.push(idx);
576
                if( c.isNumber )numberIndexArray.push(idx);
U
unknown 已提交
577 578 579 580 581 582 583 584 585 586 587 588
                idx++;
            }
        }.bind(this));
        exportArray.push(titleArray);

        o2.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
            this.options.statementId || this.options.statementName || this.json.statementId || this.json.statementName,
            "data", 1, 100000, d, function (json) {

                json.data.each(function (d, i) {
                    var dataArray = [];
                    Object.each(this.entries, function (c, k) {
U
unknown 已提交
589
                        if (this.hideColumns.indexOf(k) === -1 && c.exportEnable !== false) {
U
unknown 已提交
590
                            var text = this.getExportText(c, k, d);
591 592 593
                            // if( c.isNumber && typeOf(text) === "string" && (parseFloat(text).toString() !== "NaN") ){
                            //     text = parseFloat(text);
                            // }
U
unknown 已提交
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
                            dataArray.push( text );
                        }
                    }.bind(this));
                    //exportRow事件
                    var argu = {"index":i, "source": d, "data":dataArray};
                    this.fireEvent("exportRow", [argu]);
                    exportArray.push( argu.data || dataArray );
                }.bind(this));

                //export事件
                var arg = {
                    data : exportArray,
                    colWidthArray : colWidthArr,
                    title : excelName
                };
                this.fireEvent("export", [arg]);

                if (this.loadingAreaNode) {
                    this.loadingAreaNode.destroy();
                    this.loadingAreaNode = null;
                }

                new MWF.xApplication.query.Query.Statement.ExcelUtils().exportToExcel(
                    arg.data || exportArray,
                    arg.title || excelName,
                    arg.colWidthArray || colWidthArr,
620 621
                    dateIndexArray,  //日期格式列下标
                    numberIndexArray  //数字格式列下标
U
unknown 已提交
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
                );

            }.bind(this));
    },
    getDataByPath: function (obj, path) {
        var pathList = path.split(".");
        for (var i = 0; i < pathList.length; i++) {
            var p = pathList[i];
            if ((/(^[1-9]\d*$)/.test(p))) p = p.toInt();
            if (obj[p]) {
                obj = obj[p];
            } else {
                obj = "";
                break;
            }
        }
        return obj
    },
    getExportText: function (c, k, data) {
        var path = c.path, code = c.code, obj = data;
        if (!path) {
            return ""
        } else if (path === "$all") {
        } else {
            obj = this.getDataByPath(obj, path);
        }

        try{
            if (code && code.trim()) obj = this.view.Macro.exec(code, {
                "value": obj,
                "data": data,
                "entry": c,
                "json": c
            });
        }catch (e) {}

        var toName = function (value) {
            if (typeOf(value) === "array") {
                Array.each(value, function (v, idx) {
                    value[idx] = toName(v)
                })
            } else if (typeOf(value) === "object") {
                Object.each(value, function (v, key) {
                    value[key] = toName(v);
                })
            } else if (typeOf(value) === "string") {
                value = o2.name.cn(value)
            }
            return value;
        };

        var d;
        if (obj != undefined && obj != null) {
            if (typeOf(obj) === "array") {
                d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
            } else if (typeOf(obj) === "object") {
                d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
            } else {
                d = c.isName ? o2.name.cn(obj.toString()) : obj;
            }
        }
        return d;
U
unknown 已提交
684
    }
U
unknown 已提交
685 686 687
});

MWF.xApplication.query.Query.Statement.Item = new Class({
688
    Extends: MWF.xApplication.query.Query.Viewer.Item,
U
unknown 已提交
689
    initialize: function (view, data, prev, i, category, lazy) {
U
unknown 已提交
690 691
        this.view = view;
        this.data = data;
692
        this.dataString = JSON.stringify(data);
U
unknown 已提交
693 694
        this.css = this.view.css;
        this.isSelected = false;
U
unknown 已提交
695
        this.category = category;
U
unknown 已提交
696 697 698
        this.prev = prev;
        this.idx = i;
        this.clazzType = "item";
U
unknown 已提交
699
        this.lazy = lazy;
U
unknown 已提交
700 701
        this.load();
    },
U
unknown 已提交
702 703 704 705
    _load: function () {
        this.loading = true;

        if(!this.node)this.view.fireEvent("queryLoadItemRow", [null, this]);
U
unknown 已提交
706 707

        var viewStyles = this.view.viewJson.viewStyles;
708
        var viewContentTdNode = (viewStyles && viewStyles["contentTd"]) ? viewStyles["contentTd"] : this.css.viewContentTdNode;
U
unknown 已提交
709

U
unknown 已提交
710
        if(!this.node)this.loadNode();
U
unknown 已提交
711 712

        //if (this.view.json.select==="single" || this.view.json.select==="multi"){
713
        this.selectTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
U
unknown 已提交
714 715
        this.selectTd.setStyles({"cursor": "pointer"});
        if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
U
unknown 已提交
716 717 718

        //var selectFlag = this.view.json.select || this.view.viewJson.select ||  "none";
        var selectFlag = this.view.getSelectFlag();
719
        if (this.data.$selectedEnable && ["multi", "single"].contains(selectFlag) && this.view.viewJson.selectBoxShow === "always") {
U
unknown 已提交
720 721 722 723 724 725 726 727 728 729 730 731 732 733
            var viewStyles = this.view.viewJson.viewStyles;
            if (viewStyles) {
                if (selectFlag === "single") {
                    this.selectTd.setStyles(viewStyles["radioNode"]);
                } else {
                    this.selectTd.setStyles(viewStyles["checkboxNode"]);
                }
            } else {
                var iconName = "checkbox";
                if (selectFlag === "single") iconName = "radiobox";
                this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/" + iconName + ".png) center center no-repeat"});
            }
        }

734
        if (this.view.isSelectTdHidden()) {
U
unknown 已提交
735 736 737 738 739
            this.selectTd.hide();
        }
        //}

        //序号
740
        if (this.view.viewJson.isSequence === "yes") {
U
unknown 已提交
741 742
            this.sequenceTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
            this.sequenceTd.setStyle("width", "10px");
743
            var s = 1 + this.view.json.pageSize * (this.view.currentPage - 1) + this.idx;
U
unknown 已提交
744 745 746 747 748
            this.sequenceTd.set("text", s);
        }

        debugger;

749
        Object.each(this.view.entries, function (c, k) {
U
unknown 已提交
750
            //if (cell){
751
            if (this.view.hideColumns.indexOf(k) === -1) {
U
unknown 已提交
752
                var td = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
U
unknown 已提交
753

754
                var cell = this.getText(c, k, td); //this.data[k];
U
unknown 已提交
755 756 757 758
                if (cell === undefined || cell === null) cell = "";

                // if (k!== this.view.viewJson.group.column){
                var v = cell;
759
                if (c.isHtml) {
U
unknown 已提交
760
                    td.set("html", v);
761
                } else {
U
unknown 已提交
762
                    td.set("text", v);
U
unknown 已提交
763 764
                }

765
                if (typeOf(c.contentProperties) === "object") td.setProperties(c.contentProperties);
U
unknown 已提交
766
                if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
767
                if (typeOf(c.contentStyles) === "object") td.setStyles(c.contentStyles);
U
unknown 已提交
768 769 770 771
                // }else{
                //     if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
                // }

772
                if (this.view.openColumns.indexOf(k) !== -1) {
U
unknown 已提交
773 774 775
                    this.setOpenWork(td, c)
                }

U
unknown 已提交
776
                // if (k!== this.view.viewJson.group.column){
777 778 779 780 781 782 783
                Object.each(c.events || {}, function (e, key) {
                    if (e.code) {
                        if (key === "loadContent") {
                            this.view.Macro.fire(e.code,
                                {"node": td, "json": c, "data": v, "view": this.view, "row": this});
                        } else if (key !== "loadTitle") {
                            td.addEvent(key, function (event) {
U
unknown 已提交
784 785
                                return this.view.Macro.fire(
                                    e.code,
786
                                    {"node": td, "json": c, "data": v, "view": this.view, "row": this},
U
unknown 已提交
787 788 789
                                    event
                                );
                            }.bind(this));
U
unknown 已提交
790
                        }
U
unknown 已提交
791 792 793
                    }
                }.bind(this));
                // }
U
unknown 已提交
794 795 796 797
            }
            //}
        }.bind(this));

U
unknown 已提交
798 799 800 801 802
        if(this.placeholderTd){
            this.placeholderTd.destroy();
            this.placeholderTd = null;
        }

U
unknown 已提交
803
        //默认选中
804 805
        var selectedFlag;

U
unknown 已提交
806
        var defaultSelectedScript = this.view.json.defaultSelectedScript || this.view.viewJson.defaultSelectedScript;
807
        if (!this.isSelected && defaultSelectedScript) {
U
unknown 已提交
808 809 810 811
            // var flag = this.view.json.select || this.view.viewJson.select ||  "none";
            // if ( flag ==="single" || flag==="multi"){
            //
            // }
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
            selectedFlag = this.view.Macro.exec(defaultSelectedScript,
                {"node": this.node, "data": this.data, "view": this.view, "row": this});
        }

        //判断是不是在selectedItems中,用户手工选择
        if (!this.isSelected && this.view.selectedItems.length) {
            for (var i = 0; i < this.view.selectedItems.length; i++) {
                if (this.view.selectedItems[i].dataString === this.dataString) {
                    selectedFlag = "true";
                    break;
                }
            }
        }

        if (selectedFlag) {
            if (selectedFlag === "multi" || selectedFlag === "single") {
                this.select(selectedFlag);
            } else if (selectedFlag.toString() === "true") {
                var f = this.view.json.select || this.view.viewJson.select || "none";
                if (f === "single" || f === "multi") {
                    this.select();
U
unknown 已提交
833 834 835 836 837 838 839
                }
            }
        }

        this.setEvent();

        this.view.fireEvent("postLoadItemRow", [null, this]);
U
unknown 已提交
840 841 842

        this.loading = false;
        this.loaded = true;
U
unknown 已提交
843
    },
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
    selected: function( from ){
        for(var i=0; i<this.view.selectedItems.length; i++){
            var item = this.view.selectedItems[i];
            if( item.dataString === this.dataString ){
                this.view.selectedItems.erase(item);
                break;
            }
        }
        this.view.selectedItems.push(this);
        var viewStyles = this.view.viewJson.viewStyles;
        if( viewStyles ){
            this.selectTd.setStyles( viewStyles["checkedCheckboxNode"] );
            this.node.setStyles( viewStyles["contentSelectedTr"] );
        }else{
            this.selectTd.setStyles({"background": "url("+"../x_component_query_Query/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
            this.node.setStyles(this.css.viewContentTrNode_selected);
        }
        this.isSelected = true;
        if( from !== "view" && from !=="category" && this.view.viewJson.allowSelectAll ){
            this.view.checkSelectAllStatus();
            if( this.category )this.category.checkSelectAllStatus();
        }
        this.view.fireEvent("selectRow", [this]);
    },
    unSelected: function( from ){
        for(var i=0; i<this.view.selectedItems.length; i++){
            var item = this.view.selectedItems[i];
            if( item.dataString === this.dataString ){
                this.view.selectedItems.erase(item);
                break;
            }
        }
        var viewStyles = this.view.viewJson.viewStyles;
        if( this.view.viewJson.selectBoxShow !=="always" ){
            this.selectTd.setStyles({"background": "transparent"});
        }else{
            if (viewStyles) {
                this.selectTd.setStyles(viewStyles["checkboxNode"]);
            }else{
                this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/checkbox.png) center center no-repeat"});
            }
        }
        if( viewStyles ){
            this.node.setStyles( viewStyles["contentTr"] );
        }else{
            this.node.setStyles(this.css.viewContentTrNode);
        }
        this.isSelected = false;
        if( from !== "view" && from !=="category" && this.view.viewJson.allowSelectAll ){
            this.view.checkSelectAllStatus();
            if( this.category )this.category.checkSelectAllStatus();
        }
        this.view.fireEvent("unselectRow", [this]);
    },
    getDataByPath: function (obj, path) {
U
unknown 已提交
899 900 901 902 903 904 905 906 907 908 909 910 911
        var pathList = path.split(".");
        for (var i = 0; i < pathList.length; i++) {
            var p = pathList[i];
            if ((/(^[1-9]\d*$)/.test(p))) p = p.toInt();
            if (obj[p]) {
                obj = obj[p];
            } else {
                obj = "";
                break;
            }
        }
        return obj
    },
912
    getText: function (c, k, td) {
U
unknown 已提交
913
        var path = c.path, code = c.code, obj = this.data;
914
        if (!path) {
915 916 917
           var co = code && code.trim();
           if( !co )return "";
           obj = "";
918 919
        } else if (path === "$all") {
        } else {
U
unknown 已提交
920
            obj = this.getDataByPath(obj, path);
U
unknown 已提交
921 922
        }

923 924 925 926 927 928 929 930
        if (code && code.trim()) obj = this.view.Macro.exec(code, {
            "value": obj,
            "data": this.data,
            "entry": c,
            "node": td,
            "json": c,
            "row": this
        });
U
unknown 已提交
931 932

        var toName = function (value) {
933 934
            if (typeOf(value) === "array") {
                Array.each(value, function (v, idx) {
U
unknown 已提交
935 936
                    value[idx] = toName(v)
                })
937 938
            } else if (typeOf(value) === "object") {
                Object.each(value, function (v, key) {
U
unknown 已提交
939 940
                    value[key] = toName(v);
                })
941 942
            } else if (typeOf(value) === "string") {
                value = o2.name.cn(value)
U
unknown 已提交
943 944 945 946 947
            }
            return value;
        };

        var d;
948 949
        if (obj != undefined && obj != null) {
            if (typeOf(obj) === "array") {
U
unknown 已提交
950
                d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
951
            } else if (typeOf(obj) === "object") {
U
unknown 已提交
952
                d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
953 954
            } else {
                d = c.isName ? o2.name.cn(obj.toString()) : obj;
U
unknown 已提交
955 956 957 958 959
            }
        }

        return d;
    },
960
    setOpenWork: function (td, column) {
U
unknown 已提交
961
        td.setStyle("cursor", "pointer");
962 963
        if (column.clickCode) {
            if (!this.view.Macro) {
U
unknown 已提交
964 965
                MWF.require("MWF.xScript.Macro", function () {
                    this.view.businessData = {};
966
                    this.view.Macro = new MWF.Macro.ViewContext(this.view);
U
unknown 已提交
967 968
                }.bind(this), false);
            }
969
            td.addEvent("click", function (ev) {
U
unknown 已提交
970 971 972 973
                var result = this.view.Macro.fire(column.clickCode, this, ev);
                ev.stopPropagation();
                return result;
            }.bind(this));
974 975 976 977 978
        } else if (this.view.statementJson.entityCategory === "official" && column.idPath) {
            var id = this.getDataByPath(this.data, column.idPath);
            if (id) {
                if (this.view.statementJson.entityClassName === "com.x.cms.core.entity.Document") {
                    td.addEvent("click", function (ev) {
U
unknown 已提交
979 980 981
                        this.openCms(ev, id);
                        ev.stopPropagation();
                    }.bind(this));
982 983
                } else {
                    td.addEvent("click", function (ev) {
U
unknown 已提交
984 985 986 987 988
                        this.openWork(ev, id);
                        ev.stopPropagation();
                    }.bind(this));
                }
            }
U
unknown 已提交
989
        }
U
unknown 已提交
990
    },
991
    openCms: function (e, id) {
U
unknown 已提交
992 993 994 995
        var options = {"documentId": id};
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
        layout.desktop.openApplication(e, "cms.Document", options);
    },
996
    openWork: function (e, id) {
U
unknown 已提交
997 998 999
        var options = {"workId": id};
        this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
        layout.desktop.openApplication(e, "process.Work", options);
U
unknown 已提交
1000 1001 1002 1003
    }
});

MWF.xApplication.query.Query.Statement.Filter = new Class({
1004
    Extends: MWF.xApplication.query.Query.Viewer.Filter
U
unknown 已提交
1005 1006 1007
});

MWF.xApplication.query.Query.Statement.Actionbar = new Class({
1008
    Extends: MWF.xApplication.query.Query.Viewer.Actionbar
U
unknown 已提交
1009 1010 1011
});

MWF.xApplication.query.Query.Statement.Paging = new Class({
1012
    Extends: MWF.xApplication.query.Query.Viewer.Paging
U
unknown 已提交
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
});


MWF.xApplication.query.Query.Statement.ExcelUtils = new Class({
    initialize: function(){
        // this.datatemplate = datatemplate;
        // this.form = datatemplate.form;
        if (!FileReader.prototype.readAsBinaryString) {
            FileReader.prototype.readAsBinaryString = function (fileData) {
                var binary = "";
                var pt = this;
                var reader = new FileReader();
                reader.onload = function (e) {
                    var bytes = new Uint8Array(reader.result);
                    var length = bytes.byteLength;
                    for (var i = 0; i < length; i++) {
                        binary += String.fromCharCode(bytes[i]);
                    }
                    //pt.result  - readonly so assign binary
                    pt.content = binary;
                    pt.onload();
                };
                reader.readAsArrayBuffer(fileData);
            }
        }
    },
    _loadResource : function( callback ){
        if( !window.XLSX || !window.xlsxUtils ){
            var uri = "../x_component_Template/framework/xlsx/xlsx.full.js";
            var uri2 = "../x_component_Template/framework/xlsx/xlsxUtils.js";
            COMMON.AjaxModule.load(uri, function(){
                COMMON.AjaxModule.load(uri2, function(){
                    callback();
                }.bind(this))
            }.bind(this))
        }else{
            callback();
        }
    },
    _openDownloadDialog: function(url, saveName){
        /**
         * 通用的打开下载对话框方法,没有测试过具体兼容性
         * @param url 下载地址,也可以是一个blob对象,必选
         * @param saveName 保存文件名,可选
         */
        if( Browser.name !== 'ie' ){
            if(typeof url == 'object' && url instanceof Blob){
                url = URL.createObjectURL(url); // 创建blob地址
            }
            var aLink = document.createElement('a');
            aLink.href = url;
            aLink.download = saveName || ''; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
            var event;
            if(window.MouseEvent && typeOf( window.MouseEvent ) == "function" ) event = new MouseEvent('click');
            else
            {
                event = document.createEvent('MouseEvents');
                event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
            }
            aLink.dispatchEvent(event);
        }else{
            window.navigator.msSaveBlob( url, saveName);
        }
    },

    index2ColName : function( index ){
        if (index < 0) {
            return null;
        }
        var num = 65;// A的Unicode码
        var colName = "";
        do {
            if (colName.length > 0)index--;
            var remainder = index % 26;
            colName =  String.fromCharCode(remainder + num) + colName;
            index = (index - remainder) / 26;
        } while (index > 0);
        return colName;
    },

    upload : function ( dateColIndexArray, callback ) {
        var dateColArray = [];
        dateColIndexArray.each( function (idx) {
            dateColArray.push( this.index2ColName( idx ));
        }.bind(this))


        var uploadFileAreaNode = new Element("div");
        var html = "<input name=\"file\" type=\"file\" accept=\"csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel\" />";
        uploadFileAreaNode.set("html", html);

        var fileUploadNode = uploadFileAreaNode.getFirst();
        fileUploadNode.addEvent("change", function () {
            var files = fileNode.files;
            if (files.length) {
                var file = files.item(0);
                // if( file.name.indexOf(" ") > -1 ){
                // 	this.form.notice( MWF.xApplication.process.Xform.LP.uploadedFilesCannotHaveSpaces, "error");
                // 	return false;
                // }

                //第三个参数是日期的列
                this.importFromExcel( file, function(json){
                    //json为导入的结果
                    if(callback)callback(json);
                    uploadFileAreaNode.destroy();
                }.bind(this), dateColArray ); //["E","F"]

            }
        }.bind(this));
        var fileNode = uploadFileAreaNode.getFirst();
        fileNode.click();
    },
1126
    exportToExcel : function(array, fileName, colWidthArr, dateIndexArray, numberIndexArray){
U
unknown 已提交
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
        // var array = [["姓名","性别","学历","专业","出生日期","毕业日期"]];
        // array.push([ "张三","男","大学本科","计算机","2001-1-2","2019-9-2" ]);
        // array.push([ "李四","男","大学专科","数学","1998-1-2","2018-9-2" ]);
        // this.exportToExcel(array, "导出数据"+(new Date).format("db"));
        this._loadResource( function(){
            var data = window.xlsxUtils.format2Sheet(array, 0, 0, null);//偏移3行按keyMap顺序转换
            var wb = window.xlsxUtils.format2WB(data, "sheet1", undefined);
            var wopts = { bookType: 'xlsx', bookSST: false, type: 'binary' };
            var dataInfo = wb.Sheets[wb.SheetNames[0]];

            var widthArray = [];
            array[0].each( function( v, i ){ //设置标题行样式

                if( !colWidthArr )widthArray.push( {wpx: 100} );

1142 1143
                // var at = String.fromCharCode(97 + i).toUpperCase();
                var at = this.index2ColName(i);
U
unknown 已提交
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168
                var di = dataInfo[at+"1"];
                // di.v = v;
                // di.t = "s";
                di.s = {  //设置副标题样式
                    font: {
                        //name: '宋体',
                        sz: 12,
                        color: {rgb: "#FFFF0000"},
                        bold: true,
                        italic: false,
                        underline: false
                    },
                    alignment: {
                        horizontal: "center" ,
                        vertical: "center"
                    }
                };
            }.bind(this));

            if( dateIndexArray && dateIndexArray.length ){
                dateIndexArray.each( function( value, index ){
                    dateIndexArray[ index ] = this.index2ColName(value);
                }.bind(this))
            }

1169 1170 1171 1172 1173 1174 1175 1176
            if( numberIndexArray && numberIndexArray.length ){
                numberIndexArray.each( function( value, index ){
                    numberIndexArray[ index ] = this.index2ColName(value);
                }.bind(this))
            }

            var typeFlag = ( dateIndexArray && dateIndexArray.length ) || ( numberIndexArray && numberIndexArray.length );

U
unknown 已提交
1177 1178 1179 1180 1181 1182 1183 1184
            for( var key in dataInfo ){
                //设置所有样式,wrapText=true 后 /n会被换行
                if( key.substr(0, 1) !== "!" ){
                    var di = dataInfo[key];
                    if( !di.s )di.s = {};
                    if( !di.s.alignment )di.s.alignment = {};
                    di.s.alignment.wrapText = true;

1185 1186
                    if( typeFlag ){

U
unknown 已提交
1187 1188
                        var colName = key.replace(/\d+/g,''); //清除数字
                        var rowNum = key.replace( colName, '');
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198

                        if( rowNum > 1 ){
                            if( dateIndexArray && dateIndexArray.length && dateIndexArray.contains( colName ) ){
                                //di.s.numFmt = "yyyy-mm-dd HH:MM:SS"; //日期列 两种方式都可以
                                di.z = 'yyyy-mm-dd HH:MM:SS'; //日期列
                            }
                            if( numberIndexArray && numberIndexArray.length && numberIndexArray.contains( colName ) ){
                                di.s.alignment.wrapText = false;
                                di.t = 'n'; //数字类型
                            }
U
unknown 已提交
1199
                        }
1200

U
unknown 已提交
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279
                    }
                }

            }

            if( colWidthArr ){
                colWidthArr.each( function (w) {
                    widthArray.push( {wpx: w} );
                })
            }
            dataInfo['!cols'] = widthArray; //列宽度

            this._openDownloadDialog(window.xlsxUtils.format2Blob(wb), fileName +".xlsx");
        }.bind(this))
    },
    importFromExcel : function( file, callback, dateColArray ){
        this._loadResource( function(){
            var reader = new FileReader();
            var workbook, data;
            reader.onload = function (e) {
                //var data = data.content;
                if (!e) {
                    data = reader.content;
                }else {
                    data = e.target.result;
                }
                workbook = window.XLSX.read(data, { type: 'binary' });
                //wb.SheetNames[0]是获取Sheets中第一个Sheet的名字
                //wb.Sheets[Sheet名]获取第一个Sheet的数据
                var sheet = workbook.SheetNames[0];
                if (workbook.Sheets.hasOwnProperty(sheet)) {
                    // fromTo = workbook.Sheets[sheet]['!ref'];
                    // console.log(fromTo);
                    var worksheet = workbook.Sheets[sheet];

                    if( dateColArray && typeOf(dateColArray) == "array" && dateColArray.length ){
                        var rowCount;
                        if( worksheet['!range'] ){
                            rowCount = worksheet['!range'].e.r;
                        }else{
                            var ref = worksheet['!ref'];
                            var arr = ref.split(":");
                            if(arr.length === 2){
                                rowCount = parseInt( arr[1].replace(/[^0-9]/ig,"") );
                            }
                        }
                        if( rowCount ){
                            for( var i=0; i<dateColArray.length; i++ ){
                                for( var j=1; j<=rowCount; j++ ){
                                    var cell = worksheet[ dateColArray[i]+j ];
                                    if( cell ){
                                        delete cell.w; // remove old formatted text
                                        cell.z = 'yyyy-mm-dd'; // set cell format
                                        window.XLSX.utils.format_cell(cell); // this refreshes the formatted text.
                                    }
                                }
                            }
                        }
                    }

                    var json = window.XLSX.utils.sheet_to_json( worksheet );
                    //var data = window.XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheet], {dateNF:'YYYY-MM-DD'});
                    if(callback)callback(json);
                    // console.log(JSON.stringify(json));
                    // break; // 如果只取第一张表,就取消注释这行
                }
                // for (var sheet in workbook.Sheets) {
                //     if (workbook.Sheets.hasOwnProperty(sheet)) {
                //         fromTo = workbook.Sheets[sheet]['!ref'];
                //         console.log(fromTo);
                //         var json = window.XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);
                //         console.log(JSON.stringify(json));
                //         // break; // 如果只取第一张表,就取消注释这行
                //     }
                // }
            };
            reader.readAsBinaryString(file);
        })
    }
U
unknown 已提交
1280
});