$(function () {
    initSelect()

    $('#submit').click(function (){


        let obj = {}
        obj.minfuzhi = $("#minfuzhi").val()
        obj.maxfuzhi = $("#maxfuzhi").val()
        obj.mintime = $("#mintime").val()
        obj.maxtime = $("#maxtime").val()
        obj.minseverity = $("#minseverity").val()
        obj.maxseverity = $("#maxseverity").val()
       /* obj.eventType = $("select[name='eventType']").val()
        obj.eventReason = $("select[name='eventReason']").val()*/
        obj.triggerType = $("select[name='triggerType']").val()
        obj.fileflag = $("#fileflag").val()


        var test = /^\d+(\.{0,1}\d+){0,1}$/    //非负数
        let test2 = /^(\-|\+)?\d+(\.\d+)?$/ //所有数字

        if(obj.minfuzhi!='' && obj.minfuzhi!=null){
            if(!obj.minfuzhi.match(test)){
                layer.tips('请输入合法的值', '#minfuzhi', {
                    tips: [1, 'red'] //还可配置颜色
                });
                return
            }else {
                obj.minfuzhi = obj.minfuzhi/100
            }
        }
        if(obj.maxfuzhi!='' && obj.maxfuzhi!=null){
            if(!obj.maxfuzhi.match(test)){
                layer.tips('请输入合法的值', '#maxfuzhi', {
                    tips: [1, 'red'] //还可配置颜色
                });
                return
            }else {
                obj.maxfuzhi = obj.maxfuzhi/100
            }
        }
        if(obj.mintime!='' && obj.mintime!=null){
            if(!obj.mintime.match(test)){
                layer.tips('请输入合法的值', '#mintime', {
                    tips: [1, 'red'] //还可配置颜色
                });
                return
            }
        }
        if(obj.maxtime!='' && obj.maxtime!=null){
            if(!obj.maxtime.match(test)){
                layer.tips('请输入合法的值', '#maxtime', {
                    tips: [1, 'red'] //还可配置颜色
                });
                return
            }
        }

        if(obj.minseverity!='' && obj.minseverity!=null){
            if(!obj.minseverity.match(test2)){
                layer.tips('请输入合法的值', '#minseverity', {
                    tips: [1, 'red'] //还可配置颜色
                });
                return
            }
        }
        if(obj.maxseverity!='' && obj.maxseverity!=null){
            if(!obj.maxseverity.match(test2)){
                layer.tips('请输入合法的值', '#maxseverity', {
                    tips: [1, 'red'] //还可配置颜色
                });
                return
            }
        }

        window.parent.paramToVd(obj)
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    })

})

function initSelect(){
    $.ajax({
        type: 'post',
        url: '/pqs9000/device/getselect',
        data: {dictypeName: '暂降类型'},
        dataType: 'json',
        success: function (data) {
            $('#eventType').empty()
            var html = ''
            data.forEach(function (item) {
                let op = '<option value="' + item.dicIndex + '">' + item.dicName + '</option>'
                html += op;
            })
            $('#eventType').append(html)
            $('#eventType').fSelect();
        },
        error:function () {

        }

    })
    $.ajax({
        type: 'post',
        url: '/pqs9000/device/getselect',
        data: {dictypeName: '暂降原因'},
        dataType: 'json',
        success: function (data) {
            $('#eventReason').empty()
            var html = ''
            data.forEach(function (item) {
                let op = '<option value="' + item.dicIndex + '">' + item.dicName + '</option>'
                html += op;
            })
            $('#eventReason').append(html)
            $('#eventReason').fSelect();
        },error:function () {

        }

    })

    $('#triggerType').fSelect();

}
