"use strict";
layui.extend({
    common    :   'js/common'
}).use(['jquery','layer','common','form'],function () {
    var $ = layui.jquery;

    layui.form.on("submit(entity_submit_event)",function(data){
        var entity = data.field;
        if (!entity.id){
            layer.msg("参数异常");
            return;
        }
        if (!entity.value){
            layer.msg("请输入阈值");
            return;
        }
        $.ajax({
            url : '/ad/threshold_config/edit',
            type : 'POST',
            data : entity
        }).then(function (result) {
            if (result.code === '200'){
                $('button[type="reset"]').click();
                parent.location.reload();
            } else {
                layer.alert(result.msg);
            }
        });
    });

    $('button[type="reset"]').on('click',function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    });

});
