/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-02-24 11:10
 * 描  述：对象类型
 */
var refreshGirdData;
var ProjectId = request('ProjectId');
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGird();
            page.bind();
        },
        bind: function () {
            $("#IsExportData").change(function () {
                var extractType = $('#IsExportData').prop("checked");

                if (extractType) {
                    $("#drawingTree").show();
                }
                else {
                    $("#drawingTree").hide();
                }
            });
            //模板导出
            $('#lr_export').on('click', function () {
                //dwg range(task 6908)
                var IsExportData = document.getElementById("IsExportData").checked;
                var dwgIds = "";
                if (IsExportData) {
                    //勾选，需要图纸列表  
                    var param = $('#drawingTree').lrtreeSet("getCheckNodesEx");

                    for (var i = 0; i < param.length; i++) {
                        dwgIds += param[i].id + ",";
                    }
                    dwgIds = dwgIds.substring(0, dwgIds.length - 1);
                } 


                var exportData = $('#dataTree').lrtreeSet("getCheckNodesEx");
                if (exportData.length == 0) {
                    learun.alert.warning('请至少选择一个要导出模板的对象类型！');
                    return false;
                } 
                var objectTypeIDs = "";
                for (var i = 0; i < exportData.length; i++) {
                    objectTypeIDs += exportData[i].id + ",";
                }
                objectTypeIDs = objectTypeIDs.substring(0, objectTypeIDs.length - 1);
                var TagNumber = $('#TagNumber').val();
                learun.loading(true, "导出中...");
                var iframeUrl = top.$.rootUrl + '/ZZDT_EC/ec_objecttype/ExportToExcel?ProjectId=' + ProjectId + "&IsExportData=" + IsExportData + "&objectTypeIDs=" + objectTypeIDs + "&TagNumber=" + TagNumber + "&DwgIds=" + dwgIds;
                learun.loading(true, "Excel读取中...");
                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);
            });
            //查询
            $('#btn_Search').on('click', function () {
                var ObjectTypeName = $('#ObjectTypeName').val();
                var TagNumber = $('#TagNumber').val();
                $('#dataTree').lrtree({
                    url: top.$.rootUrl + '/ZZDT_EC/ec_objecttype/GetTreeDataByFilter',
                    param: { ProjectId: ProjectId, ObjectTypeName: ObjectTypeName, TagNumber: TagNumber, isShowCheck: true },
                    nodeClick: function (item) {

                    }
                });
            });
        },
        initGird: function () {
            $("#drawingTree").hide();//默认隐藏
            // 初始化左侧设备类型的树形数据
            $('#dataTree').lrtree({
                url: top.$.rootUrl + '/ZZDT_EC/ec_objecttype/GetTreeDataByFilter',
                param: { ProjectId: ProjectId, isShowCheck: true },
                nodeClick: function (item) {

                }
            });

            // 初始化右侧图纸的树形数据
            $('#drawingTree').lrtree({
                url: top.$.rootUrl + '/ZZDT_EC/ec_drawing_file/GetTreeData',
                param: { ProjectId: ProjectId, isShowCheck: true },
                nodeClick: function (item) {

                }
            });
            //learun.httpAsyncGet(top.$.rootUrl + '/ZZDT_EC/ec_drawing_file/GetTreeData?ProjectId=' + ProjectId + "&isShowCheck=true", function (res) {
            //    if (res.code == 200) {
            //        var treeData = res.data;
            //        $('#dataTree').lrtree({
            //            data: treeData
            //        });
            //        setTreeData1();
            //    }
            //    setTimeout(function () {
            //        learun.loading(false);
            //    });
            //});
        },

    };
    page.init();
}
