/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-06-15 10:00
 * 描  述：report，电缆清册范围选择
 */
var acceptClick;
var folderId = request('folderId');//文件夹ID 
var reportFileName = request('reportFileName');
var ProjectId = request('ProjectId');
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            $('.lr-form-wrap').lrscroll();
            page.bind();
            page.initData();
        },
        bind: function () {
            //抽取类型
            $('#ExtractType').lrselect({
                data: [
                    {
                        id: 0, text: '抽取所有'
                    },
                    {
                        id: 1, text: '按系统抽取'
                    },
                    {
                        id: 2, text: '按图纸目录抽取'
                    }
                ],
                allowSearch: true,
                value: 'id',
                text: 'text',
            });
            //图纸目录
            var isShowCheck = false;
            $('#DrawingCatalogueID').lrselect({
                url: top.$.rootUrl + '/ZZDT_EC/ec_drawing_file/GetTreeData',
                
                param: { ProjectId: ProjectId, isShowCheck: isShowCheck },
                type: 'tree',
                allowSearch: true,
                maxHeight: 225,
                select: function (item) {
                   
                }
            });
            //系统
            $('#DataItemDetailID').lrselect({
                url: top.$.rootUrl + '/ZZDT_EC/ec_dataitem/GetDetailTree',
                param: { itemCode: 'Be_DrawingSystem', ProjectId: ProjectId },
                type: 'tree',
                allowSearch: true,
                maxHeight: 225,
                select: function (item) {

                }
            });
            $("#ExtractType").change(function () {
                var extractType = $('#ExtractType').lrselectGet();
                $("#divDrawingCatalogueID").hide();
                $("#divDataItemDetailID").hide();
                if (extractType == 0) {
                    $("#divDrawingCatalogueID").hide();
                    $("#divDataItemDetailID").hide();
                }
                else if (extractType == 1) {
                    $("#divDrawingCatalogueID").hide();
                    $("#divDataItemDetailID").show();
                }
                else if (extractType == 2) {
                    $("#divDrawingCatalogueID").show();
                    $("#divDataItemDetailID").hide();
                }
                else {
                    $("#divDrawingCatalogueID").hide();
                    $("#divDataItemDetailID").hide();
                }
            });
        },
        initData: function () {
           
        }
    };
    // 保存数据
    acceptClick = function (callBack) {
        if (!$('#form').lrValidform()) {
            return false;
        }
        if (!verify()) {
            return false;
        }
        // 保存成功后才回调
        if (!!callBack) {
            var model = $('#ExtractType').lrselectGet();
            var dataItemDetailIDOrDrawingCategoryID = '';
            if (model == 1) {
                dataItemDetailIDOrDrawingCategoryID = $('#DataItemDetailID').lrselectGet();
            }
            if (model == 2) {
                dataItemDetailIDOrDrawingCategoryID = $('#DrawingCatalogueID').lrselectGet();
            }

            var param = param || {};
            param.model = model;
            param.dataItemDetailIDOrDrawingCategoryID = dataItemDetailIDOrDrawingCategoryID;
            callBack(folderId, escape(reportFileName), JSON.stringify(param));
        }
        learun.layerClose(window.name);
    };
    page.init();
}
function verify() {
    var extractType = $('#ExtractType').lrselectGet();
    if (extractType == 1) {
        if ($('#DataItemDetailID').lrselectGet() == '') {
            $.lrValidformMessage($("#DataItemDetailID"), "不能为空");
            $('#DataItemDetailID').click();
            return false;
        }
    }
    if (extractType == 2) {
        if ($('#DrawingCatalogueID').lrselectGet() == '') {
            $.lrValidformMessage($("#DrawingCatalogueID"), "不能为空");
            $('#DrawingCatalogueID').click();
            return false;
        }
    }
    return true;
}