/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-02-09 22:05
 * 描  述：样板文件
 */
var refreshGirdData;
var ProjectId = parent.request('ProjectId');
var TemplateCatalogueID;
var relrtree; //初始化树形
var ShowFile;
var isCaoz = false;
var showLeftTree = request("showLeftTree");
var showContent;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGird();
            page.bind();
        },
        bind: function () {
            if (showLeftTree == "0") {
                $(".lr-layout-left").hide();
                $(".lr-layout-title").hide();
                $(".lr-layout-title").parent().addClass("lr-layout-wrap-notitle ");
                $("#lr_layout").removeClass("lr-layout-left-center");
            } else {
                //初始化tree
                relrtree();
            }

            //查询
            $('#btn_Search').on('click', function () {
                page.search($('.lr-layout-tool-left').lrGetFormData());
            });

            // 刷新
            $('#lr_refresh').on('click', function () {
                refreshGirdData();
            });

            // 新增
            $('#lr_add').on('click', function () {
                if (!TemplateCatalogueID && showLeftTree != "0") {
                    learun.alert.warning("请选择分类");
                    return;
                }
                learun.layerForm({
                    id: 'form',
                    title: '新增',
                    url: top.$.rootUrl + '/ZZDT_EC/ec_template_file/Form?TemplateCatalogueID=' + TemplateCatalogueID + "&ProjectId=" + ProjectId,
                    width: 700,
                    height: 300,
                    callBack: function (id) {
                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });

            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('TemplateFileID');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form',
                        title: '编辑',
                        url: top.$.rootUrl + '/ZZDT_EC/ec_template_file/Form?keyValue=' + keyValue + "&ProjectId=" + ProjectId + "&TemplateCatalogueID=" + TemplateCatalogueID,
                        width: 700,
                        height: 300,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });

            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('TemplateFileID');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('是否确认删除该项！', function (res) {
                        if (res) {
                            learun.deleteForm(top.$.rootUrl + '/ZZDT_EC/ec_template_file/DeleteForm', { keyValue: keyValue, ProjectId: ProjectId }, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });

        },
        // 初始化列表
        initGird: function () {
            var tbalewidth = window.innerWidth / 4;
            if (!!top) {
                tbalewidth = top.window.innerWidth / 4.5;
            }
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/ZZDT_EC/ec_template_file/GetPageList',
                headData: [
                    {
                        label: "样板文件名称", name: "TemplateFileName", width: 300, align: "left", sort: false,
                        formatter: function (value, row, op, $cell) {
                            return "<a style='color: #337ab7;text-decoration: underline;' href='javascript:showContent(\"" + row.TemplateFileID + "\");'>" + value + "</a>";
                        }
                    },
                    { label: "创建人", name: "CreateUserName", width: 100, align: "center", sort: false },
                    {
                        label: "创建时间", name: "CreateTime", width: 150, align: "center", sort: false,
                        formatter: function (cellvalue) {
                            return learun.formatDate(cellvalue, 'yyyy-MM-dd hh:mm');
                        }
                    },
                    { label: "备注", name: "Remark", width: 300, align: "left", sort: false },
                    { name: "", width: 1, sort: false }
                ],
                mainId: 'TemplateFileID',
                sidx: "CreateTime",
                sord: "DESC",
                isPage: true
            });
            page.search();
        },
        search: function (param) {
            param = param || {};
            param.TemplateCatalogueID = TemplateCatalogueID;
            param.ProjectId = ProjectId;
            $('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
        }
    };
    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    };
    relrtree = function () {
        // 初始化左侧树形数据
        $('#dataTree').lrtree({
            url: top.$.rootUrl + '/ZZDT_EC/ec_template_catalogue/GetTreeData',
            param: { ProjectId: ProjectId },
            nodeClick: function (item) {
                TemplateCatalogueID = item.value;
                $("#titleinfo").html(item.text);
                page.search({ TemplateCatalogueID: item.value });
            }
        });
    };
    ShowFile = function (keyValue) {
        if (learun.checkrow(keyValue)) {
            learun.layerForm({
                id: 'downform',
                title: '附件管理',
                url: top.$.rootUrl + '/LR_SystemModule/Annexes/DownForm?keyVaule=' + keyValue,
                width: $('#gridtable').width() * 0.5,
                height: $('#gridtable').width() * 0.3,
                maxmin: true,
                btn: null
            });
        }
    };
    //查看详情
    showContent = function (id) {
        if (learun.checkrow(id)) {
            learun.layerForm({
                id: 'form',
                title: '查看',
                url: top.$.rootUrl + '/ZZDT_EC/ec_template_file/Form?keyValue=' + id + '&openType=look' + "&ProjectId=" + ProjectId,
                width: 700,
                height: 260,
                btn: null
            });
        }
    };
    page.init();
}
