userCoupon.html 9.96 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">
        <input id="couponCode" type="text">
        <input id="uid" type="text">
        <a id="searchLinkButton" 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="couponTable"></table>
    </div>
</div>

<script type="text/javascript">
    var couponId;
    var userId;
    $(function () {
        $("#uid").textbox({
            prompt: "UID"
        });
        $("#couponCode").textbox({
            prompt: "单券号"
        });
        $("#couponTable").myDatagrid({
            fit: true,
            fitColumns: true,
            nowrap: false,
            url: contextPath + "/coupon/queryUserCouponList",
            method: 'POST',
            loadFilter: function (data) {
                var temp = defaultLoadFilter(data);
                temp.rows = temp.list;
                return temp;   //couponAmount
            },
            columns: [[{
                title: "UID",
                field: "uid",
                width: 40,
                align: "center"
            },{
                title: "优惠券ID",
                field: "couponId",
                width: 40,
                align: "center"
            },{
                title: "单券号",
                field: "couponCode",
                width: 100,
                align: "center"
            },{
                title: "订单号",
                field: "orderCode",
                width: 80,
                align: "center"
            }, {
                title: "优惠券名称",
                field: "couponName",
                width: 40,
                align: "center"
            },{
                title: "使用期限",
                field: "limitTime",
                width: 80,
                align: "center"
            }, {
                title: "状态",
                field: "statusValue",
                width: 50,
                align: "center",
                formatter: function (value, rowData) {
                    return value == 1 ? '已使用' : (value == 2 ? '已作废' : '未使用');
                }
            }, {
                title: "操作",
                field: "operations",
                width: 80,
                align: "center",
                formatter: function (value, rowData) {
                    var str = '';
                    if(rowData.statusValue == 0){
                        str += "<a role='edit' dataId='" + rowData.couponId + "' dataUid='" + rowData.uid + "'  style='margin-left:10px;background-color: #5bc0de'>延期</a>";
                        str += "<a role='del' dataCode='" + rowData.couponCode + "' dataUid='" + rowData.uid + "' style='margin-left:10px;background-color: red'>作废</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='edit']").linkbutton({
                    iconCls: "icon-edit",
                    onClick: function () {
                        var id = $(this).attr("dataId");
                        var uid = $(this).attr("dataUid");
                        editRow(id,uid);
                    }
                });
                // 作废
                $(this).myDatagrid("getPanel").find("a[role='del']").linkbutton({
                    iconCls: "icon-more",
                    onClick: function () {
                        var couponCode = $(this).attr("dataCode");
                        var uid = $(this).attr("dataUid");
                        invalidCoupon(couponCode,uid);
                    }
                });
            }
        });

        //延迟发券modal
        function editRow(id,uid) {
            couponId = id;
            userId =  uid;
            var div = $("<div>").appendTo($(document.body));
            var title = "编辑优惠券";
            var message = "确认修改吗?";
            $(div).myDialog({
                width: "680px",
                height: "450px",
                title: title,
                href: contextPath + "/html/coupon/editUserCoupon.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 endTimeStr = $('#updateUserCoupon #endTimeStr').datetimebox('getValue');
                                if (endTimeStr == '' || endTimeStr == null || endTimeStr == undefined) {
                                    $.messager.alert("提示", '优惠券截止时间不能为空!', "error");
                                    return false;
                                }
                                $('#updateUserCoupon #endTime').val(new Date(endTimeStr).getTime()/1000);
                                var url = contextPath + "/coupon/updateUserCoupon";
                                $("#updateUserCoupon").form("submit", {
                                    url: url,
                                    onSubmit: function () {
                                        if (!$("#updateUserCoupon").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");
                                            $.messager.show({
                                                title: "提示",
                                                msg: title + "成功!",
                                                height: 120
                                            });
                                        } else {
                                            $.messager.alert("失败", data.message, "error");
                                        }
                                    }
                                });
                            }
                        });
                    }
                }, {
                    text: "关闭",
                    iconCls: "icon-cancel",
                    handler: function () {
                        $(div).dialog("close");
                    }
                }]
            });
        }

        function invalidCoupon(couponCode,uid) {
            var message = "确定要作废吗?";
            var msg = "操作成功";
            $.messager.confirm("确认", message, function (flag) {
                if (flag) {
                    $.messager.progress({
                        title: "正在执行",
                        msg: "正在执行,请稍后...",
                        interval: 500,
                        text: ""
                    });
                    $.post(contextPath + "/coupon/invalidateUserCoupon", {
                        "uid": uid,
                        "couponCode": couponCode
                    }, function (data) {
                        $.messager.progress("close");
                        if (data.code == 200) {
                            $.messager.show({
                                title: "提示",
                                msg: msg,
                                height: 120
                            });
                        } else {
                            $.messager.alert("失败", data.message, "error");
                        }
                    }, "json");
                }
            });
        }
        // 搜索
        $("#searchLinkButton").linkbutton({
            onClick: function () {
                var param = getParams();
                $("#couponTable").myDatagrid("load", param);
            }
        });

        /**
         * 提取出搜索参数
         */
        function getParams() {
            var uid = $('#uid').textbox('getText');
            var couponCode = $('#couponCode').textbox('getText');
            var param = {};
            if (undefined !== uid && null !== uid && "" !== uid) {
                param.uid = uid;
            }
            if (undefined !== couponCode && null !== couponCode && "" !== couponCode) {
                param.couponCode = couponCode;
            }
            return param;
        }
    });


</script>

</body>
</html>