Files

105 lines
5.2 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* 车辆管理(v24 第 16 批 用户第 8 条;第 17 批 第 3 条改)。
*
* 用户原话(第 16 批 第 8 条):
* 「增加一个设置按钮,用来设置车辆管理、出行方式、节点类型。
* 注意,我们在财务中,已经把车辆添加进去了…但是可以添加其他的车辆,
* 比如租的车,借别人的车。」
*
* 用户原话(**第 17 批 第 3 条 —— 本次,推翻上一批的做法**):
* 「车辆下拉框,**不需要出现什么财务里登记的车**,只把车辆列出来就行了。」
*
* ⚠️ 所以这一页现在**只有一块**:「出行用的车」(自家 / 租的 / 借的)。
* 原来那块「财务里已登记的车」整块删掉了 —— 财务里的 kind=car 是**资产账目**
* ("这台车值多少钱"),它没有车牌车型,混进选车列表只会让人发懵。
* `Vehicle::fromLedger()` 方法保留在模型层(将来按车统计油费/保养还要用它
* 跟 `vehicles.ledger_id` 对上),但**不再被任何界面调用**。
*
* @param array $mine Vehicle::all() 的结果
*/
$canWrite = \App\Auth::canWrite();
$mine = $mine ?? [];
$back = url('trips');
?>
<div class="page-head">
<h1>车辆管理</h1>
<span class="sub">出行时能挑的车:自家的、租的、借别人的</span>
<div class="actions">
<a class="btn btn-ghost" href="<?= e($back) ?>">返回旅程</a>
<?php $trSetCurrent = 'vehicles'; require __DIR__ . '/_settings_menu.php'; ?>
</div>
</div>
<div class="card card-pad">
<h2 class="cinema-h2">
出行用的车
<span class="hint">自家车录一台方便选;租的车、借的车也录在这里</span>
</h2>
<?php if ($mine): ?>
<ul class="veh-list">
<?php foreach ($mine as $v): ?>
<li class="veh-row">
<span class="veh-ico"><?= ($v['vtype'] ?? 'own') === 'rental' ? '🔑' : (($v['vtype'] ?? 'own') === 'borrowed' ? '🤝' : '🚗') ?></span>
<?php if ($canWrite): ?>
<form class="inline-form veh-form" method="post" action="<?= e(url('trips/vehicles_save')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int)$v['id'] ?>">
<input class="input" name="plate" value="<?= e((string)$v['plate']) ?>"
placeholder="车牌" aria-label="车牌">
<input class="input" name="name" value="<?= e((string)$v['name']) ?>"
placeholder="车型名" required aria-label="车型名">
<select class="select" name="vtype" aria-label="来源">
<?php foreach (\App\Vehicle::TYPES as $vk => $vv): ?>
<option value="<?= e($vk) ?>"<?= (string)$v['vtype'] === $vk ? ' selected' : '' ?>>
<?= e($vv) ?>
</option>
<?php endforeach; ?>
</select>
<input class="input" name="vendor" value="<?= e((string)($v['vendor'] ?? '')) ?>"
placeholder="租车公司 / 车主" aria-label="租车公司或车主">
<label class="veh-def">
<input type="checkbox" name="is_default" value="1"<?= (int)$v['is_default'] === 1 ? ' checked' : '' ?>>
<span>默认</span>
</label>
<button class="btn btn-sm" type="submit">保存</button>
</form>
<form class="inline-form" method="post" action="<?= e(url('trips/vehicles_del')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int)$v['id'] ?>">
<button class="btn btn-ghost btn-sm" type="submit"
onclick="return confirm('删掉这辆车?')">删</button>
</form>
<?php else: ?>
<span class="veh-name"><?= e(\App\Vehicle::label($v)) ?></span>
<span class="veh-tag"><?= e(\App\Vehicle::TYPES[(string)$v['vtype']] ?? '') ?></span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p class="empty-hint">还没有。自家车录一台,出行时能直接挑。</p>
<?php endif; ?>
<?php if ($canWrite): ?>
<h3 class="set-sub">加一辆车</h3>
<form class="inline-form veh-form veh-add" method="post" action="<?= e(url('trips/vehicles_save')) ?>">
<?= csrf_field() ?>
<input class="input" name="plate" placeholder="车牌(借的车可不填)" aria-label="车牌">
<input class="input" name="name" placeholder="车型名,如「大众朗逸」" required aria-label="车型名">
<select class="select" name="vtype" aria-label="来源">
<?php foreach (\App\Vehicle::TYPES as $vk => $vv): ?>
<option value="<?= e($vk) ?>"><?= e($vv) ?></option>
<?php endforeach; ?>
</select>
<input class="input" name="vendor" placeholder="租车公司 / 车主" aria-label="租车公司或车主">
<input class="input" name="order_no" placeholder="租车订单号" aria-label="租车订单号">
<label class="veh-def">
<input type="checkbox" name="is_default" value="1">
<span>设为默认</span>
</label>
<button class="btn btn-sm" type="submit">加进车辆库</button>
</form>
<?php endif; ?>
</div>