<?php
/** PSI 供应商表单 */
$s = $supplier;
$isEdit = !empty($s);
$typeOpts = ['面料商' => '面料商', '辅料商' => '辅料商', '成衣加工厂' => '成衣加工厂', 'OEM' => 'OEM', '物流' => '物流', '其他' => '其他'];
$gradeOpts = ['战略' => '战略', '合格' => '合格', '试用' => '试用', '淘汰' => '淘汰'];
$curType = $s['type'] ?? '';
$curGrade = $s['grade'] ?? '';
?>
<div class="page-head"><h1><?php echo $isEdit ? '编辑供应商' : '新增供应商'; ?></h1></div>
<div class="panel">
    <form method="post" action="<?php echo site_url($isEdit ? 'PSI/suppliers/update/' . $s['id'] : 'PSI/suppliers/store'); ?>">
        <?php echo csrf_field(); ?>
        <div class="form-grid">
            <div class="field"><label>名称 *</label><input name="name" value="<?php echo e($s['name'] ?? ''); ?>" required></div>
            <div class="field"><label>供应商类型</label>
                <select name="type">
                    <option value="">未设置</option>
                    <?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="grade">
                    <option value="">未设置</option>
                    <?php foreach ($gradeOpts as $k => $v): ?>
                        <option value="<?php echo $k; ?>" <?php echo $curGrade === $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="field"><label>联系人</label><input name="contact" value="<?php echo e($s['contact'] ?? ''); ?>"></div>
            <div class="field"><label>电话</label><input name="phone" value="<?php echo e($s['phone'] ?? ''); ?>"></div>
            <div class="field"><label>国家/地区</label><input name="country" value="<?php echo e($s['country'] ?? ''); ?>"></div>
            <div class="field"><label>交期达成率(%)</label><input name="ontime_rate" type="number" step="0.01" value="<?php echo e($s['ontime_rate'] ?? '0'); ?>"></div>
            <div class="field"><label>质检合格率(%)</label><input name="qc_rate" type="number" step="0.01" value="<?php echo e($s['qc_rate'] ?? '0'); ?>"></div>
        </div>
        <div class="field"><label>备注</label><textarea name="remark" rows="2"><?php echo e($s['remark'] ?? ''); ?></textarea></div>
        <button class="btn-primary" type="submit">保存</button>
        <a class="btn-soft" href="<?php echo site_url('PSI/suppliers'); ?>">取消</a>
    </form>
</div>
