<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>票详情 - VR票务</title>
    {include file="public/head" /}
    <style>
        .ticket-detail-card {max-width:800px;}
        .detail-row {padding:12px 0;border-bottom:1px solid #f0f0f0;}
        .detail-label {color:#999;font-size:13px;margin-bottom:4px;}
        .detail-value {font-size:14px;}
        .qr-box {text-align:center;padding:20px;background:#fafafa;border-radius:4px;}
        .qr-box img {max-width:200px;}
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card ticket-detail-card">
        <div class="layui-card-header">
            票详情
            <span class="layui-badge layui-bg-{{$ticket['verify_status']==1 ? 'green' : ($ticket['verify_status']==2 ? 'red' : 'blue')}}">
                {{$ticket['verify_status']==1 ? '已核销' : ($ticket['verify_status']==2 ? '已退款' : '未核销')}}
            </span>
            <span class="layui-btn layui-btn-xs layui-btn-primary" style="float:right" onclick="history.back()">返回</span>
        </div>
        <div class="layui-card-body">
            <!-- 票码 -->
            <div class="detail-row">
                <div class="detail-label">票码</div>
                <div class="detail-value" style="font-family:monospace;font-size:16px;color:#1e9fff">{$ticket.ticket_code}</div>
            </div>

            <!-- 二维码 -->
            <div class="detail-row">
                <div class="detail-label">二维码</div>
                <div class="qr-box">
                    <img src="{$ticket.qr_code_url}" alt="票二维码">
                    <div style="margin-top:10px;color:#999;font-size:12px">扫描核销</div>
                </div>
            </div>

            <!-- 基本信息 -->
            <div class="detail-row">
                <div class="detail-label">关联商品</div>
                <div class="detail-value">{$goods['title']|default='已删除商品'}</div>
            </div>
            <div class="detail-row">
                <div class="detail-label">订单号</div>
                <div class="detail-value">{$ticket.order_no}</div>
            </div>
            <div class="detail-row">
                <div class="detail-label">座位信息</div>
                <div class="detail-value">{$ticket.seat_info|default='无'}</div>
            </div>

            <!-- 观演人 -->
            <div class="detail-row">
                <div class="detail-label">观演人</div>
                <div class="detail-value">{$ticket.real_name|default='-'}</div>
            </div>
            <div class="detail-row">
                <div class="detail-label">手机号</div>
                <div class="detail-value">{$ticket.phone|default='-'}</div>
            </div>
            <div class="detail-row">
                <div class="detail-label">身份证</div>
                <div class="detail-value">{$ticket.id_card|default='-'}</div>
            </div>

            <!-- 时间 -->
            <div class="detail-row">
                <div class="detail-label">发放时间</div>
                <div class="detail-value">{$ticket.issued_at > 0 ? date('Y-m-d H:i:s', $ticket.issued_at) : '-'}</div>
            </div>
            {if $ticket['verify_status'] == 1}
            <div class="detail-row">
                <div class="detail-label">核销时间</div>
                <div class="detail-value">{$ticket.verify_time > 0 ? date('Y-m-d H:i:s', $ticket.verify_time) : '-'}</div>
            </div>
            <div class="detail-row">
                <div class="detail-label">核销员</div>
                <div class="detail-value">{$verifier['name']|default='-'}</div>
            </div>
            {/if}

            <!-- 操作 -->
            {if $ticket['verify_status'] == 0}
            <div class="detail-row">
                <div class="detail-label">手动核销</div>
                <div class="detail-value">
                    <form class="layui-form" style="display:inline" id="verify-form">
                        <select name="verifier_id" required lay-verify="required" style="width:200px;display:inline">
                            <option value="">选择核销员</option>
                            {foreach $verifiers as $v}
                                <option value="{$v.id}">{$v.name}</option>
                            {/foreach}
                        </select>
                        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-submit lay-filter="do-verify">确认核销</button>
                    </form>
                </div>
            </div>
            {/if}
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
layui.use('form', function() {
    var form = layui.form;
    form.on('submit(do-verify)', function(data) {
        if (!data.field.verifier_id) {
            layer.msg('请选择核销员');
            return false;
        }
        $.post('{:MyUrl("plugins_vr_ticket/admin/ticket/verify")}', {
            ticket_code: '{$ticket.ticket_code}',
            verifier_id: data.field.verifier_id
        }, function(res) {
            if (res.code == 0) {
                layer.msg('核销成功', function() { location.reload(); });
            } else {
                layer.msg(res.msg || '核销失败');
            }
        });
        return false;
    });
});
</script>
</body>
</html>
