<?php
/** CRM 跟进表单 */
$f = $follow;
$isEdit = !empty($f);
$wayOpts = ['tel' => '电话', 'wechat' => '微信', 'visit' => '拜访', 'email' => '邮件', 'other' => '其他'];
$curWay = $f['way'] ?? 'tel';
?>
<div class="page-head"><h1><?php echo $isEdit ? '编辑跟进' : '新增跟进'; ?></h1></div>
<div class="panel">
    <form method="post" action="<?php echo site_url($isEdit ? 'CRM/followups/update/' . $f['id'] : 'CRM/followups/store'); ?>">
        <?php echo csrf_field(); ?>
        <div class="form-grid">
            <div class="field"><label>关联客户 *</label>
                <select name="customer_id">
                    <option value="0">未关联</option>
                    <?php foreach ($customers as $c): ?>
                        <option value="<?php echo e($c['id']); ?>" <?php echo ($f['customer_id'] ?? 0) == $c['id'] ? 'selected' : ''; ?>><?php echo e($c['name']); ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="field"><label>跟进方式</label>
                <select name="way">
                    <?php foreach ($wayOpts as $k => $v): ?>
                        <option value="<?php echo $k; ?>" <?php echo $curWay === $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="field"><label>下次跟进</label><input name="next_at" type="date" value="<?php echo e($f['next_at'] ?? ''); ?>"></div>
            <div class="field"><label>跟进结果</label><input name="result" value="<?php echo e($f['result'] ?? ''); ?>" placeholder="如：已寄样/待报价"></div>
            <div class="field"><label>负责人</label><input name="owner" value="<?php echo e($f['owner'] ?? ''); ?>"></div>
        </div>
        <div class="field"><label>跟进内容 *</label><textarea name="content" rows="4" required><?php echo e($f['content'] ?? ''); ?></textarea></div>
        <button class="btn-primary" type="submit">保存</button>
        <a class="btn-soft" href="<?php echo site_url('CRM/followups'); ?>">取消</a>
    </form>
</div>
