metaConfig.html 13.8 KB
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>Yoho!Buy运营平台</title>
    <script src="/ufoPlatform/js/include.js"></script>
    <style>
        .selected{background: #5bc0de; color:#fff; }
    </style>

    <style type="text/css">
        .nav li {float:left; list-style:none;}
        .nav li a{float:left;text-decoration:none;padding:0.2em 1.6em;border-right:1px solid white;color:black; font-size:14px;}
    </style>
</head>
<body class="easyui-layout">
<div region="north" style="height:240px;">
    <script>
        document.write(addHead('订单管理', '配置管理'));
    </script>
    <br>
    <div style="margin-left: 10px;margin-top: 30px">
        <hr style="border:1px solid #ddd;"><br>
        <div style="border:1px solid #ddd;border-radius:5px 5px 5px 5px;">
            <div style="margin-left: 10px;margin-top: 20px;margin-bottom: 20px">
                <label>订单编号:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
                <input id="code" type="text" class="easyui-textbox" style="width:150px">

                <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;标题:</label>
                <input id="title" type="text" class="easyui-textbox" style="width:150px"/>
                <a id="searchBtn" class="btn-info">查询</a>
                <a id="allBtn" class="btn-success">全部</a>
            </div>
        </div>
    </div>
</div>

<div id="orderList" region="center" style="margin-left: 10px;border:1px solid #ddd;border-radius:5px 5px 5px 5px;">
    <table id="configListTable"></table>
</div>

<script>
    var code;
    var keyValueMap = {};
    $(function() {

        $("#searchBtn").linkbutton({
            iconCls : "icon-search",
            onClick : function() {
                $("#configListTable").datagrid("load", {
                    code : $("#code").val(),
                    uid : $("#title").val(),
                });
            }
        });

        //全部按钮
        $("#allBtn").linkbutton({
            iconCls: "icon-import",
            onClick: function () {
                $("#code").textbox('setValue','');
                $("#uid").textbox('setValue','');
                $("#configListTable").datagrid("load", {
                });
            }
        });

        getOrderList();
    });

    function getOrderList(){
        $("#configListTable").myDatagrid({
            fit: true,
            fitColumns: true,
            striped: true,
            url: contextPath + "/metaConfig/list",
            method: 'POST',
            queryParams: {
            },
            loadFilter: function (data) {
                var temp = defaultLoadFilter(data);
                temp=null==temp?[]:temp;
                temp.rows = temp.list;
                return temp;
            },

            columns: [[{
                title: "编号",
                field: "code",
                width: 40
            },  {
                title: "标题",
                field: "title",
                align: "center",
                width: 40
            },  {
                title: "修改时间",
                field: "uid",
                align: "center",
                width: 40
            }, {
                title: "创建时间",
                field: "productName",
                align: "center",
                width: 40
            }, {
                title: "操作",
                field: "operations",
                align: "center",
                width: 40,
                formatter: function (value, rowData) {
                    var str = "<a role='detail' dataId='"+ rowData.code + "' style='margin-left:10px;background-color: #5cb85c !important;'>编辑</a>";
                    return str;
                }}
                ]],
            cache: false,
            pagination: true,
            pageSize: 10,
            idField: "id",
            singleSelect: true,
            onLoadSuccess: function () {
                var me = $(this);
                me.datagrid("getPanel").find("a[role='detail']").linkbutton({
                    onClick: function () {
                        code = $(this).attr("dataId");
                        editRow()
                    }
                });
            }
        });
    }

    function editRow() {
        var div = $("<div>").appendTo($(document.body));
        var title = "编辑";
        var message = "确认修改吗?";
        $(div).myDialog({
            width: "780px",
            height: "550px",
            title: title,
            href: contextPath + "/html/orderManage/editConfig.html?time_version=" + new Date().getTime(),
            modal: true,
            collapsible: true,
            cache: false,
            buttons: [{
                id: "saveBtn",
                text: "保存",
                handler: function () {
                    $.messager.confirm("确认", message, function (flag) {
                        if (flag) {
                            var a = toJSON();
                            delete a.id;
                            delete a.code;
                            delete a.title;
                            delete a.desc;
                            delete a.value;
                            //$('#value').val(JSON.stringify(a));
                            var url = contextPath + "/metaConfig/update";
                            var code = $('#metaConfigEditForm #code').val();
                            if (code == '' || code == null || code == undefined) {
                                $.messager.alert("提示", '编码不能为空!', "error");
                                return false;

                            }

                            var title = $('#metaConfigEditForm #title').val();
                            if (title == '' || title == null || title == undefined) {
                                $.messager.alert("提示", '标题不能为空!', "error");
                                return false;

                            }


                            for(key in keyValueMap){
                                var val = $("#metaConfigEditForm [name = '"+key+"']").val();
                                if (val == '' || val == null || val == undefined) {
                                    $.messager.alert("提示", keyValueMap[key] + '不能为空!', "error");
                                    return false;

                                }
                            }

                            $("#metaConfigEditForm").form("submit", {
                                url: url,
                                onSubmit: function () {
                                    if (!$("#metaConfigEditForm").form("validate")) {
                                        return false;
                                    }
                                    $.messager.progress({
                                        title: "正在执行",
                                        msg: "正在执行,请稍后..."
                                    });
                                    return true;
                                },
                                success: function (data) {
                                    $.messager.progress("close");
                                    data = JSON.parse(data);
                                    if (data.code == 200) {
                                        $(div).dialog("close");
                                        $("#noticeListTable").myDatagrid("reload");
                                        $.messager.show({
                                            title: "提示",
                                            msg: title + "成功!",
                                            height: 120
                                        });
                                    } else {
                                        $.messager.alert("失败", data.message, "error");
                                    }
                                }
                            });
                            /*var name = $('#metaConfigEditForm #name').val();
                            if (name == '' || name == null || name == undefined) {
                                $.messager.alert("提示", '公告名称不能为空!', "error");
                                return false;
                            }
                            var url = $('#metaConfigEditForm #url').val();
                            if (url == '' || url == null || url == undefined) {
                                $.messager.alert("提示", '跳转页面不能为空!', "error");
                                return false;
                            }
                            var orderBy = $('#metaConfigEditForm #orderBy').val();
                            if (orderBy == '' || orderBy == null || orderBy == undefined) {
                                $.messager.alert("提示", '排序不能为空!', "error");
                                return false;
                            }
                            var showFront = $('input[name="showFront"]:checked').val();
                            if (showFront == '' || showFront == null || showFront == undefined) {
                                $.messager.alert("提示", '请选择是否开启滚动通知!', "error");
                                return false;
                            }
                            var url = contextPath + "/usersNotice/saveOrUpdateNotice";
                            $("#metaConfigEditForm").form("submit", {
                                url: url,
                                onSubmit: function () {
                                    if (!$("#metaConfigEditForm").form("validate")) {
                                        return false;
                                    }
                                    $.messager.progress({
                                        title: "正在执行",
                                        msg: "正在执行,请稍后..."
                                    });
                                    return true;
                                },
                                success: function (data) {
                                    $.messager.progress("close");
                                    data = JSON.parse(data);
                                    if (data.code == 200) {
                                        $(div).dialog("close");
                                        $("#noticeListTable").myDatagrid("reload");
                                        $.messager.show({
                                            title: "提示",
                                            msg: title + "成功!",
                                            height: 120
                                        });
                                    } else {
                                        $.messager.alert("失败", data.message, "error");
                                    }
                                }
                            });*/
                        }
                    });
                }
            }, {
                text: "关闭",
                iconCls: "icon-cancel",
                handler: function () {
                    $(div).dialog("close");
                }
            }]
        });
    }

    /**
     * form表单转JSON格式
     */
    function toJSON() {
        var keyValues = $('#metaConfigEditForm').serializeArray();
        var pattern=/\[(\d+)\]/;
        var filter_keys = [],
            normal_keys = keyValues.filter(function (v, i) {
                if (~v.name.indexOf('.')||~pattern.test(v.name)) {
                    filter_keys.push(v);
                    return false
                }
                return true;
            })

        var resultJson = {};
        filter_keys.forEach(function (v, i, ary) {
            var v_ary = v.name.split('.'),
                v_last = v_ary.length - 1;

            var deal = function (obj, j, array) {
                var me = arguments.callee,
                    islast = j === v_last ? true : false;
                if (islast&&!pattern.test(array[j])) {
                    if(typeof obj =='array'){
                        return obj.push(v.value);
                    }else{
                        if(obj[array[j]]){
                            obj[array[j]]+=','+v.value||'';
                        }else{
                            obj[array[j]] = v.value || '';
                        }
                        return;
                    }
                }else if(islast&&pattern.test(array[j])){
                    var name = array[j].substr(0, array[j].indexOf('['));
                    var index = array[j].match(pattern)[1];
                    if (!obj[name]) {
                        obj[name] = [];
                    }
                    if (obj[name].length<= index) {
                        return obj[name].push(v.value||'');
                    }
                }
                var nextObj;
                if (pattern.test(array[j])) {
                    var name = array[j].substr(0, array[j].indexOf('['));
                    var index = array[j].match(pattern)[1];
                    if (!obj[name]) {
                        obj[name] = [];
                    }
                    if (obj[name].length<= index) {
                        nextObj={};
                        obj[name].push(nextObj);
                    }else{
                        nextObj=obj[name][index];
                    }
                } else {
                    if (!obj[array[j]]) {
                        obj[array[j]] = {};
                    }
                    nextObj=obj[array[j]];
                }
                return me(nextObj, j + 1, array);
            }
            deal(resultJson, 0, v_ary);
        });
        normal_keys.forEach(function (v) {
            resultJson[v.name] = v.value;
        });
        return resultJson;
    }
</script>
</body>
</html>