/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2023-07-20 11:30
 * 描  述：模板选择
 */
var acceptClick;
var WireGroupTemplateID = request('WireGroupTemplateID'); //会是“”因为从index界面点击编辑按钮时，没有这个参数
var ProjectId = request('ProjectId');
var mode;
var thiscall;
var uploadKeyValue;
var version;
var singleColIndex;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            $("#singleColIndex").hide();
            $("#title_singleColIndex").hide();
            $('.lr-form-wrap').lrscroll();
            page.bind();
        },
        bind: function () {
            //模板版本
            $('#Version').lrselect({
                data: [
                    {
                        id: 1, text: '1642版'
                    },
                    {
                        id: 2, text: '8600版'
                    },
                    {
                        id: 3, text: '8600版(单行)'
                    }
                ], 
                value: 'id',
                text: 'text',
            });
            //导入模式（24 06 05加）
            $('#mode').lrselect({
                data: [
                    {
                        id: 1, text: '只新增'
                    },
                    {
                        id: 2, text: '新增和更新'
                    },
                    {
                        id: 3, text: '完全（增、删、改），且不受已审核约束'
                    },
                    {
                        id: 4, text: '只更新单列'
                    }
                ], 
                value: 'id',
                text: 'text',
            });

            $('#mode').change(function () { 
                var propertyType = $('#mode').lrselectGet();
                if (propertyType == "4") { 
                    $("#singleColIndex").show();
                    $("#title_singleColIndex").show();
                    
                } 
                else {
                    $("#singleColIndex").hide(); 
                    $("#title_singleColIndex").hide();
                }
            });
        },
    };
    // 保存数据
    acceptClick = function (callBack) {
        if (!$('#form').lrValidform()) {
            return false;
        }
        var format = 'xlsx';
        uploadKeyValue = Guid.NewGuid().toString();
        version = $('#Version').lrselectGet();
        mode = $('#mode').lrselectGet();
        singleColIndex = $('#singleColIndex').val();
        //因为这个时候界面就关掉了，等待上传文件了。
        thiscall = callBack;
        learun.layerForm({
            id: 'import',
            title: '数据导入',
            url: top.$.rootUrl + '/LR_SystemModule/Annexes/UploadForm?keyVaule=' + uploadKeyValue + "&multiple=false" + "&format=" + format,
            width: 600,
            height: 400,
            maxmin: true,
            btn: ['确认'],
            callBack: function (id) {
                learun.layerClose('import');
                MuliteImport(uploadKeyValue);
            }
        });
    };
    page.init();
}
function MuliteImport(fileId) {
    var learun = top.learun;
    learun.loading(true, "数据导入中...");
    $.ajax({
        type: 'POST',
        url: top.$.rootUrl + "/ZZDT_EC/ec_Wire_Group/ExcelImport?rdo=" + Math.random(),
        data: {
            fileId: fileId,
            ProjectId: ProjectId,
            wireGroupTemplateID: WireGroupTemplateID,
            mode: mode,
            version: version,
            singleColIndex: singleColIndex
        },
        traditional: true,
        success: function (data) {
            var data = JSON.parse(data);
            if (data.code == '200') {
                learun.alert.success(data.info);
                learun.loading(true, "下载导入结果的Excel...");
                var iframeUrl = top.$.rootUrl + '/ZZDT_EC/ec_Wire_Group/ImportResult?fileId=' + uploadKeyValue;
                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);
            } else {
                learun.alert.error(data.info);
            }

        },
        error: function (msg) {
            learun.alert.error(msg);
        },
        complete: function (data) {
            learun.loading(false);
            if (!!thiscall) {
                thiscall();
            }
        }
    });
}