<style>
    .checked {
        color: red;
    }

    .detail-images > div {
        float: left;
        margin-right: 15px;
    }

        .detail-images > div > img {
            border: 1px solid #efefef;
            margin: 5px;
            padding: 5px;
        }

    .tdright {
        width: 180px !important;
    }
</style>

<script src="~/App_Scripts/Jquery/plugin/jquery.easyui/easyui-lang-zh_CN.js"></script>
<script src="~/App_Scripts/Jquery/plugin/jquery.easyui/validate/jeasyui.extensions.validatebox.rules.js"></script>

<script>
    //初始化
    $(function () {
        $('#EditForm').ajaxForm({
            beforeSubmit: function () {

                //遍历必填的文本框如果值为空就提示 并隐藏进度条
                $('#EditForm input').each(function () {
                    if (($(this).attr('required') != undefined || $(this).attr('validType') != undefined) && $(this).attr('class').toString().indexOf('easy') < 0) {
                        if (!$(this).validatebox('isValid')) {
                            alert($(this).parents("td").prev("th").html() + "数据异常！");
                            $.messager.progress('close');
                        }
                    }
                })

                //提交前验证
                var isValid = $('#EditForm').form('validate');
                if (!isValid) {
                    // 如果表单是无效的则隐藏进度条
                    $.messager.progress('close');
                }

                // 返回false终止表单提交
                return isValid;
            },
            success: function (data) {

                //提交成功后
                $.messager.progress('close');
                try {
                    data = $.parseJSON(data);
                } catch{

                }
                if (data.result.success) {
                    $.messager.alert('提示', data.result.message, 'info', function () {
                        window.parent.refreshGrid();
                        if (data.guid != undefined) {
                            window.setGuid(data.guid);
                        }
                    });
                } else {
                    $.messager.alert('错误', data.result.message, 'error');
                }

            },
            error: function (data) {

                alert(data);

                //提交失败
                $.messager.progress('close');
                $.messager.alert('错误', '页面提交发生错误，请联系管理员', 'error');
            },
            dataType: 'json'//数据格式
        });
    });

    $(function () {
        if ($.module_edit !== null) {
            $.module_edit.init();
        }

        GetLengthBind('F_SeoDescription', 160);
        GetLengthBind('F_SeoKeyWord', 160);
        GetLengthBind('F_SeoKeyWordaa', 160);
    });

    (function ($) {
        $.module_edit = {
            init: function () {
                var that = this;
                that.effect();
                that.radio_Handle();
                that.checkbox_Handle();
            },

            // 效果
            effect: function () {
                // 已选中单选、复选文字效果
                $('input[type="radio"]:checked,input[type="checkbox"]:checked').parent().addClass('checked');
            },

            // 单选按钮组处理
            radio_Handle: function () {
                $('input[type="radio"]').click(function () {
                    var $this = $(this),
                        this_name = $this[0].name;

                    $('input[name="' + this_name + '"]').parent().removeClass('checked');
                    $this.parent().addClass('checked');
                });
            },

            // 复选按钮组处理
            checkbox_Handle: function () {
                $('input[type="checkbox"]:not([name="chk_CheckCause"])').click(function () {
                    var $this = $(this),
                        this_name = $this[0].name,
                        // 已选中标签
                        $check_box = $('input[type="checkbox"][name="' + this_name + '"]:checked');

                    $('input[name="' + this_name + '"]').parent().removeClass('checked');
                    $check_box.parent().addClass('checked');
                });
            },
        };
    }(jQuery));

    $.extend($.fn.validatebox.defaults.rules, {
        multiple: {
            validator: function (value, vtypes) {
                var returnFlag = true;
                var opts = $.fn.validatebox.defaults;
                for (var i = 0; i < vtypes.length; i++) {
                    var methodinfo = /([a-zA-Z_]+)(.*)/.exec(vtypes[i]);
                    var rule = opts.rules[methodinfo[1]];
                    if (value && rule) {
                        var parame = eval(methodinfo[2]);
                        if (!rule["validator"](value, parame)) {
                            returnFlag = false;
                            this.message = rule.message;
                            break;
                        }
                    }
                }
                return returnFlag;
            }
        }
    });

    //添加
    function Add(ActionGUID) {
        Loading();
        $("#IsNew").val("True");
        $("#ActionGUID").val(ActionGUID);
        $("#EditForm").submit();
    }

    //编辑
    function Edit(ActionGUID) {
        Loading();
        $("#IsNew").val("False");
        $("#ActionGUID").val(ActionGUID);
        $("#EditForm").submit();
    }
</script>