<!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>
                            <label>演出Id：</label>
                            <input type="text" name="targetId"/>
                        </li>
                        <li>
                            <label>退款状态：</label>
                            <select name="status">
                                <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>
                            <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="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="kylin:refundBatch:apply">
                <i class="fa fa-plus"></i> 提交申请
            </a>
        </div>

        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>

        <!--审核的弹窗-->
        <div class="wrapper wrapper-content animated fadeInRight ibox-content hidden" id="form-refund-review">
            <form class="form-horizontal m">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-xs-2 control-label layui-required">备注：</label>
                            <div class="col-xs-10">
                                <textarea name="remark" maxlength="500" class="form-control layui-required"
                                          rows="3"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>

    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var detailFlag = [[${@permission.hasPermi('kylin:refundBatch:detail')}]];
    var reviewFlag = [[${@permission.hasPermi('kylin:refundBatch:review')}]];
    var executeFlag = [[${@permission.hasPermi('kylin:refundBatch:execute')}]];
    var cancelFlag = [[${@permission.hasPermi('kylin:refundBatch:cancel')}]];
    var reapplyFlag = [[${@permission.hasPermi('kylin:refundBatch:reapply')}]];

    var prefix = ctx + "kylin/refundBatch";

    function review(id) {
        data = {"refundBatchId": id};
        layer.open({
            type: 1,
            fixed: false,
            maxmin: true,
            title: '一审',
            area: ['500px', '220px'],
            content: $("#form-refund-review").html(),
            btn: ["通过", '拒绝'],
            yes: function (index, layero) {
                var remark = $(layero).find("[name='remark']").val();
                if (!remark) {
                    layer.msg("请填写备注");
                    return false;
                }
                data['reject'] = remark;
                data['status'] = 44;
                $.operate.save(prefix + "/review", data);
                layer.close(index)
            },
            btn2: function (index, layero) {
                var remark = $(layero).find("[name='remark']").val();
                if (!remark) {
                    layer.msg("请填写备注");
                    return false;
                }
                data['reject'] = remark;
                data['status'] = 33;
                $.operate.save(prefix + "/review", data);
            }
        });
    }

    function execute(id) {
        data = {"refundBatchId": id};
        layer.open({
            type: 1,
            fixed: false,
            maxmin: true,
            title: '二审',
            area: ['500px', '220px'],
            content: $("#form-refund-review").html(),
            btn: ["通过", '拒绝'],
            yes: function (index, layero) {
                var remark = $(layero).find("[name='remark']").val();
                if (!remark) {
                    layer.msg("请填写备注");
                    return false;
                }
                data['refuse'] = remark;
                data['status'] = 66;
                $.operate.save(prefix + "/execute", data);
                layer.close(index)
            },
            btn2: function (index, layero) {
                var remark = $(layero).find("[name='remark']").val();
                if (!remark) {
                    layer.msg("请填写备注");
                    return false;
                }
                data['refuse'] = remark;
                data['status'] = 55;
                $.operate.save(prefix + "/execute", data);
                // return false;
            }
        });
    }

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/applyView",
            detailUrl: prefix + "/details/{id}",
            cancelUrl: prefix + "/cancel",
            reapplyUrl: prefix + "/reapply",
            modalName: "-演出退款",
            columns: [{
                checkbox: true
            },
                {
                    field: 'refundBatchId',
                    title: '退款id'
                },
                {
                    field: 'targetId',
                    title: '演出id'
                },
                {
                    field: 'performancesInfo.title',
                    title: '演出名称'
                },
                {
                    field: 'statusName',
                    title: '状态'
                },
                {
                    field: 'createdAt',
                    title: '申请时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.refundBatchId + '\')"></i>查看</a> ');

                        actions.push('<a class="btn btn-success btn-xs ' + reviewFlag + '" href="javascript:void(0)" onclick="review(\'' + row.refundBatchId + '\')"></i>一审</a> ');
                        actions.push('<a class="btn btn-primary btn-xs ' + executeFlag + '" href="javascript:void(0)" onclick="execute(\'' + row.refundBatchId + '\')"></i>二审</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + cancelFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.refundBatchId + '\', \'确定取消退款申请吗？\', table.options.cancelUrl)"></i>取消</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + reapplyFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.refundBatchId + '\', \'确定重新提交退款审核吗？\', table.options.reapplyUrl)"></i>重新提交</a> ');
                        return actions.join('');
                    }
                }]
        };

        $.table.init(options);

    });
</script>
</body>
</html>