/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-04-11 09:45
 * 描  述：项目备份表
 */
var refreshGirdData;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGird();
            page.bind();
        },
        bind: function () {
            //查询
            $('#btn_Search').on('click', function () {
                page.search($('.lr-layout-tool-left').lrGetFormData());
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('ProjectBakupID');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form',
                        title: '编辑',
                        url: top.$.rootUrl + '/ZZDT_EC/ec_project_bakup/Form?keyValue=' + keyValue,
                        width: 580,
                        height: 300,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });
            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('ProjectBakupID');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('是否确认删除该项！', function (res) {
                        if (res) {
                            learun.deleteForm(top.$.rootUrl + '/ZZDT_EC/ec_project_bakup/DeleteForm', { keyValue: keyValue }, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });

            //下载备份
            $('#lr_download').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('ProjectBakupID');
                if (keyValue == "") {
                    learun.alert.warning('请选择一条记录！');
                    return false;
                }
                learun.loading(true, "下载备份中...");
                var iframeUrl = top.$.rootUrl + "/ZZDT_EC/ec_project_bakup/BackupDown?projectBakupID=" + keyValue;
                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);
            });
        },
        // 初始化列表
        initGird: function () {
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/ZZDT_EC/ec_project_bakup/GetPageList',
                headData: [
                    { label: "备份名称", name: "BakupName", width: 300, align: "left", sort: false },
                    { label: "备注", name: "Remark", width: 500, align: "left", sort: false },
                    { label: '创建人', name: 'CreateUserName', width: 120, align: "center", sort: false },
                    { label: '创建时间', name: 'CreateTime', width: 150, align: "center", sort: false },
                    { label: "", name: "", width: 1, sort: false }
                ],
                mainId: 'ProjectBakupID',
                sidx: "CreateTime ",
                sord: "DESC",
                isPage: true
            });
            page.search();
        },
        search: function (param) {
            param = param || {};
            $('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
        }
    };
    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    };
    page.init();
}
