<!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="performancesId"/>
                        </li>
                        <li>
                            <label>订单编号：</label>
                            <input type="text" name="orderCode"/>
                        </li>
                        <li>
                            <label>取票方式：</label>
                            <select name="getTicketType">
                                    <option value="">全部</option>
                                    <option value="electronic">电子票</option>
                                    <option value="express">快递票</option>
                            </select>
                        </li>
                        <li>
                            <label>申请退款类型：</label>
                            <select name="type">
                                    <option value="">全部</option>
                                    <option value="0">客服申请</option>
                                    <option value="1">超时退款</option>
                                    <option value="2">用户申请普通退款</option>
                                    <option value="3">用户申请快递退款</option>
                            </select>
                        </li>
                        <li>
                            <label>退款状态：</label>
                            <select name="status">

                                <shiro:hasRole name="admin">
                                    <option value="">全部</option>
                                    <option value="0">请求退款</option>
                                    <option value="2">取消退款</option>
                                    <option value="1">运营审核通过</option>
                                    <option value="5">运营审核驳回退款</option>
                                    <option value="9">已确认收货</option>
                                    <option value="7">财务审核通过等待退款</option>
                                    <option value="8">财务审核驳回退款</option>
                                    <option value="4">完成退款</option>
                                    <option value="6">退款失败</option>
                                </shiro:hasRole>
                                <shiro:hasPermission name="kylin:refund:apply">
                                    <shiro:lacksRole name="admin">
                                        <option value="">全部</option>
                                        <option value="0">请求退款</option>
                                        <option value="2">取消退款</option>
                                        <option value="1">运营审核通过</option>
                                        <option value="5">运营审核驳回退款</option>
                                        <option value="9">已确认收货</option>
                                        <option value="7">财务审核通过等待退款</option>
                                        <option value="8">财务审核驳回退款</option>
                                        <option value="4">完成退款</option>
                                        <option value="6">退款失败</option>
                                    </shiro:lacksRole>
                                </shiro:hasPermission>
                                <shiro:hasPermission name="kylin:refund:review">
                                    <shiro:lacksRole name="admin">
                                        <option value="0,8,4,6">全部</option>
                                        <option value="0">请求退款</option>
                                        <option value="8">财务审核驳回退款</option>
                                        <option value="4">完成退款</option>
                                        <option value="6">退款失败</option>
                                    </shiro:lacksRole>
                                </shiro:hasPermission>
                                <shiro:hasPermission name="kylin:refund:ticketAudit">
                                    <shiro:lacksRole name="admin">
                                        <option value="1">运营审核通过</option>
                                    </shiro:lacksRole>
                                </shiro:hasPermission>
                                <shiro:hasPermission name="kylin:refund:execute">
                                    <shiro:lacksRole name="admin">
                                        <option value="1,9,4,6">全部</option>
                                        <option value="1">运营审核通过</option>
                                        <option value="9">已确认收货</option>
                                        <option value="4">完成退款</option>
                                        <option value="6">退款失败</option>
                                    </shiro:lacksRole>
                                </shiro:hasPermission>
                            </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 search-collapse">
            <form id="formId2">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>短订单号：</label>
                            <input type="text" name="findCode"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="findCode()"><i
                                    class="fa fa-search"></i>&nbsp;查询</a>
                        </li>
                        <li>
                            <label>长订单号：</label>
                            <input type="text" name="allCode" readonly/>
                        </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-success multiple disabled" onclick="ticketAudit()"
               shiro:hasPermission="kylin:refund:ticketAudit">
                票务审核
            </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">备注：</label>
                            <div class="col-xs-10">
                                <textarea name="remark" maxlength="500" class="form-control" 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 ticketAuditFlag = [[${@permission.hasPermi('kylin:refund:ticketAudit')}]];

    var prefix = ctx + "kylin/refund";

    function findCode() {
        var shortCode = document.getElementsByName("findCode")[0].value;
        var allCode = document.getElementsByName("allCode")[0];
        $.operate.get(prefix + "/search/code?code=" + shortCode + "&type=2", function (res) {
            allCode.value = res.msg;
        });
    }

    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();
                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();
                data['reject'] = remark;
                data['status'] = 5;
                $.operate.save(prefix + "/review", data);
            }
        });
    }

    function ticketAudit(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();
                data['ticketRemark'] = remark;
                $.operate.save(prefix + "/ticketAudit", data);
                layer.close(index)
            },
            btn2: function (index, layero) {
            }
        });
    }

    function execute(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();
                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();
                data['refuse'] = remark;
                data['status'] = 8;
                $.operate.save(prefix + "/execute", data);
            }
        });
    }

    $(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: 'performanceTitle',
                    title: '演出名称'
                },
                {
                    field: 'orderCode',
                    title: '订单编号'
                },
                {
                    field: 'getTicketType',
                    title: '取票方式',
                    formatter: function (value, row, index) {
                        if (row.getTicketType == "electronic") {
                            return "电子票";
                        } else {
                            return '快递票';
                        }
                    },
                },
                {
                    field: 'type',
                    title: '申请退款类型',
                    formatter: function (value, row, index) {
                        switch (row.type) {
                            case 0:
                                return "客服申请";
                                break;
                            case 1:
                                return "超时退款";
                                break;
                            case 2:
                                return "用户申请普通退款";
                                break;
                            case 3:
                                return "用户申请快递退款";
                                break;
                        }
                    },
                },
                {
                    field: 'price',
                    title: '退票金额'
                },
                {
                    field: 'priceExpress',
                    title: '退快递费金额'
                },
                {
                    field: 'statusName',
                    title: '退款状态'
                },
                {
                    field: 'mailno',
                    title: '运单号'
                },
                {
                    field: 'refundError',
                    title: '退款结果备注',
                    formatter: function (value, row, index) {
                        if (row.status == 6) {
                            return row.refundError;
                        } else {
                            return '';
                        }
                    },
                    cellStyle: function (value, row, index) {
                        return {css: {"color": "red", "font-weight": "bold"}};
                    }
                },
                {
                    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-success btn-xs ' + ticketAuditFlag + '" href="javascript:void(0)" onclick="ticketAudit(\'' + 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>
