feat(postcard): allow manual status override in new-sent form (auto/pending/sent/delivered)

This commit is contained in:
2026-07-15 19:10:12 +08:00
parent de29f5445e
commit 5ec21f0e3f
3 changed files with 48 additions and 20 deletions

View File

@@ -122,6 +122,7 @@
"pc_form.number": "Number", "pc_form.number": "Number",
"pc_form.number_hint": "Format: AB-1234567", "pc_form.number_hint": "Format: AB-1234567",
"pc_form.status": "Status", "pc_form.status": "Status",
"pc_form.status_auto": "Auto (based on date)",
"pc_form.recipient": "Recipient", "pc_form.recipient": "Recipient",
"pc_form.country": "Country", "pc_form.country": "Country",
"pc_form.country_from": "From", "pc_form.country_from": "From",

View File

@@ -122,6 +122,7 @@
"pc_form.number": "编号", "pc_form.number": "编号",
"pc_form.number_hint": "格式AB-1234567", "pc_form.number_hint": "格式AB-1234567",
"pc_form.status": "状态", "pc_form.status": "状态",
"pc_form.status_auto": "自动(根据日期)",
"pc_form.recipient": "收件人", "pc_form.recipient": "收件人",
"pc_form.country": "国家/地区", "pc_form.country": "国家/地区",
"pc_form.country_from": "寄出地", "pc_form.country_from": "寄出地",

View File

@@ -35,10 +35,18 @@
{% else %} {% else %}
{# ── 寄出表单 ── #} {# ── 寄出表单 ── #}
{% if is_new %} {% if is_new %}
{# 新建寄出:状态由日期自动定,隐藏选择 #} {# 新建寄出:状态默认由日期自动定,可手动覆盖 #}
<input type="hidden" name="status" id="hidden-status" value="sent">
<label>{{ 'pc_form.status'|t(user.language) }}</label> <label>{{ 'pc_form.status'|t(user.language) }}</label>
<div id="auto-status-display" class="form-card" style="padding:.4rem .75rem;margin-bottom:.25rem;font-size:.85rem;display:inline-block"></div> <div style="display:flex;align-items:center;gap:.5rem">
<select name="status" id="status-select" onchange="onStatusChange()">
<option value="auto">{{ 'pc_form.status_auto'|t(user.language) }}</option>
<option value="pending">{{ 'status.pending'|t(user.language) }}</option>
<option value="sent">{{ 'status.sent'|t(user.language) }}</option>
<option value="delivered">{{ 'status.delivered'|t(user.language) }}</option>
</select>
<span id="auto-status-hint" style="font-size:.8rem;color:var(--text-muted)"></span>
</div>
<input type="hidden" name="status" id="hidden-status" value="sent">
{% else %} {% else %}
{# 编辑时:显示状态选择 #} {# 编辑时:显示状态选择 #}
<label>{{ 'pc_form.status'|t(user.language) }} *</label> <label>{{ 'pc_form.status'|t(user.language) }} *</label>
@@ -80,33 +88,51 @@
(function() { (function() {
var sendTime = document.getElementById('input-send-time'); var sendTime = document.getElementById('input-send-time');
var hiddenStatus = document.getElementById('hidden-status'); var hiddenStatus = document.getElementById('hidden-status');
var display = document.getElementById('auto-status-display'); var select = document.getElementById('status-select');
var hint = document.getElementById('auto-status-hint');
var arrival = document.getElementById('input-arrival'); var arrival = document.getElementById('input-arrival');
var labelArrival = document.getElementById('label-arrival'); var labelArrival = document.getElementById('label-arrival');
var today = new Date().toISOString().slice(0, 10); var today = new Date().toISOString().slice(0, 10);
// 如果没填日期,自动填今天
if (!sendTime.value) sendTime.value = today; if (!sendTime.value) sendTime.value = today;
function updateAutoStatus() {
function autoFromSendTime() {
var v = sendTime.value; var v = sendTime.value;
if (!v) { display.textContent = ''; return; } if (!v) return 'sent';
if (v > today) { return v > today ? 'pending' : 'sent';
hiddenStatus.value = 'pending'; }
display.textContent = '📋 {{ "status.pending"|t(user.language) }}';
display.style.borderLeft = '3px solid var(--primary)'; function updateArrival(s) {
if (s === 'delivered') {
arrival.disabled = false;
arrival.value = arrival.value || today;
labelArrival.textContent = '{{ "pc_form.arrival_time"|t(user.language) }} *';
} else { } else {
hiddenStatus.value = 'sent';
display.textContent = '📮 {{ "status.sent"|t(user.language) }}';
display.style.borderLeft = '3px solid var(--sent)';
}
// arrived 仅在 delivered 时启用sent/pending 时禁用
if (hiddenStatus.value !== 'delivered') {
arrival.disabled = true; arrival.disabled = true;
arrival.value = ''; arrival.value = '';
labelArrival.textContent = '{{ "pc_form.arrival_time"|t(user.language) }}';
} }
} }
sendTime.addEventListener('change', updateAutoStatus);
sendTime.addEventListener('input', updateAutoStatus); function syncHint() {
updateAutoStatus(); var sel = select.value;
if (sel === 'auto') {
var auto = autoFromSendTime();
hiddenStatus.value = auto;
hint.textContent = '→ ' + (auto === 'pending' ? '{{ "status.pending"|t(user.language) }}' : '{{ "status.sent"|t(user.language) }}');
updateArrival(auto);
} else {
hiddenStatus.value = sel;
hint.textContent = '';
updateArrival(sel);
}
}
// expose for inline onchange
window.onStatusChange = syncHint;
sendTime.addEventListener('change', syncHint);
sendTime.addEventListener('input', syncHint);
syncHint();
})(); })();
{% elif is_edit and not is_received_form %} {% elif is_edit and not is_received_form %}
// ── 编辑寄出:根据状态切换 arrival 可用性 ── // ── 编辑寄出:根据状态切换 arrival 可用性 ──