/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2023-07-20 11:30
 * 描  述：信号表
 */
var refreshGirdData;
var ProjectId = parent.request('ProjectId');
var StatusType = 0;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGird();
            page.bind();
        },
        bind: function () {
            //查询
            $('#btn_Search').on('click', function () {
                page.search();
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 新增
            $('#lr_add').on('click', function () {
                learun.layerForm({
                    id: 'form',
                    title: '新增信号',
                    url: top.$.rootUrl + '/ZZDT_EC/ec_Wire_Group/Form?ProjectId=' + ProjectId,
                    width: 550,
                    height: 450,
                    callBack: function (id) {
                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('Wire_Group_ID');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form',
                        title: '编辑',
                        url: top.$.rootUrl + '/ZZDT_EC/ec_Wire_Group/Form?ProjectId=' + ProjectId + "&keyValue=" + keyValue,
                        width: 550,
                        height: 450,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });
            // 彻底删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('Wire_Group_ID');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('是否确认删除该项！', function (res) {
                        if (res) {
                            learun.deleteForm(top.$.rootUrl + '/ZZDT_EC/ec_Wire_Group/DeleteForm', { ProjectId: ProjectId, keyValue: keyValue }, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });
            //信号履历
            $('#lr_history').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('Wire_Group_ID');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'HistoryForm',//窗口id
                        title: '信号履历',//标题
                        url: top.$.rootUrl + '/ZZDT_EC/ec_wire_group_propertyhis/Index?ProjectId=' + ProjectId + "&WireGroupID=" + keyValue,//窗体打开页面连接
                        width: 800,
                        height: 500,
                        maxmin: true,
                        btn: null//窗体底部显示按钮
                    });
                }
            });
            //通知
            $('#lr_notice').on('click', function () {
                learun.layerForm({
                    id: 'NoticeForm',//窗口id
                    title: '通知',//标题
                    url: top.$.rootUrl + '/ZZDT_EC/ec_WireGroupNotice/Index?ProjectId=' + ProjectId,
                    width: 800,
                    height: 500,
                    maxmin: true,
                    btn: null//窗体底部显示按钮
                });
            });
            // 删除
            $('#lr_isdelete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('Wire_Group_ID');
                if (learun.checkrow(keyValue)) {
                    learun.httpPost(top.$.rootUrl + '/ZZDT_EC/ec_Wire_Group/SaveStatus', {
                        ProjectId: ProjectId,
                        keyValue: keyValue,
                        status: 1,
                    }, function (res) {
                        if (res.code == 200) {
                            learun.alert.success(res.info);
                        }
                        else {
                            learun.alert.error(res.info);
                        }
                        refreshGirdData();
                    });
                }
            });
            // 撤销删除
            $('#lr_notdelete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('Wire_Group_ID');
                if (learun.checkrow(keyValue)) {
                    learun.httpPost(top.$.rootUrl + '/ZZDT_EC/ec_Wire_Group/SaveStatus', {
                        ProjectId: ProjectId,
                        keyValue: keyValue,
                        status: 2,
                    }, function (res) {
                        if (res.code == 200) {
                            learun.alert.success(res.info);
                        }
                        else {
                            learun.alert.error(res.info);
                        }
                        refreshGirdData();
                    });
                }
            });
            //审核
            $('#lr_approve').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('Wire_Group_ID');
                if (learun.checkrow(keyValue)) {
                    learun.httpPost(top.$.rootUrl + '/ZZDT_EC/ec_Wire_Group/SaveStatus', {
                        ProjectId: ProjectId,
                        keyValue: keyValue,
                        status: 4,
                    }, function (res) {
                        if (res.code == 200) {
                            learun.alert.success(res.info);
                        }
                        else {
                            learun.alert.error(res.info);
                        }
                        refreshGirdData();
                    });
                }
            });
            //重现打开
            $('#lr_reopen').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('Wire_Group_ID');
                if (learun.checkrow(keyValue)) {
                    learun.httpPost(top.$.rootUrl + '/ZZDT_EC/ec_Wire_Group/SaveStatus', {
                        ProjectId: ProjectId,
                        keyValue: keyValue,
                        status: 5,
                    }, function (res) {
                        if (res.code == 200) {
                            learun.alert.success(res.info);
                        }
                        else {
                            learun.alert.error(res.info);
                        }
                        refreshGirdData();
                    });
                }
            });
            // 信号模板管理
            $('#lr_groupmanager').on('click', function () {
                learun.layerForm({
                    id: 'group',
                    title: '信号模板管理',
                    url: top.$.rootUrl + '/ZZDT_EC/ec_Wire_Group_Template/Index?ProjectId=' + ProjectId,
                    width: 850,
                    height: 550,
                    btn: null,
                    end: function () {
                        location.reload();
                    }
                });


            });
            //监测系统表导出 lr_export
            $('#lr_export').on('click', function () {
                 
                learun.loading(true, "导出中...");
                var iframeUrl = top.$.rootUrl + '/ZZDT_EC/ec_Wire_Group/IOModuleExportExcel?ProjId=' + ProjectId;
                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);
            });


            //数据导入
            $('#lr_import').on('click', function () {
                learun.layerForm({
                    id: 'form',//窗口id
                    title: '选择模板',//标题
                    url: top.$.rootUrl + '/ZZDT_EC/ec_Wire_Group/SelectTemplate?ProjectId=' + ProjectId,//窗体打开页面连接
                    width: 400,
                    height: 300,
                    callBack: function (id) {
                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            //一组状态查询
            $('#sf_all').on('click', function () {
                StatusType = 0;
                page.search();
            });
            $('#sf_todelete').on('click', function () {
                StatusType = 1;
                page.search();
            });
            $('#sf_notdelete').on('click', function () {
                StatusType = 2;
                page.search();
            });
            $('#sf_linked').on('click', function () {
                StatusType = 3;
                page.search();
            });
            $('#sf_approve').on('click', function () {
                StatusType = 4;
                page.search();
            });
            $('#sf_reopen').on('click', function () {
                StatusType = 5;
                page.search();
            });
        },
        // 初始化列表
        initGird: function () {
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/ZZDT_EC/ec_Wire_Group/GetList',
                headData: [
                    { label: "信号", name: "Group_Name", width: 170, align: "center", sort: false, frozen: true },
                    { label: "描述(EN)", name: "Group_Desc_EN", width: 350, align: "left", sort: false, frozen: true },
                    { label: "描述", name: "Group_Desc", width: 350, align: "left", sort: false },
                    { label: "代码", name: "Code", width: 70, align: "center", sort: false },
                    { label: "信号类型", name: "IO_Type", width: 80, align: "center", sort: false },
                    { label: "Range_Min", name: "Range_Min", width: 90, align: "center", sort: false },
                    { label: "Range_Max", name: "Range_Max", width: 90, align: "center", sort: false },
                    { label: "单位", name: "Unit", width: 70, align: "center", sort: false },
                    { label: "Alarm_LL", name: "Alarm_LL", width: 70, align: "center", sort: false },
                    { label: "Alarm_L", name: "Alarm_L", width: 70, align: "center", sort: false },
                    { label: "Alarm_H", name: "Alarm_H", width: 70, align: "center", sort: false },
                    { label: "Alarm_HH", name: "Alarm_HH", width: 70, align: "center", sort: false },
                    { label: "AL_GRP", name: "AL_GRP", width: 70, align: "center", sort: false },
                    { label: "BL_GRP", name: "BL_GRP", width: 70, align: "center", sort: false },
                    { label: "延时", name: "Time_Delay", width: 70, align: "center", sort: false },
                    { label: "供应商", name: "Supplier", width: 70, align: "center", sort: false },
                    { label: "传感器代码", name: "SENSOR_CODE", width: 70, align: "center", sort: false },
                    { label: "输入/输出", name: "InOrOut", width: 70, align: "center", sort: false },
                    { label: "VDR_Record", name: "VDR_Record", width: 90, align: "center", sort: false },
                    { label: "备注", name: "Remarks", width: 350, align: "left", sort: false },
                    { label: "柜子", name: "PanelName", width: 90, align: "left", sort: false },
                    { label: "通道号", name: "ChannelName", width: 90, align: "left", sort: false },
                    { label: "端子排", name: "StripName", width: 90, align: "left", sort: false },
                    { label: "电缆位号", name: "CableName", width: 90, align: "left", sort: false },
                    { label: "电缆对", name: "CableSetName", width: 90, align: "left", sort: false },
                    { label: "状态", name: "StatusValue", width: 90, align: "left", sort: false }
                ],
                mainId: 'Wire_Group_ID',
                isPage: true,
            });
            page.search();
        },
        search: function (param) {
            param = param || {};
            param.GroupName = $("#GroupName").val();
            param.ProjectId = ProjectId;
            param.Status = StatusType;
            $('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
        }
    };
    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    };
    page.init();
}