/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-06-15 10:00
 * 描  述：报表文件
 */
var refreshGirdData;
var ProjectId = parent.request('ProjectId');
var ReportCatalogueID;
var relrtree; //初始化树形
var showLeftTree = request("showLeftTree");
var showContent;
var exportToExcel;
var reportToExcel;
var signalToExcel;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            if (!!ProjectId) {
                $("#lr_export").show();
            }
            page.initGird();
            page.bind();
        },
        bind: function () {
            if (showLeftTree == "0") {
                $(".lr-layout-left").hide();
                $(".lr-layout-title").hide();
                $(".lr-layout-title").parent().addClass("lr-layout-wrap-notitle ");
                $("#lr_layout").removeClass("lr-layout-left-center");
            } else {
                //初始化tree
                relrtree();
            }

            //生成报表
            $('#lr_export').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('ReportFileID');
                if (learun.checkrow(keyValue)) {
                    var folderId = $('#gridtable').jfGridValue('FolderId');
                    var reportFileName = $('#gridtable').jfGridValue('ReportFileName');
                    if (reportFileName == '电缆清册') {
                        learun.layerForm({
                            id: 'systemselect',
                            title: '电缆清册 参数选择',
                            url: top.$.rootUrl + '/ZZDT_EC/ec_report_file/SystemSelect?folderId=' + folderId + "&reportFileName=" + escape(reportFileName) + "&ProjectId=" + ProjectId,
                            width: 700,
                            height: 400,
                            callBack: function (id) {
                                return top[id].acceptClick(reportToExcel);
                            }
                        });
                    }
                    else if (reportFileName == '信号清册（1642版）' || reportFileName == '信号清册（8600版）' || reportFileName == '信号清册（8600版单行）' || reportFileName == '信号修改清单') {
                        learun.layerForm({
                            id: 'versionselect',
                            title: '信号清册 参数选择',
                            url: top.$.rootUrl + '/ZZDT_EC/ec_report_file/SignalParamSelect?folderId=' + folderId + "&reportFileName=" + escape(reportFileName),
                            width: 900,
                            height: 450,
                            callBack: function (id) {
                                return top[id].acceptClick(signalToExcel);
                            }
                        });
                    }
                    else if (reportFileName == '云线备注清单') {
                        learun.layerForm({
                            id: 'cloudListSelect',
                            title: '云线备注清单 参数选择',
                            url: top.$.rootUrl + '/ZZDT_EC/ec_report_file/CloudListParamSelect?folderId=' + folderId + "&reportFileName=" + escape(reportFileName),
                            width: 500,
                            height: 400,
                            callBack: function (id) {
                                return top[id].acceptClick(reportToExcel);
                            }
                        });
                    }
                    else if (reportFileName == '设备清册') {
                        learun.layerForm({
                            id: 'SelectDrawingsForm',
                            title: '设备清册 图纸范围选择',
                            url: top.$.rootUrl + '/ZZDT_EC/ec_report_file/SelectDrawings?folderId=' + folderId + "&reportFileName=" + escape(reportFileName) + "&ProjectId=" + ProjectId,
                            width: 500,
                            height: 400,
                            callBack: function (id) {
                                return top[id].acceptClick(reportToExcel);
                            }
                        });
                    }
                    else {
                        learun.layerForm({
                            id: 'paramselect',
                            title: '参数选择',
                            url: top.$.rootUrl + '/ZZDT_EC/ec_report_file/ParamSelect?folderId=' + folderId + "&ProjectId=" + ProjectId + "&reportFileName=" + escape(reportFileName),
                            width: 700,
                            height: 350,
                            callBack: function (id) {
                                return top[id].acceptClick(exportToExcel);
                            }
                        });
                    }
                }
            });

            //查询
            $('#btn_Search').on('click', function () {
                page.search($('.lr-layout-tool-left').lrGetFormData());
            });

            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 新增
            $('#lr_add').on('click', function () {
                if (!ReportCatalogueID && showLeftTree != "0") {
                    learun.alert.warning("请选择分类");
                    return;
                }
                learun.layerForm({
                    id: 'form',
                    title: '新增',
                    url: top.$.rootUrl + '/ZZDT_EC/ec_report_file/Form?ReportCatalogueID=' + ReportCatalogueID + "&ProjectId=" + ProjectId,
                    width: 700,
                    height: 300,
                    callBack: function (id) {
                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('ReportFileID');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form',
                        title: '编辑',
                        url: top.$.rootUrl + '/ZZDT_EC/ec_report_file/Form?keyValue=' + keyValue + "&ProjectId=" + ProjectId + "&ReportCatalogueID=" + ReportCatalogueID,
                        width: 700,
                        height: 300,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });
            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('ReportFileID');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('是否确认删除该项！', function (res) {
                        if (res) {
                            learun.deleteForm(top.$.rootUrl + '/ZZDT_EC/ec_report_file/DeleteForm', { keyValue: keyValue, ProjectId: ProjectId }, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });
        },
        // 初始化列表
        initGird: function () {
            var tbalewidth = window.innerWidth / 4;
            if (!!top) {
                tbalewidth = top.window.innerWidth / 4.5;
            }
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/ZZDT_EC/ec_report_file/GetPageList',
                headData: [
                    {
                        label: "报表文件名称", name: "ReportFileName", width: 300, align: "left", sort: false,
                        formatter: function (value, row, op, $cell) {
                            return "<a style='color: #337ab7;text-decoration: underline;' href='javascript:showContent(\"" + row.ReportFileID + "\");'>" + value + "</a>";
                        }
                    },
                    { label: "创建人", name: "CreateUserName", width: 100, align: "center", sort: false },
                    {
                        label: "创建时间", name: "CreateTime", width: 150, align: "center", sort: false,
                        formatter: function (cellvalue) {
                            return learun.formatDate(cellvalue, 'yyyy-MM-dd hh:mm');
                        }
                    },
                    { label: "备注", name: "Remark", width: 300, align: "left", sort: false },
                    { name: "", width: 1, sort: false }
                ],
                mainId: 'ReportFileID',
                sidx: "CreateTime",
                sord: "DESC",
                isPage: true
            });
            page.search();
        },
        search: function (param) {
            param = param || {};
            param.ReportCatalogueID = ReportCatalogueID;
            param.ProjectId = ProjectId;
            $('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
        }
    };
    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    };
    //最普通的
    exportToExcel = function (folderId, reportFileName, objectTypeIDs, propertyIDs, relTypeIDs) {
        var iframeUrl = top.$.rootUrl + '/ZZDT_EC/ec_report_file/ExportToExcel?ProjectId=' + ProjectId + "&folderId=" + folderId + "&reportFileName=" + reportFileName + "&objectTypeIDs=" + objectTypeIDs + "&propertyIDs=" + propertyIDs + "&relTypeIDs=" + relTypeIDs;
        learun.loading(true, "生成 简易 报表中...");
        var body = document.getElementsByTagName("body")[0];
        var downloadIframe = document.createElement("iframe");
        downloadIframe.setAttribute("src", iframeUrl);
        downloadIframe.setAttribute("style", "display:none;")
        body.appendChild(downloadIframe);
        learun.loading(false);
    };
    //电缆清册dataItemDetailIDOrDrawingCategoryID, model
    reportToExcel = function (folderId, reportFileName, param) {
        var iframeUrl = top.$.rootUrl + '/ZZDT_EC/ec_report_file/ReportToExcel?ProjectId=' + ProjectId + "&folderId=" + folderId + "&reportFileName=" + reportFileName + "&param=" + param;//"&dataItemDetailIDOrDwgCategoryID=" + dataItemDetailIDOrDrawingCategoryID + "&model=" + model;
        learun.loading(true, "生成 复杂 报表中...");
        var body = document.getElementsByTagName("body")[0];
        var downloadIframe = document.createElement("iframe");
        downloadIframe.setAttribute("src", iframeUrl);
        downloadIframe.setAttribute("style", "display:none;")
        body.appendChild(downloadIframe);
        learun.loading(false);
    };
    //信号清单
    signalToExcel = function (folderId, reportFileName, deleteFlg, DateFrom,DateTo) {
        var iframeUrl = top.$.rootUrl + '/ZZDT_EC/ec_Wire_Group/ExportToExcel?ProjectId=' + ProjectId + "&DeleteFlg=" + deleteFlg + "&folderId=" + folderId + "&reportFileName=" + reportFileName + "&DateFrom=" + DateFrom + "&DateTo=" + DateTo;
        learun.loading(true, "生成 信号清单 报表中...");
        var body = document.getElementsByTagName("body")[0];
        var downloadIframe = document.createElement("iframe");
        downloadIframe.setAttribute("src", iframeUrl);
        downloadIframe.setAttribute("style", "display:none;")
        body.appendChild(downloadIframe);
        learun.loading(false);
    };
    relrtree = function () {
        // 初始化左侧树形数据
        $('#dataTree').lrtree({
            url: top.$.rootUrl + '/ZZDT_EC/ec_report_catalogue/GetTreeData',
            param: { ProjectId: ProjectId },
            nodeClick: function (item) {
                ReportCatalogueID = item.value;
                $("#titleinfo").html(item.text);
                page.search();
            }
        });
    };
    //查看详情
    showContent = function (id) {
        if (learun.checkrow(id)) {
            learun.layerForm({
                id: 'form',
                title: '查看',
                url: top.$.rootUrl + '/ZZDT_EC/ec_report_file/Form?keyValue=' + id + '&openType=look' + "&ProjectId=" + ProjectId,
                width: 700,
                height: 260,
                btn: null
            });
        }
    };
    page.init();
}
