<!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>
                        <li>
                            用户名/姓名：<input type="text" name="userName" placeholder="昵称或姓名"/>
                        </li>
                        <li>
                            申请状态：
                            <select name="auditStatus">
                                <option value="">全部</option>
                                <option value="0">待审核</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-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var detailFlag = [[${@permission.hasPermi('adam:caomei:badgeApplyAudit:list')}]];
    var passFlag = [[${@permission.hasPermi('adam:caomei:badgeApplyAudit:edit')}]];
    var rejectFlag = [[${@permission.hasPermi('adam:caomei:badgeApplyAudit:edit')}]];
    var prefix = ctx + "adam/caomei/badgeApplyAudit";

    $(function() {
        var options = {
            url: prefix + "/list",
            formId: "formId",
            modalName: "补签审核",
            columns: [
                { field: 'applyRecordId', title: '申请ID' },
                { field: 'userId', title: '申请账号' },
                { field: 'realName', title: '姓名', formatter: function(v) { return v || '-'; } },
                { field: 'idCard', title: '证件号', formatter: function(v) { return v || '-'; } },
                { field: 'badgeName', title: '申请徽章', formatter: function(v) { return v || '-'; } },
                { field: 'performanceName', title: '关联演出', formatter: function(v) { return v || '-'; } },
                {
                    field: 'proofImageUrl',
                    title: '申请附件',
                    align: 'center',
                    formatter: function(value) {
                        if (!value) return '-';
                        return '<img src="' + value + '" style="height:32px;max-width:60px;cursor:pointer;border-radius:3px;" onclick=\'viewImage(' + JSON.stringify(value) + ')\' />';
                    }
                },
                {
                    field: 'auditStatus',
                    title: '审核状态',
                    align: 'center',
                    formatter: function(value) {
                        if (value === 0) return '<span class="label label-warning">待审核</span>';
                        if (value === 1) return '<span class="label label-success">已通过</span>';
                        if (value === 2) return '<span class="label label-danger">已驳回</span>';
                        return '-';
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick=\'detail(' + JSON.stringify(row.applyRecordId) + ')\'><i class="fa fa-eye"></i>详情</a> ');
                        if (row.auditStatus === 0) {
                            actions.push('<a class="btn btn-success btn-xs ' + passFlag + '" href="javascript:void(0)" onclick=\'passAudit(' + JSON.stringify(row.applyRecordId) + ')\'><i class="fa fa-check"></i>通过</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + rejectFlag + '" href="javascript:void(0)" onclick=\'rejectAudit(' + JSON.stringify(row.applyRecordId) + ')\'><i class="fa fa-close"></i>驳回</a>');
                        }
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

    function viewImage(url) {
        window.open(url, "_blank");
    }

    function detail(applyRecordId) {
        $.modal.open("补签详情", prefix + "/detail/" + encodeURIComponent(applyRecordId));
    }

    function passAudit(applyRecordId) {
        $.modal.confirm("确认审核通过并为用户发放对应徽章吗？", function() {
            $.operate.post(prefix + "/pass", { applyRecordId: applyRecordId });
        });
    }

    function rejectAudit(applyRecordId) {
        layer.prompt({
            title: "请输入驳回理由",
            formType: 2,
            maxlength: 255
        }, function(value, index) {
            layer.close(index);
            var reason = $.trim(value);
            if (!reason) {
                $.modal.msgError("驳回理由不能为空");
                return;
            }
            $.operate.post(prefix + "/reject", { applyRecordId: applyRecordId, rejectReason: reason });
        });
    }
</script>
</body>
</html>
