<%@ page language="java" import="java.util.*" pageEncoding="gbk" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
    <%@include file="../../frame/assets/header-all.jsp" %>
    <script type="text/javascript" src="../nhyw/js/jquery.form.js"></script>
    <script type="text/javascript" src=""></script>
</head>
<body>

<div class="easyui-layout">
    <form id="childform" class="easyui-form" data-options="novalidate:true">
        <div class="form-line clearfix">
            <div class="fl">
                <span class="text-content">设备类型：</span>
                <input id="alarmdevicetype" class="easyui-combobox">
            </div>
            <%--            <div class="fl" id="machine" style="display: none">--%>
            <%--                <span class="text-content">服务器名称：</span>--%>
            <%--                <input id="machineid" class="easyui-combobox" data-options="required:true,validType:'length[0,128]'">--%>
            <%--            </div>--%>
            <div class="fl" id="video" style="display: block">
                <span class="text-content"><em class="must"></em>设备名称：</span>
                <input id="gysmc" disable class="easyui-textbox" data-options="required:false">
                <div class="input-addimg" style="margin-top: -22px; margin-left: 245px;">
                    <a href="javascript:selectGys();" class="icon-add img-btn1"></a>
                </div>
            </div>
        </div>
        <%--        根据选择设备类型展示是服务器数据还是监控数据--%>
        <div >
            <div class="form-line clearfix" style="display: none">
                <div class="fl" >
                    <span class="text-content"><em class="must"></em>设备编码：</span>
                    <input id="sbbh" disabled class="easyui-textbox"   data-options="required:false,validType:'length[0,40]'"
                    >
                </div>
                <div class="fl" id="videoparam">
                    <span class="text-content"><em class="must"></em>通道编号：</span>
                    <input id="LIKEtdbh" class="easyui-textbox" data-options="required:false,validType:'length[0,40]'">
                </div>

            </div>
        </div>
        <%--        <div class="form-line clearfix"  >--%>

        <%--            <div class="fl">--%>
        <%--                <span class="text-content"><em class="must"></em>CPU使用率：</span>--%>
        <%--                <input id="cpuusag" class="easyui-textbox" data-options="required:false,validType:'length[0,10]'">--%>
        <%--            </div>--%>

        <%--            <div class="fl">--%>
        <%--                <span class="text-content"><em class="must"></em>内存使用率：</span>--%>
        <%--                <input id="memoryusag" class="easyui-textbox" data-options="required:false,validType:'length[0,10]'">--%>
        <%--            </div>--%>
        <%--            <div class="fl">--%>
        <%--                <span class="text-content"><em class="must"></em>硬盘使用率：</span>--%>
        <%--                <input id="harddiskusag" class="easyui-textbox" data-options="required:false,validType:'length[0,10]'">--%>
        <%--            </div>--%>
        <%--         </div>--%>
        <div class="form-line clearfix">
            <div class="fl">
                <span class="text-content"><em class="must"></em>告警来源：</span>
                <input class="easyui-combobox" id="alarrulename"/>
            </div>
            <div class="fl">
                <span class="text-content"><em class="must"></em>告警子类：</span>
                <input class="easyui-combobox" id="alarmsubtypes"/>
            </div>
        </div>
        <div class="form-line clearfix">
            <div class="fl">
                <span class="text-content"><em class="must"></em>告警等级：</span>
                <input class="easyui-combobox" id="alarmgrade"
                       data-options="valueField:'id', textField:'text',panelHeight:'auto'">
            </div>
            <div class="fl">
                <span class="text-content"><em class="must"></em>发生时间：</span>
                <input id="faultoccurtime" class="easyui-datetimebox">
            </div>
        </div>
        <div class="form-line clearfix">

            <div class="fl">
                <span class="text-content"><em class="must"></em>故障描述：</span>
                <textarea id="falutdescription" style="width:400px;height:60px"> </textarea>
            </div>
        </div>
        <%-- <div id="upload">
             <div class="form-line clearfix">
                 <div class="fl">
                     <span class="text-content"><em class="must"></em>故障图片：</span>
                     <input disabled id="xctp2" class="easyui-textbox"
                            data-options="required:false,validType:'length[0,128]'">
                 </div>
                 <div class="fl">
                     <form id="uploadForm2" class="form" action="" method="post" enctype="multipart/form-data">
                         <input type="file" name="myFile"  id="tp1"  multiple style="margin-left: -85px !important;"/>
                         <input type="button" id="submitPic2" value="上传"/>
                     </form>
                     <span id="uploadResultPic2" style="color:blue" class="text-content"></span>
                 </div>
             </div>
             <div class="form-line clearfix">--%>
                <%--<div class="fl">--%>
                    <%--<span class="text-content"><em class="must"></em>视频地址：</span>--%>
                    <%--<input disabled id="xcsp" class="easyui-textbox"--%>
                           <%--data-options="required:false,validType:'length[0,128]'">--%>
                <%--</div>--%>
                <%--<div class="fl">--%>
                    <%--<form id="uploadFormVideo" class="form" action="" method="post" enctype="multipart/form-data">--%>
                        <%--<input type="file" name="myFile" id="tpid" multiple/>--%>
                        <%--&lt;%&ndash;<input type="button" id="submitVideo" value="上传"/>&ndash;%&gt;--%>
                        <%--&lt;%&ndash;故障图片&ndash;%&gt;--%>
                        <%--<input type="file" name="myFile"  id="tp"  multiple style="margin-left: -85px !important;"/>--%>
                        <%--<input type="button" id="submitVideo" value="上传"/>--%>
                    <%--</form>--%>
                    <%--<span id="uploadResultVideo" class="text-content" style="color:blue"></span>--%>
                <%--</div>--%>
            <%--</div>--%>
        </div>
    </form>
