layui.use(['form','layer'], function(){
    var form = layui.form,
    layer = layui.layer,
        $ = layui.jquery


    //监听提交
    form.on('submit(addType)', function(data){
        var field = data.field
        var msgname = field.msg_name
        var begin = field.value1
        var end =field.value2
        msgname=filterXSS(msgname);
        if(!/^[\u4E00-\u9FA5A-Za-z0-9_\s+]+$/gi.test(msgname)){
            layer.msg('请规范输入',{icon:2})
            return false
        }
        layer.confirm('确定提交吗？', function (index) {
            $.ajax({
                type: 'POST',
                dataType: "json",
                data:{
                    msgType:2,
                    value1:begin,
                    value2:end,
                    msgName:msgname.toString()
                },
                url: '/pqs9900/message/addMsgDicdata',
                success: function (data) {
                    if(data.code == 200){

                        parent.layer.closeAll()
                        window.parent.flushPage()
                        window.parent.msgTo()
                    }else {
                        layer.msg(data.message,{icon:2})
                    }
                    //***********关闭loading

                },
                error:function () {
                    layer.msg('请规范输入',{icon:2})
                }
            });

        })

        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)<=36))
                    sum=sum+1;
                else
                    sum=sum+2;
            }
            if (sum > 36) {
                return '最多只能36个字符或者18个中文字';
            }
        }
    });

})