promotionList.html 19 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
<!DOCTYPE html>
<html lang="en">
<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">

<div region="north" style="height:260px;">
    <script>
        document.write(addHead('促销管理', '促销活动'));
    </script>
    <style>
        .div_search input {
            margin-top: 20px;
        }

        .div_search .easyui-linkbutton {
            margin-top: 20px;
        }
    </style>
    <div style="margin-left: 30px;" class="div_search">
        <a id="addBtn" class="easyui-linkbutton btn-success">新建</a>
    </div>
    <div style="padding:20px;">
        <label>ID:</label>
        <input id="id" type="text" class="easyui-numberbox" style="width:150px" data-options="min:0,precision:0,prompt:'ID'">

        <label>促销名称:</label>
        <input id="activityName" type="text" class="easyui-textbox" style="width:150px" data-options="prompt:'促销名称'"/>

        <label>状态:</label>
        <select id="status" class="easyui-combobox" name="status" style="width:150px;" data-options="prompt:'状态',panelHeight:80">
            <option value="1">未开始</option>
            <option value="2">进行中</option>
            <option value="3">已结束</option>
            <option value="4">已关闭</option>
        </select>
        <a id="searchBtn" class="btn-info">筛选</a>
        <a id="allBtn" class="btn-success">全部</a>
    </div>
</div>

<div region="center">
    <div style="margin-left: 30px;margin-top: 20px;height: 660px">
        <table id="promotionActivityTable"></table>
    </div>
</div>

