<!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="orderTicketsId"/>
                        </li>
                        <li>
                            <label>退款编号：</label>
                            <input type="text" name="orderRefundCode"/>
                        </li>
                        <li>
                            <label>退款状态：</label>
                            <select name="status">
                                <option value="">全部</option>
                                <option value="0">请求退款</option>
                                <option value="2">取消退款</option>
                                <option value="1">一审审核通过</option>
                                <option value="5">一审驳回退款</option>
                                <option value="7">二审通过等待退款</option>
                                <option value="8">二审驳回退款</option>
                                <option value="3">正在退款</option>
                                <option value="4">完成退款</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:refund:apply">
                <i class="fa fa-plus"></i> 提交申请
            </a>
            <a class="btn btn-success multiple disabled" onclick="review()" shiro:hasPermission="kylin:refund:review">
                批量一审
            </a>
            <a class="btn btn-primary multiple disabled" onclick="execute()" shiro:hasPermission="kylin:refund:execute">
                批量二审
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll('确定取消选中的退款申请吗？', 'refund/cancel')"
               shiro:hasPermission="kylin:refund:cancel">
                批量取消
            </a>
            <a class="btn btn-warning multiple disabled"
               onclick="$.operate.removeAll('确定重新提交选中的退款审核吗？', 'refund/reapply')"
               shiro:hasPermission="kylin:refund:reapply">
                批量重新提交
            </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:refund:detail')}]];
    var reviewFlag = [[${@permission.hasPermi('kylin:refund:review')}]];
    var executeFlag = [[${@permission.hasPermi('kylin:refund:execute')}]];
    var cancelFlag = [[${@permission.hasPermi('kylin:refund:cancel')}]];
    var reapplyFlag = [[${@permission.hasPermi('kylin:refund:reapply')}]];
    var completedFlag = [[${@permission.hasPermi('kylin:refund:completed')}]];

    var prefix = ctx + "kylin/refund";

    function review(id) {
        var data = '';
        if (id) {
            var ids = [id];
            data = {"ids": ids.join()};
        } else {
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            data = {"ids": rows.join()};
        }
        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'] = 1;
                $.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'] = 5;
                $.operate.save(prefix + "/review", data);
                // return false;
            }
        });
    }

    function execute(id) {
        // $.modal.open("二审", prefix + '/reviewExecute', '800', '300', 2222);
        var data = '';
        if (id) {
            var ids = [id];
            data = {"ids": ids.join()};
        } else {
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            data = {"ids": rows.join()};
        }
        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'] = 7;
                $.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'] = 8;
                $.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",
            completedUrl: prefix + "/completed",
            modalName: "-订单退款",
            columns: [{
                checkbox: true
            },
                {
                    field: 'orderRefundsId',
                    title: '退款id'
                },
                {
                    field: 'orderTicketsId',
                    title: '票务订单id'
                },
                {
                    field: 'orderRefundCode',
                    title: '退款编号'
                },
                {
                    field: 'refundCode',
                    title: '退款中心退款编号'
                },
                {
                    field: 'price',
                    title: '退款总金额'
                },
                {
                    field: 'statusName',
                    title: '退款状态'
                },
                {
                    field: 'createdAt',
                    title: '申请时间'
                },
                {
                    field: 'refundAt',
                    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.orderRefundsId + '\')"></i>查看</a> ');

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

        $.table.init(options);

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