<?php
/** CRM 客户表单（服装行业） */
$c = $customer;
$isEdit = !empty($c);
$typeOpts = [
    'brand'   => '品牌方',
    'dealer1' => '一级经销商',
    'dealer2' => '二级经销商',
    'retail'  => '直营门店',
    'ecom'    => '电商',
    'export'  => '外贸出口',
    'oem'     => '生产代工',
];
$levelOpts = ['A' => 'A（重点）', 'B' => 'B（普通）', 'C' => 'C（潜在）'];
$industryOpts = ['服装' => '服装', '鞋帽' => '鞋帽', '家纺' => '家纺', '其他' => '其他'];
$statusOpts = [
    'lead'        => '潜在客户',
    'intent'      => '意向客户',
    'quote'       => '报价中',
    'cooperating' => '合作中',
    'won'         => '已成交',
    'lost'        => '已流失',
    'dormant'     => '休眠',
];
$curType = $c['type'] ?? 'brand';
$curLevel = $c['level'] ?? 'C';
$curIndustry = $c['industry'] ?? '服装';
$curStatus = $c['status'] ?? 'lead';
?>
<div class="page-head">
    <h1><?php echo $isEdit ? '编辑客户' : '新增客户'; ?></h1>
</div>
<div class="panel">
    <form method="post" action="<?php echo site_url($isEdit ? 'CRM/customers/update/' . $c['id'] : 'CRM/customers/store'); ?>">
        <?php echo csrf_field(); ?>
        <div class="form-grid">
            <div class="field"><label>客户名称 *</label><input name="name" value="<?php echo e($c['name'] ?? ''); ?>" required></div>
            <div class="field"><label>客户编号</label><input name="customer_no" value="<?php echo e($c['customer_no'] ?? ''); ?>" placeholder="如：C-0001"></div>
            <div class="field"><label>公司</label><input name="company" value="<?php echo e($c['company'] ?? ''); ?>"></div>
            <div class="field"><label>联系人</label><input name="contact" value="<?php echo e($c['contact'] ?? ''); ?>"></div>
            <div class="field"><label>电话</label><input name="phone" value="<?php echo e($c['phone'] ?? ''); ?>"></div>
            <div class="field"><label>邮箱</label><input name="email" value="<?php echo e($c['email'] ?? ''); ?>"></div>
            <div class="field"><label>国家/地区</label><input name="country" value="<?php echo e($c['country'] ?? ''); ?>" placeholder="如：德国 / 广东"></div>
            <div class="field"><label>客户类型</label>
                <select name="type">
                    <?php foreach ($typeOpts as $k => $v): ?>
                        <option value="<?php echo $k; ?>" <?php echo $curType === $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="field"><label>客户等级</label>
                <select name="level">
                    <?php foreach ($levelOpts as $k => $v): ?>
                        <option value="<?php echo $k; ?>" <?php echo $curLevel === $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="field"><label>所属行业</label>
                <select name="industry">
                    <?php foreach ($industryOpts as $k => $v): ?>
                        <option value="<?php echo $k; ?>" <?php echo $curIndustry === $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="field"><label>区域</label><input name="region" value="<?php echo e($c['region'] ?? ''); ?>" placeholder="如：华东/华南/海外"></div>
            <div class="field"><label>信用额度</label><input name="credit_limit" type="number" step="0.01" value="<?php echo e($c['credit_limit'] ?? '0'); ?>"></div>
            <div class="field"><label>客户状态</label>
                <select name="status">
                    <?php foreach ($statusOpts as $k => $v): ?>
                        <option value="<?php echo $k; ?>" <?php echo $curStatus === $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="field"><label>来源</label><input name="source" value="<?php echo e($c['source'] ?? ''); ?>" placeholder="如：展会/官网/转介绍"></div>
            <div class="field"><label>负责人</label><input name="owner" value="<?php echo e($c['owner'] ?? ''); ?>"></div>
        </div>
        <div class="field"><label>备注</label><textarea name="remark" rows="3"><?php echo e($c['remark'] ?? ''); ?></textarea></div>
        <button class="btn-primary" type="submit">保存</button>
        <a class="btn-soft" href="<?php echo site_url('CRM/customers'); ?>">取消</a>
    </form>
</div>
