usersNoticeList.html 9.61 KB
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>Yoho!Buy运营平台</title>
    <script src="/ufoPlatform/js/include.js"></script>
    <script src="/ufoPlatform/js/ajaxfileupload.js"></script>
</head>
<body class="easyui-layout" fit="true">
<div region="north" style="height: 230px">
    <script>
        document.write(addHead('卖家中心/公告管理', ''));
    </script>
    <style>
        .div_search input {
            margin-top: 20px;
        }

        .div_search .textbox {
            margin-top: 20px;
        }

        .div_search .easyui-linkbutton {
            margin-top: 20px;
        }
    </style>
    <div style="margin-left: 30px;" class="div_search">
        <a id="addNotice" class="easyui-linkbutton btn-success">添加一条</a>
    </div>
</div>
<div region="center">
    <div style="margin-left: 30px;margin-top: 20px;height: 660px">
        <table id="noticeListTable"></table>
    </div>
</div>

<script type="text/javascript">
    var userNoticeId;
    $(function () {
        $('#addNotice').linkbutton({
            iconCls: "icon-edit",
            onClick: function () {
                editRow(0);
            }
        });

        $("#noticeListTable").myDatagrid({
            fit: true,
            fitColumns: true,
            nowrap: false,
            url: contextPath + "/usersNotice/getNoticeList",
            method: 'POST',
            loadFilter: function (data) {
                var temp = defaultLoadFilter(data);
                temp.rows = temp.list;
                return temp;
            },
            columns: [[{
                title: "ID",
                field: "id",
                width: 20,
                align: "center"
            }, {
                title: "公告名称",
                field: "name",
                width: 300,
                align: "center"
            }, {
                title: "是否开启滚动通知",
                field: "showFront",
                width: 40,
                align: "center",
                formatter: function (value) {
                    if (value == 1) {
                        return "开启";
                    } else if(value == 0){
                        return "关闭";
                    }
                }
            },{
                title: "排序",
                field: "orderBy",
                width: 40,
                align: "center"
            },{
                title: "创建时间",
                field: "createTimeStr",
                width: 80,
                align: "center"
            }, {
                title: "操作",
                field: "operations",
                width: 80,
                align: "center",
                formatter: function (value, rowData) {
                    var str = "<a role='edit' dataId='" + rowData.id + "'  style='margin-left:10px;background-color: #5bc0de'>编辑</a>";
                    str += "<a role='del' dataId='" + rowData.id + "' style='margin-left:10px;background-color: red'>删除</a>";
                    return str;
                }
            }]],
            cache: false,
            pagination: true,
            pageSize: 10,
            pageList: [10,30,50],
            idField: "id",
            singleSelect: false,
            checkOnSelect: false,
            onLoadSuccess: function () {
                // 编辑
                $(this).myDatagrid("getPanel").find("a[role='edit']").linkbutton({
                    iconCls: "icon-edit",
                    onClick: function () {
                        var id = $(this).attr("dataId");
                        editRow(id);
                    }
                });
                // 删除
                $(this).myDatagrid("getPanel").find("a[role='del']").linkbutton({
                    iconCls: "icon-more",
                    onClick: function () {
                        del($(this).attr("dataId"));
                    }
                });
            }
        });


        function editRow(id) {
            userNoticeId = id;
            var div = $("<div>").appendTo($(document.body));
            var title = "编辑";
            var message = "确认修改吗?";
            if (id == 0) {
                title = "添加";
                message = "确认添加吗?";
            }
            $(div).myDialog({
                width: "680px",
                height: "450px",
                title: title,
                href: contextPath + "/html/usersNotice/editUsersNotice.html?time_version=" + new Date().getTime(),
                queryParams: {
                    id: id
                },
                modal: true,
                collapsible: true,
                cache: false,
                buttons: [{
                    id: "saveBtn",
                    text: "保存",
                    handler: function () {
                        $.messager.confirm("确认", message, function (flag) {
                            if (flag) {
                                var name = $('#usersNoticeEditForm #name').val();
                                if (name == '' || name == null || name == undefined) {
                                    $.messager.alert("提示", '公告名称不能为空!', "error");
                                    return false;
                                }
                                var url = $('#usersNoticeEditForm #url').val();
                                if (url == '' || url == null || url == undefined) {
                                    $.messager.alert("提示", '跳转页面不能为空!', "error");
                                    return false;
                                }
                                var orderBy = $('#usersNoticeEditForm #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";
                                $("#usersNoticeEditForm").form("submit", {
                                    url: url,
                                    onSubmit: function () {
                                        if (!$("#usersNoticeEditForm").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");
                    }
                }]
            });
        }

        function del(id) {
            var message = "确定要删除吗?";
            var msg = "删除成功";
            $.messager.confirm("确认", message, function (flag) {
                if (flag) {
                    $.messager.progress({
                        title: "正在执行",
                        msg: "正在执行,请稍后...",
                        interval: 500,
                        text: ""
                    });
                    $.post(contextPath + "/usersNotice/delNoticeById", {
                        "id": id
                    }, function (data) {
                        $.messager.progress("close");
                        if (data.code == 200) {
                            $("#noticeListTable").myDatagrid("reload");
                            $.messager.show({
                                title: "提示",
                                msg: msg,
                                height: 120
                            });
                        } else {
                            $.messager.alert("失败", data.message, "error");
                        }
                    }, "json");
                }
            });
        }
    });


</script>

</body>
</html>