<?php
/** CRM 商机线索列表 */
$stageLabel = ['new' => '新线索', 'contact' => '已联系', 'quote' => '报价中', 'won' => '已成交', 'lost' => '已流失'];
$sourceLabel = ['expo' => '展会', 'referral' => '转介绍', 'online' => '线上', 'web' => '官网', 'tel' => '电话', 'other' => '其他'];
?>
<div class="page-head">
    <h1>商机线索</h1>
    <a class="btn-primary" href="<?php echo site_url('CRM/leads/create'); ?>">+ 新增商机</a>
</div>
<div class="panel">
    <table class="tbl">
        <thead><tr><th>ID</th><th>标题</th><th>客户</th><th>金额</th><th>阶段</th><th>来源</th><th>成交概率</th><th>预计成交</th><th>负责人</th><th>操作</th></tr></thead>
        <tbody>
        <?php foreach ($leads as $l): ?>
            <tr>
                <td><?php echo e($l['id']); ?></td>
                <td><?php echo e($l['title']); ?></td>
                <td><?php echo e($cmap[$l['customer_id']] ?? ('#' . $l['customer_id'])); ?></td>
                <td>¥<?php echo e(number_format((float)($l['amount'] ?? 0), 2)); ?></td>
                <td><?php echo e($stageLabel[$l['stage'] ?? ''] ?? $l['stage'] ?? ''); ?></td>
                <td><?php echo e($sourceLabel[$l['source'] ?? ''] ?? $l['source'] ?? ''); ?></td>
                <td><?php echo e((int)($l['probability'] ?? 0)); ?>%</td>
                <td><?php echo e($l['expected_close'] ?? ''); ?></td>
                <td><?php echo e($l['owner'] ?? ''); ?></td>
                <td class="row-actions">
                    <a href="<?php echo site_url('CRM/leads/edit/' . $l['id']); ?>">编辑</a>
                    <a href="<?php echo site_url('CRM/leads/destroy/' . $l['id']); ?>" data-confirm="确认删除？">删除</a>
                </td>
            </tr>
        <?php endforeach; ?>
        <?php if (empty($leads)): ?><tr><td colspan="10" class="muted">暂无商机，点击右上角新增</td></tr><?php endif; ?>
        </tbody>
    </table>
</div>