</div>
</div>
</body>
</html>
<script type="text/javascript">
    var sel = {};
    var winId = $.getUrlParam("winId");
    var jobid = $.getUrlParam("jobid");
    var isdelayatbefor = false;
    var alarmeventinfo = {};
    var alarmsubtypeObj = [];
    var devicetypedata = [{"id": "", "text": "全部", "selected": true}];
    var alarmLevelArr = [{"id": "", "text": "全部", "selected": true}];
    var alarmsource = [{"id": "", "text": "全部", "selected": true}];
    $(function () {
        $.ajax({
            url: " xtclAction!query_Xtcl_task.do",
            type: "post",
            dataType: "JSON",
            data: {"csdl": "nhywjtsblx,ywAlarmRuleLevel"},
            success: function (res) {
                //	console.log(res);
                if (res && res.length > 0) {
                    for (i in res) {
                        if (res[i].csdl == "nhywjtsblx") {
                            devicetypedata.push({"id": res[i].csdm, "text": res[i].csmc});
                        } else if (res[i].csdl == "ywAlarmRuleLevel") {
                            alarmLevelArr.push({"id": res[i].csdm, "text": res[i].csmc});
                        }
                    }
                }
                //根据选择的设备类型加载设备信息
                $('#alarmdevicetype').combobox({
                    data: devicetypedata,//加载数据
                    valueField: 'id',
                    textField: 'text',
                    //onselect事件查询设备信息
                    onChange: function (record) {
                        if (record== '1') {
                            //如果选择的是监控
                            $("#machine").css("display", "none");
                            $("#videoparam").css("display", "block");
                            $("#upload").css("display", "block");

                        } else  {
                            $("#machine").css("display", "block");
                            $("#videoparam").css("display", "none");
                            $("#upload").css("display", "none");
                        }
                    }
                });
                $('#alarrulename').combobox({
                    data: devicetypedata,//加载数据
                    valueField: 'id',
                    textField: 'text',
                    onChange: function (n, o) {
                        if (!isNull(n)) {
                            $('#alarmsubtypes').combobox('clear');//清空选中项
                            $('#alarmsubtypes').combobox('loadData', {});//清空option选项
                            $('#alarmsubtypes').combobox({
                                url: 'xtclAction!queryXtcl_alarm.do?startLIKEcsdm=' + n,
                                valueField: 'csdm',
                                textField: 'csmc'
                            });
                        }
                    }
                });
                $('#alarmgrade').combobox({
                    data: alarmLevelArr,//加载数据
                    valueField: 'id',
                    textField: 'text'
                });
            }
        });

        $('#machineid').combobox({
            url: 'ywmachineinfoAction!query_Ywmachineinfo.do',
            textField: "machinename",
            valueField: "machineid",
            panelWidth: 148,
            value: ""
        });
        $("#faultoccurtime").datetimebox("setValue", $.getTodayStart(0, "00:00:00"));
        // 确认  反馈人相关信息
        $('#jobacceptcompany').combobox({				// 确认反馈单位
            url: 'ywrepairjobinfoAction!getReportBm.do',    // 查询有审批工单权限的部门
            textField: "bmmc",
            valueField: "bmbh",
            panelWidth: 148,
            value: ""
        });
        $("#jobacceptcompany").combobox({
            onChange: function (n, o) {
                $('#jobreportpeople').combobox({				// 选取确认反馈人
                    url: 'ywrepairjobinfoAction!getReportUser.do?bmbh=' + n,    // 查询部门下有审批工单权限的人
                    textField: "yhmc",
                    valueField: "yhzh",
                    value: ""
                });
            }
        })
        // 点击确认提交数据
        parent.parent.$(".l-btn-text").on("click", function () {
            if ($(this).text() == "确定") {
                //新增到库中
                saveInfo();
            }
        })
    });

    function doSearch() {
        //channelSmallType
        var param = {
            LIKEsbbh: $('#sbbh').textbox('getValue'),
            LIKEtdmc: $('#tdmc').textbox('getValue'),
            tdlx: $('#tdlx').combobox('getValue')
        };
        $('#tableGrid').datagrid('options').url = "sbtdspsrAction!query_Sbtdspsr_ext.do";
        $("#tableGrid").datagrid('load', param);
    }

    function selectGys() {
        var url = "";
        if (top.sysUrl) {
            url = top.sysUrl + "/yw/ptxztree/ptxzs_show.jsp";
        }
        //判断当前选中设备
        var devicetyp = $('#alarmdevicetype').combobox("getValue");
        switch (devicetyp) {
            case "2":
                url = top.sysUrl + "/yw/homepage/deviceinfo/ywmachineinfochose.jsp";
                break;
            case "3":
                url = top.sysUrl + "/yw/homepage/deviceinfo/nhywjtxhdglstate.jsp";
                break;
            case "4":
                url = top.sysUrl + "/yw/homepage/deviceinfo/nhywjtydpglstate.jsp";
                break;
            case "10"://地磁
                url = top.sysUrl + "/yw/homepage/deviceinfo/detectorstate.jsp?detectortype=GVD";
                break;
            case "11"://微波
                url = top.sysUrl + "/yw/homepage/deviceinfo/detectorstate.jsp?detectortype=SMARTSENSOR";
                break;
            case "12"://雷达
                url = top.sysUrl + "/yw/homepage/deviceinfo/zxldstate.jsp";
                break;

        }
        gysWin = top.$.createWin({
            title: "设备",
            width: 800,
            height: 500,
            url: url,
            buttons: [{
                text: $.fn.textbox.defaults.ok,
                handler: doUpdateGysValue
            }]
        });
        $(GETWIN(gysWin)).destroy();
    }



    function doUpdateGysValue() {
        var win = $.getTopWindowById(gysWin);
        var devicetyp = $('#alarmdevicetype').combobox("getValue");
        if (devicetyp == '1') {
            var selRows_no = win.$('#noCodeSearch').datagrid('getSelections');
            var selRows_out = win.$('#outCodeSearch').datagrid('getSelections');
            if (selRows_no.length <= 0 && selRows_out.length <= 0) {
                $.showMsg('请先选择一条记录! ');
                return;
            }
            if (selRows_no.length > 1) {
                $.showMsg('选择记录数量大于1! ');
                return;
            }
            if (selRows_no.length > 0) {
                for (var i = 0; i < selRows_no.length; i++) {
                    alarmeventinfo.alarmdeviceid = selRows_no[i].sbbh;
                    $("#gysmc").textbox("setValue", selRows_no[i].tdmc);
                    $("#LIKEtdbh").textbox("setValue", selRows_no[i].tdbh);
                    $("#sbbh").textbox("setValue", selRows_no[i].sbbh);
                }
            }
            if (selRows_out.length > 0) {
                for (var i = 0; i < selRows_out.length; i++) {
                    alarmeventinfo.alarmdeviceid = selRows_out[i].sbbh;
                    $("#gysmc").textbox("setValue", selRows_out[i].tdmc);
                    $("#LIKEtdbh").textbox("setValue", selRows_out[i].tdbh);
                    $("#sbbh").textbox("setValue", selRows_out[i].sbbh);
                }
            }
        } else {
            var selRows = win.$('#tableGrid').datagrid('getSelections');
            if (selRows.length <= 0 && selRows_out.length <= 0) {
                $.showMsg('请先选择一条记录! ');
                return;
            }
            if (selRows.length > 1) {
                $.showMsg('选择记录数量大于1! ');
                return;
            }
            if (selRows.length > 0) {
                for (var i = 0; i < selRows.length; i++) {
                    switch (devicetyp) {
                        case '2':
                            alarmeventinfo.alarmdeviceid = selRows[i].machineid;
                            $("#sbbh").textbox("setValue", selRows[i].machineid);
                            $("#gysmc").textbox("setValue", selRows[i].machinename);
                            break;
                        case '3':
                            alarmeventinfo.alarmdeviceid = selRows[i].xh;
                            $("#sbbh").textbox("setValue", selRows[i].xh);
                            $("#gysmc").textbox("setValue", selRows[i].xhdmc);
                            break;
                        case '4':
                            alarmeventinfo.alarmdeviceid = selRows[i].xh;
                            $("#sbbh").textbox("setValue", selRows[i].xh);
                            $("#gysmc").textbox("setValue", selRows[i].ledmc);
                            break;
                        case '10':
                        case '11':
                            alarmeventinfo.alarmdeviceid = selRows[i].id;
                            $("#sbbh").textbox("setValue", selRows[i].id);
                            $("#gysmc").textbox("setValue", selRows[i].name);
                            break;
                        case '12':
                            alarmeventinfo.alarmdeviceid = selRows[i].xh;
                            $("#sbbh").textbox("setValue", selRows[i].xh);
                            $("#gysmc").textbox("setValue", selRows[i].ldmc);
                            break;
                    }
                }
            }
        }
        top.$("#" + gysWin).dialog("close");
    }




    // $("#submitPic2").on('click', function () {
    //     $.ajax({
    //         url: "uploadPictureAction!uploadPicture.do",
    //         type: "POST",
    //         data: new FormData($('#uploadFormVideo')[0]),//$( '#uploadForm1').serialize(),    //表单序列化 ,【注意】上传文件的文件流是无法被序列化并传递的
    //         processData: false,   //  告诉jquery不要处理发送的数据
    //         contentType: false,    // 告诉jquery不要设置content-Type请求头
    //         success: function (data) {
    //             if (data && data != "error") {
    //                 $.showMsg("上传成功");
    //                 $("#xctp2").textbox("setValue", data);
    //                 $("#uploadResultPic2").text("上传成功");
    //             } else {
    //                 $.showMsg("上传失败");
    //                 $("#uploadResultPic2").text("上传失败");
    //             }
    //             //$("#uploadForm2").resetForm();
    //         }
    //     });
    // });
    // $("#submitVideo").on('click', function () {
    //     var formData = new FormData(); //创建了空FormData对象，手动封装需要的数据
    //     if($("#uploadFormVideo")[0].files.length==1){ //如果只上传了一张图片
    //         formData.append("myFile",$("#uploadFormVideo")[0].files[0]);
    //         //第一个参数代表后台文件属性名，第二个参数表示html中input的id
    //     }else{
    //         for(var i=0; i<$("#f_upload")[0].files.length;i++){ //如果上传了多张图片
    //             formData.append("myFile",$("#uploadFormVideo")[0].files[i]); //多个文件上传
    //         }
    //     }
    //     $.ajax({
    //         url: "uploadPictureAction!uploadPicture.do",
    //         type: "POST",
    //         data: formData,//$( '#uploadForm1').serialize(),    //表单序列化 ,【注意】上传文件的文件流是无法被序列化并传递的
    //         processData: false,   //  告诉jquery不要处理发送的数据
    //         contentType: false,    // 告诉jquery不要设置content-Type请求头
    //         success: function (data) {
    //             if (data && data != "error") {
    //                 $.showMsg("上传成功");
    //                 $("#xcsp").textbox("setValue", data);
    //                 $("#uploadResultVideo").text("上传成功");
    //             } else {
    //                 $.showMsg("上传失败");
    //                 $("#uploadResultVideo").text("上传失败");
    //             }
    //             //$("#uploadFormVideo").resetForm();
    //         }
    //     });
    //
    // });

    function saveInfo() {
        // 数据入库
        if (isNull($("#alarrulename").combobox("getValue"))) {
            top.$.dlg.alertError('告警不能为空! ');
            return;
        }
        alarmeventinfo.alarmdevicename = $('#gysmc').combobox("getText");
        alarmeventinfo.alarmdevicetype = parseInt($('#alarmdevicetype').combobox("getValue"));


           if (isNull($("#alarmgrade").combobox("getValue")))
        {
            top.$.dlg.alertError('告警等级不能为空! ');
            return;
        }
        if (alarmeventinfo.alarmdevicetype == "1")  {
            if (isNull($("#sbbh").textbox("getValue"))) {
                top.$.dlg.alertError('设备不能为空! ');
                return;
            }
            alarmeventinfo.channelnum = parseInt($("#LIKEtdbh").textbox("getValue"));
            //alarmeventinfo.pictureurl = $("#xctp2").textbox("getValue");
           // alarmeventinfo.videourl = $("#xcsp").textbox("getValue");
        }

        alarmeventinfo.alarmgrade = parseInt($("#alarmgrade").combobox("getValue"));
        alarmeventinfo.alarmrulename = $("#alarrulename").combobox("getText");
        alarmeventinfo.alarmtype= $("#alarrulename").combobox("getValue");
        alarmeventinfo.alarmreason = $("#falutdescription").val();
        alarmeventinfo.alarmtime = $('#faultoccurtime').datetimebox('getValue');
        alarmeventinfo.alarmsubtypecode = $('#alarmsubtypes').combobox("getValue");
        alarmeventinfo.alarmsubtypename = $('#alarmsubtypes').combobox("getText");
        alarmeventinfo.processstatus = 900;
        $.ajax({
            url: "ywalarmeventinfoAction!insert_Ywalarmeventinfo.do",
            type: "POST",
            dataType: "JSON",
            data: alarmeventinfo,
            success: function (res) {
                if (res == 'success') {
                    $.showMsg("操作成功");
                    top.$("#" + winId).dialog('close');
                }
            }
        })
    }

    function isNull(str) {
        if (str == null || str == '' || str == " " || str == "null" || str == undefined) {
            return true;
        } else {
            return false;
        }
    }

</script>