layui.use(['form','jquery','layer','table','laydate'],function () {

    var layer = layui.layer,
        $ = layui.jquery,
        form = layui.form,
        table = layui.table,
        laydate = layui.laydate


    var DefaultObj ={

    }

    //监听查询按钮
    form.on('submit(sendMsg)', function(data){
        var str =data.field
        var phone =str.phone
        var content = str.content
        if(phone == '' ||phone == null || content =='' || content == null){
            return  false
        }
        content = filterXSS(content);
        layer.confirm('确认发送吗？',function () {
            var i;
            $.ajax({
                type: 'POST',
                dataType: "json",
                contentType:"application/x-www-form-urlencoded",
                url: '/pqs9900/message/sendMsg',
                data:{
                    phone:phone,
                    msg:content
                },
                beforeSend:function(){
                   i= layer.load()
                },
                success: function (data) {
                    if(data.code == 200){
                        layer.msg('发送成功',{icon:1})

                    }else {
                        layer.msg(data.message,{icon:2})
                    }
                    layer.close(i);
                },

            })
        })
        return false
    });

   //监听清空按钮
    $('#formId').on('click','#clears',function () {
        $('#formId')[0].reset();
        form.render();
        return false
    })



    form.verify({
        clength: function (value) {
            var i,sum;
            sum=0;
            for(i=0;i<value.length;i++){
                if ((value.charCodeAt(i)>=0) && (value.charCodeAt(i)<=1024))
                    sum=sum+1;
                else
                    sum=sum+2;
            }
            if (sum > 2048) {
                return '短信内容过长';
            }
        }
    });




})
