poolAndCodeList.html 12.3 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>
    <link rel="stylesheet" href="/ufoPlatform/css/iview.css">
</head>
<body class="easyui-layout" fit="true">
<div region="north" style="height: 230px">
    <script>
        document.write(addHead('资源管理 /详情banner', ''));
    </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="addPoolAndCode" class="easyui-linkbutton btn-success">新增活动配置</a>
    </div>
    <div style="margin-left: 30px;" class="div_search">
        <select id="status" class="easyui-combobox" style="width:150px;"  >
            <option value="">选择选择状态</option>
            <option value="1">开启</option>
            <option value="0">关闭</option>
            <option value="2">进行中</option>
            <option value="3">已失效</option>
        </select>

        <a id="searchLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">搜索</a>
        <a id="searchAllLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">全部</a>
    </div>
</div>
<div region="center">
    <div style="margin-left: 30px;margin-top: 20px;height: 660px">
        <table id="listTable"></table>
    </div>
</div>
<script type="text/javascript" src="/ufoPlatform/js/moment.min.js"></script>
<script type="text/javascript" src="/ufoPlatform/js/vue/vue-2.3.4.js"></script>
<script type="text/javascript" src="/ufoPlatform/js/iview.min.js"></script>
<script type="text/javascript">
    var searchWordId;
    var dataList;
    var info = {};
    var formData = {};
    $(function () {
        $("#searchWord").textbox({
            prompt: "搜索词"
        });
        $('#addPoolAndCode').linkbutton({
            iconCls: "icon-edit",
            onClick: function () {
                editRow(0);
            }
        });



        $("#listTable").myDatagrid({
            fit: true,
            fitColumns: true,
            nowrap: false,
            url: contextPath + "/resource/getPoolAndCodeList",
            method: 'POST',
            loadFilter: function (data) {
                var temp = defaultLoadFilter(data);
                temp.rows = temp.list;
                return temp;
            },
            columns: [[{
                title: "序号",
                field: "id",
                width: 40,
                align: "center"
            }, {
                title: "活动名称",
                field: "activityName",
                width: 80,
                align: "center"
            }, {
                title: "商品池",
                field: "poolId",
                width: 80,
                align: "center",
                formatter: function (value) {
                    if (value == 0) {
                        return "全部商品";
                    } else {
                        return value;
                    }
                }
            }, {
                title: "位置码",
                field: "code",
                width: 180,
                align: "center"
            },{
                title: "展示时间",
                field: "orderBy",
                width: 80,
                align: "center",
                formatter: function (value, rowData) {
                    console.log(rowData.startTime, rowData.endTime);
                    return moment(rowData.startTime*1000).format('YYYY-MM-DD H:mm:ss') + "至" + moment(rowData.endTime*1000).format('YYYY-MM-DD H:mm:ss');
                }
            },{
                title: "状态",
                field: "status",
                width: 80,
                align: "center",
                formatter: function (value, rowData) {
                    if (value == 0) {
                        return "关闭";
                    }

                    else if (value == 1) {
                        return "开启";
                    }

                    else if (value == 2) {
                        return "生效中";
                    }

                    else if (value == 3) {
                        return "已失效";
                    }
                }
            }, {
                title: "操作",
                field: "operations",
                width: 80,
                align: "center",
                formatter: function (value, rowData, index) {
                    var str = "";
                    var edit = "<a role='editor' data-id='" + rowData.id + "'  style='margin-left:10px;'>编辑</a>";
                    var open = "<a role='updateStatus' data-id='" + rowData.id + "' data-status='1'  style='margin-left:10px;'>开启</a>";
                    var close = "<a role='updateStatus' data-id='" + rowData.id + "' data-status='0'  style='margin-left:10px; background: #f00'>关闭</a>";

                    if (rowData.status == 0) {
                        str = edit + open;
                    }

                    else if (rowData.status == 1 || rowData.status == 2) {
                        str = close;
                    }

                    return str;
                }
            }]],
            cache: false,
            pagination: true,
            pageSize: 10,
            pageList: [10],
            idField: "id",
            singleSelect: false,
            checkOnSelect: false,
            onLoadSuccess: function (data) {
                dataList = data.list;
                // 编辑
                $(this).myDatagrid("getPanel").find("a[role='editor']").linkbutton({
                    iconCls: "icon-edit",
                    onClick: function () {
                        var id = $(this).data("id");
                        editRow(id);
                    }
                });

                // 开启/关闭
                $(this).myDatagrid("getPanel").find("a[role='updateStatus']").linkbutton({
                    iconCls: "icon-more",
                    onClick: function () {
                        var id = $(this).data("id");
                        var status = $(this).data("status");
                        updateStatus(id, status);
                    }
                });
            }
        });

        // 搜索
        $("#searchLinkButton").linkbutton({
            onClick: function () {
                var param = getParams();
                $("#listTable").myDatagrid("load", param);
            }
        });

        // 搜索全部
        $("#searchAllLinkButton").linkbutton({
            onClick: function () {
                $('#status').combobox('clear');
                var param = {};
                $("#listTable").myDatagrid("load", param);
            }
        });

        /**
         * 提取出搜索参数
         */
        function getParams() {

            // 状态
            var status = $('#status').combobox('getValue');
            var param = {};
            if (undefined !== status && null !== status && "" !== status) {
                param.status = status;
            }

            return param;
        }

        /**
         * 开启/关闭
         * @param id
         * @param status
         */
        function updateStatus(id, status) {
            // console.log(id, status);
            // return;
            $.ajax({
                url: contextPath + "/resource/updateStatus",
                type: "POST",
                dataType: "json",
                data: {
                    id: id,
                    status: status
                },
                success: function (data) {
                    $.messager.progress("close");
                    if (data.code == 200) {
                        $("#listTable").myDatagrid("reload");
                        $.messager.show({
                            title: "提示",
                            msg: "操作成功!",
                            height: 120
                        });
                    } else {
                        $.messager.alert("失败", data.message, "error");
                    }
                },
                error: function (err) {
                    console.log(err)
                },
                complete: function () {

                }
            })
        }

        /**
         * 新增/编辑
         * @param id
         */
        function editRow(id){
            var div = $("<div>").appendTo($(document.body));
            var title = "编辑活动";
            var message = "确认修改活动信息吗?";

            if (id == 0) {
                title = "添加活动";
                message = "确认添加活动吗?";
            } else {
                for(var key in dataList) {
                    if (dataList[key].id == id) {
                        info = dataList[key];
                        break;
                    }
                }
            }

            $(div).myDialog({
                width: "700px",
                height: "680px",
                title: title,
                href: contextPath + "/html/resourceManage/poolAndCodeEdit.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) {
                                if (formData.activityName == "") {
                                    $.messager.alert("提示", '请输入活动名称!', "error");
                                }

                                if (formData.code == "") {
                                    $.messager.alert("提示", '请输入资源位码!', "error");
                                }

                                if (formData.startTime == 0 || formData.startTime == 0) {
                                    $.messager.alert("提示", '请选择展示时间!', "error");
                                }
                                $.messager.progress({
                                    title: "正在执行",
                                    msg: "正在执行,请稍后..."
                                });
                                $.ajax({
                                    url: contextPath + "/resource/editPoolAndCode",
                                    type: "POST",
                                    dataType: "json",
                                    data: formData,
                                    success: function (data) {
                                        $.messager.progress("close");
                                        if (data.code == 200) {
                                            $(div).dialog("close");
                                            $("#listTable").myDatagrid("reload");
                                            $.messager.show({
                                                title: "提示",
                                                msg: title + "成功!",
                                                height: 120
                                            });
                                        } else {
                                            $.messager.alert("失败", data.message, "error");
                                        }
                                    },
                                    error: function (err) {
                                        console.log(err)
                                    },
                                    complete: function () {

                                    }
                                })
                            }
                        });
                    }
                }, {
                    text: "关闭",
                    iconCls: "icon-cancel",
                    handler: function () {
                        $(div).dialog("close");
                    }
                }]
            });
        }
    });


</script>

</body>
</html>