<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('积分活动中奖列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <input hidden type="text" name="integralActivityId" th:value="${integralActivityId}">
                        <li>
                            <label>奖品名称：</label>
                            <input type="text" name="prizeTitle"/>
                        </li>
                        <li>
                            <label>奖品类型：</label>
                            <select name="prizeType">
                                <option value="">全部</option>
                                <option value="1">谢谢惠顾</option>
                                <option value="2">积分</option>
                                <option value="3">代金券</option>
                                <option value="4">满减券</option>
                                <option value="5">优先购买券</option>
                                <option value="6">实物</option>
                            </select>
                        </li>
                        <li>
                            <label>用户昵称：</label>
                            <input type="text" name="nickname"/>
                        </li>
                        <li>
                            <label>发放状态：</label>
                            <select name="receivingStatus">
                                <option value="">全部</option>
                                <option value="1">未发放</option>
                                <option value="2">已发放</option>
                            </select>
                        </li>
                        <li>
                            <label>是否中奖：</label>
                            <select name="isWin">
                                <option value="">全部</option>
                                <option value="1">未中奖</option>
                                <option value="2">已中奖</option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var receivingStatusFlag = [[${@permission.hasPermi('sweet:IntegralActivityDraw:receivingStatus')}]];

    var prefix = ctx + "sweet/IntegralActivityDraw";
    $(function () {
        var options = {
            url: prefix + "/list",
            modalName: "积分活动中奖记录",
            columns: [{
                checkbox: true
            },
                {
                    field: 'prizeTitle',
                    title: '奖品名称'
                },
                {
                    field: 'prizeType',
                    title: '奖品类型',
                    formatter: function (value, row) {
                        var prizeType = row.prizeType;
                        switch (prizeType) {
                            case 1:
                                break;
                        }
                        return prizeType;
                    }
                },
                {
                    field: 'prizeTypeNum',
                    title: '数量'
                },
                {
                    field: 'nickname',
                    title: '用户昵称'
                },
                {
                    field: 'receivingName',
                    title: '收货人姓名'
                },
                {
                    field: 'receivingPhone',
                    title: '收货人电话'
                },
                {
                    field: 'receivingAddress',
                    title: '收货人姓名地址'
                },
                {
                    field: 'receivingStatus',
                    title: '发放状态',
                    formatter: function (value, row) {
                        var receivingStatus = row.receivingStatus;
                        if (row.receivingStatus == 1) {
                            receivingStatus = "未发放";
                        } else {
                            receivingStatus = "已发放";
                        }
                        return receivingStatus;
                    }
                },
                {
                    field: 'createdAt',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + receivingStatusFlag + '" href="javascript:void(0)" onclick="openModal(\'' + row.drawId + '\')"></i>发放</a> ');
                        return actions.join('');
                    }
                }]
        };

        $.table.init(options);

    });
    function openModal(id) {
        $.modal.confirm(`确定要发放吗？`, function() {
            $.ajax({
                type: 'put',
                url: '/sweet/IntegralActivityDraw/receivingStatus',
                data: {drawId: id},
                success:function(e) {
                    console.log(e)
                    if (e.code == 0) {
                        layer.msg('发放成功！')
                        $("button[name=refresh]").click();
                    }
                }
            })
        });
    }
</script>
</body>
</html>