/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-02-24 11:10
 * 描  述：报表 - 选择图纸
 */
var ProjectId = request('ProjectId');
var folderId = request('folderId');//文件夹ID 
var reportFileName = request('reportFileName');
var selectData = [];
var acceptClick;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGird();
            page.bind();
        },
        bind: function () {
            //抽取范围
            $('#ExtractRange').lrselect({
                data: [
                    {
                        id: 0, text: '所有图纸'
                    },
                    {
                        id: 1, text: '部分图纸'
                    }
                ],
                allowSearch: true,
                value: 'id',
                text: 'text',
            });

            $("#ExtractRange").change(function () {
                var extractType = $('#ExtractRange').lrselectGet();

                if (extractType == 0) {
                    $("#dataTree").hide();
                }
                else if (extractType == 1) {
                    $("#dataTree").show();
                }
            });
        },

        initGird: function () {
            $("#dataTree").hide();
            learun.loading(true, '正在获取数据');
            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();
    // 保存数据
    acceptClick = function (callBack) {
        if (!$('#form').lrValidform()) {
            return false;
        }
        // 保存成功后才回调
        if (!!callBack) {

            var param = $('#dataTree').lrtreeSet("getCheckNodesEx");
            var extractType = $('#ExtractRange').lrselectGet();
            if (extractType == 0) {
                //all
            }
            else {
                //partial
                if (!param || param.length === 0) {
                    alert("请至少选择一个图纸！");
                    return false;
                }
            }

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


            callBack(folderId, escape(reportFileName), JSON.stringify({ range: extractType, dwgIds: dwgIds }));//会去index.Js的203行
        }
        learun.layerClose(window.name);
    };
}

function setTreeData1() {
    if (!!selectData) {
        setTimeout(function () {
            $('#dataTree').lrtreeSet('setCheck', selectData);
        });
    }
    else {
        setTimeout(setTreeData1, 100);
    }
}