<!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"
                                    th:with="type=${@dict.getType('zhengzai_sweet_draw_prize_type')}">
                                <option value="">全部</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>用户账户：</label>
                            <input type="text" name="mobile"/>
                        </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>
                                <option value="3">未领取</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 prizeType = [[${@dict.getType('zhengzai_sweet_draw_prize_type')}]];

    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) {
                        let dictLabel = $.table.selectDictLabel(prizeType, value);
                        if (row.relationId) {
                                return dictLabel + "(" + row.relationId + ")";
                        } else {
                            return dictLabel;
                        }
                    }
                },
                {
                    field: 'prizeTypeNum',
                    title: '数量'
                },
                {
                    field: 'nickname',
                    title: '用户昵称'
                },
                {
                    field: 'mobile',
                    title: '用户账号'
                },
                {
                    field: 'receivingName',
                    title: '收货人姓名'
                },
                {
                    field: 'receivingPhone',
                    title: '收货人电话'
                },
                {
                    field: 'receivingAddress',
                    title: '收货人地址',
                    formatter: function (value, row) {
                        var receivingProvince = row.receivingProvince;
                        var receivingCity = row.receivingCity;
                        var receivingCounty = row.receivingCounty;
                        var receivingAddress = row.receivingAddress;
                        return receivingProvince + ' ' + receivingCity + ' ' + receivingCounty + ' ' + receivingAddress;
                    }
                },
                {
                    field: 'receivingStatus',
                    title: '发放状态',
                    formatter: function (value, row) {
                        var receivingStatusName = "";
                        var prizeType = row.prizeType;
                        var relationId = row.relationId;
                        switch (value) {
                            case 1:
                                receivingStatusName = "未发放";
                                break;
                            case 2:
                                receivingStatusName = "已发放";
                                break;
                            case 3:
                                receivingStatusName = "未领取";
                                break;
                        }
                        return receivingStatusName;
                    }
                },
                {
                    field: 'createdAt',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.receivingStatus == 1) {
                            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>