<script>
    $(function() {

        $("#status").combobox({
            editable: false,
            panelHeight : 130
        });

        $('#status').combobox('clear');

        $('#allBtn').linkbutton({
            iconCls: 'icon-search',
            onClick: function () {
                $('#id').numberbox('clear');
                $('#activityName').textbox('clear');
                $('#status').combobox('clear');
                var param = {};
                $("#promotionActivityTable").myDatagrid("load", param);
            }
        });

        $('#searchBtn').linkbutton({
            iconCls: 'icon-search',
            onClick: function () {
                debugger;
                var param = getParams();
                $("#promotionActivityTable").myDatagrid("load", param);
            }
        });

        $('#addBtn').linkbutton({
            iconCls: 'icon-add',
            width : 70,
            height : 40,
            onClick: function () {
                edit(0);
            }
        });

        $("#promotionActivityTable").myDatagrid({
            fit: true,
            fitColumns: true,
            nowrap: false,
            url: contextPath + "/PromotionController/getPromotionList",
            method: 'POST',
            loadFilter: function (data) {
                var temp = defaultLoadFilter(data);
                temp.rows = temp.list;
                return temp;
            },
            columns: [[{
                title: "ID",
                field: "id",
                width: 40,
                align: "center"
            }, {
                title: "促销名称",
                field: "activityName",
                width: 80,
                align: "center"
            }, {
                title: "促销类型",
                field: "promotionTypeStr",
                width: 80,
                align: "center"
            }, {
                title: "活动开始时间",
                field: "startTimeStr",
                width: 80,
                align: "center"
            },{
                title: "活动结束时间",
                field: "endTimeStr",
                width: 80,
                align: "center"
            },{
                title: "状态",
                field: "statusStr",
                width: 80,
                align: "center"
            },{
                title: "操作",
                field: "operations",
                width: 80,
                align: "center",
                formatter: function (value, rowData) {
                    var str = "<a role='view' dataId='" + rowData.id + "'  style='margin-left:10px;background-color: #5bc0de'>查看</a>";
                    str += "<a role='edit' dataId='" + rowData.id + "' style='margin-left:10px;background-color: #e68900'>编辑</a>";
                    if(rowData.status == 1){
                        str += "<a role='close' dataId='" + rowData.id + "' style='margin-left:10px;background-color: red'>关闭</a>";
                    }else if(rowData.status == 2){
                        str += "<a role='open' dataId='" + rowData.id + "' style='margin-left:10px;background-color: green'>开启</a>";
                    }
                    return str;
                }
            }]],
            cache: false,
            pagination: true,
            pageSize: 10,
            pageList: [10],
            idField: "id",
            singleSelect: false,
            checkOnSelect: false,
            onLoadSuccess: function () {
                // 查看
                $(this).myDatagrid("getPanel").find("a[role='view']").linkbutton({
                    iconCls: "icon-view",
                    onClick: function () {
                        var id = $(this).attr("dataId");
                        view(id);
                    }
                });

                // 编辑
                $(this).myDatagrid("getPanel").find("a[role='edit']").linkbutton({
                    iconCls: "icon-edit",
                    onClick: function () {
                        var id = $(this).attr("dataId");
                        edit(id);
                    }
                });
                // 开启
                $(this).myDatagrid("getPanel").find("a[role='open']").linkbutton({
                    iconCls: "icon-more",
                    onClick: function () {
                        updateStatus($(this).attr("dataId"),1);
                    }
                });

                // 关闭
                $(this).myDatagrid("getPanel").find("a[role='close']").linkbutton({
                    iconCls: "icon-more",
                    onClick: function () {
                        updateStatus($(this).attr("dataId"),2);
                    }
                });
            }
        });


        function getParams() {
            debugger;
            var id = $('#id').numberbox('getValue');
            var activityName = $('#activityName').textbox('getText');
            var status = $('#status').combobox('getValue');
            var param = {};
            if (undefined !== id && 0 !== id && "" !== id) {
                param.id = id;
            }
            if (undefined !== activityName && null !== activityName && "" !== activityName) {
                param.activityName = activityName;
            }
            if (undefined !== status && null !== status && "" !== status) {
                param.status = status;
            }
            return param;
        }

        function view(id){
            paramObject.promotionId = id;
            var div = $("<div>").appendTo($(document.body));
            var title = "查看促销活动";
            $(div).myDialog({
                width: "60%",
                height: "90%",
                title: title,
                href: contextPath + "/html/promotionManage/promotionEdit.html",
                modal: true,
                collapsible: true,
                cache: false,
                buttons: [{
                    text: "关闭",
                    iconCls: "icon-cancel",
                    handler: function () {
                        $(div).dialog("close");
                    }
                }]
            });
        }

        function edit(id) {
            paramObject.promotionId = id;
            var div = $("<div>").appendTo($(document.body));
            var title = id == 0 ? "新增促销" : "编辑促销";
            $(div).myDialog({
                width: "60%",
                height: "90%",
                title: title,
                href: contextPath + "/html/promotionManage/promotionEdit.html",
                modal: true,
                collapsible: true,
                cache: false,
                buttons: [{
                    id: "saveBtn",
                    text: "发布",
                    handler: function () {
                        var url = contextPath + "/PromotionController/saveOrUpdatePromotion";
                        $("#promotionEditForm").form("submit", {
                            url: url,
                            onSubmit: function (param) {
                                var initStatus = $("#promotionEditForm #initStatus").combobox("getValue");
                                if( initStatus == ""){
                                    $.messager.alert("提示", "请选择活动是否开启", "error");
                                    return false;
                                }
                                if($("#promotionEditForm #productScopeType").combobox("getValue") == ""){
                                    $.messager.alert("提示", "请选择商品使用范围", "error");
                                    return false;
                                }
                                //组装商品范围
                                var productScope;
                                var scopeJson = {};
                                var productScopeType = $("#promotionEditForm #productScopeType").combobox("getValue");
                                var scopeValue = $("#promotionEditForm #limitValues").val();
                                var limitType =$("#promotionEditForm #limitType").combobox("getValue");
                                if(productScopeType == 2 && (scopeValue == ""  || limitType == "")){
                                    $.messager.alert("提示", "请输入商品池限制条件", "error");
                                    return false;
                                }
                                scopeJson["productScopeType"] = productScopeType;
                                scopeJson["limitType"] = limitType;
                                scopeJson["scopeValue"] = scopeValue;
                                productScope = JSON.stringify(scopeJson);

                                //组装促销类型限定金额参数
                                var promotionTypeParamses = "";
                                var limitJson = {};
                                if($("#promotionEditForm #promotionType").combobox("getValue") == 1){
                                    //满减
                                    var crashLimitCount = $("#promotionEditForm #addLimitCount").val();
                                    for(var j = 1;j <= crashLimitCount;j++){
                                        if($("#promotionEditForm" + " #limitAmount_" + j).length == 0){
                                            continue;
                                        }
                                        var limitAmount = $("#promotionEditForm" + " #limitAmount_" + j).numberbox("getValue");
                                        var offerAmount = $("#promotionEditForm" + " #offerAmount_" + j).numberbox("getValue");
                                        if(limitAmount == ""){
                                            continue;
                                        }
                                        if(offerAmount == ""){
                                            continue;
                                        }

                                        limitJson["limitAmount"] = limitAmount;
                                        limitJson["offerAmount"] = offerAmount;
                                        if(j == crashLimitCount){
                                            promotionTypeParamses = promotionTypeParamses + JSON.stringify(limitJson);
                                        }else{
                                            //接口通过"-" 解析
                                            promotionTypeParamses = promotionTypeParamses + JSON.stringify(limitJson) + "-";
                                        }

                                    }

                                }else if($("#promotionEditForm #promotionType").combobox("getValue") == 2){
                                    //折扣
                                    var limitAmount0 = $("#promotionEditForm #limitAmount_0").numberbox("getValue");
                                    var offerAmount0 = $("#promotionEditForm #offerAmount_0").numberbox("getValue");
                                    var offerMaxLimit = $("#promotionEditForm #offerMaxLimit").numberbox("getValue");
                                    if(limitAmount0 == "" || offerAmount0 == "" || offerMaxLimit == "") {
                                        $.messager.alert("提示", "折扣的三个参数不可为空!", "error");
                                        return false;
                                    }

                                    limitJson["limitAmount"] = limitAmount0;
                                    limitJson["offerAmount"] = offerAmount0;
                                    limitJson["offerMaxLimit"] = offerMaxLimit;
                                    promotionTypeParamses = JSON.stringify(limitJson);
                                }
                                if(promotionTypeParamses == ""){
                                    $.messager.alert("提示", "请填写完成促销参数!", "error");
                                    return false;
                                }

                                //组装购买渠道
                                var businessClient = "";
                                var businessClientCheck = $("#promotionEditDiv").find("input:checked[name='businessClient']");
                                if(businessClientCheck != null){
                                    $(businessClientCheck).each(function (index, item) {
                                            businessClient = businessClient + $(item).val() + ",";
                                    });
                                }
                                if(businessClient == ""){
                                    $.messager.alert("提示","请选择购买渠道!", "error");
                                    return false;
                                }

                                //组装可用订单类型
                                var  productLimitType = "";
                                if($("#promotionEditForm #isAll").prop('checked') == true){
                                    var values = $("#promotionEditDiv").find("input:checkbox[name='productLimitChose']");
                                    for(var k = 0; k < values.length; k++){
                                        productLimitType = productLimitType + values[k].value + ",";
                                    }

                                }else{
                                    var checkedTypes = $("#promotionEditDiv").find("input:checked[name='productLimitChose']");
                                    if(checkedTypes != null){
                                        $(checkedTypes).each(function (index, item) {
                                            productLimitType = productLimitType + $(item).val() + ",";
                                        });
                                    }
                                }
                                if(productLimitType == ""){
                                    $.messager.alert("提示", "请选择可用订单类型!", "error");
                                    return false;
                                }

                                if (!$("#promotionEditForm").form("validate")) {
                                    return false;
                                }
                                param.id = id;
                                param.promotionAmountConditions = promotionTypeParamses;
                                param.productTypeLimitList = productLimitType.substring(0,productLimitType.length - 1);
                                param.promotionProductScopes = productScope;
                                param.joinLimitType= 1;
                                param.initStatus = initStatus;
                                $.messager.progress({
                                    title: "正在执行",
                                    msg: "正在执行,请稍后..."
                                });

                                return true;
                            },
                            success: function (data) {
                                $.messager.progress("close");
                                data = JSON.parse(data);
                                if (data.code == 200) {
                                    $(div).dialog("close");
                                    $("#promotionActivityTable").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 updateStatus(id, status) {
            var message = status == 1 ? "确定开启该促销吗?" : "确定关闭该促销吗?";
            $.messager.confirm("确认", message, function (flag) {
                if (flag) {
                    $.messager.progress({
                        title: "正在执行",
                        msg: "正在执行,请稍后...",
                        interval: 500,
                        text: ""
                    });
                    $.post(contextPath + "/PromotionController/updateStatusById",{"id":id, "status":status}, function (data) {
                        $.messager.progress("close");
                        if (data.code == 200) {
                            $("#promotionActivityTable").myDatagrid("reload");
                            $.messager.show({
                                title: "提示",
                                msg: "操作成功!",
                                height: 120
                            });
                        } else {
                            $.messager.alert("失败", data.message, "error");
                        }
                    }, "json");
                }
            });
        }

    })

</script>

</body>
</html>