diff --git a/app/locales/en.json b/app/locales/en.json index e696947..ba7da72 100644 --- a/app/locales/en.json +++ b/app/locales/en.json @@ -122,6 +122,7 @@ "pc_form.number": "Number", "pc_form.number_hint": "Format: AB-1234567", "pc_form.status": "Status", + "pc_form.status_auto": "Auto (based on date)", "pc_form.recipient": "Recipient", "pc_form.country": "Country", "pc_form.country_from": "From", diff --git a/app/locales/zh.json b/app/locales/zh.json index 3163d48..372196c 100644 --- a/app/locales/zh.json +++ b/app/locales/zh.json @@ -122,6 +122,7 @@ "pc_form.number": "编号", "pc_form.number_hint": "格式:AB-1234567", "pc_form.status": "状态", + "pc_form.status_auto": "自动(根据日期)", "pc_form.recipient": "收件人", "pc_form.country": "国家/地区", "pc_form.country_from": "寄出地", diff --git a/app/templates/postcard_form.html b/app/templates/postcard_form.html index b6075ff..e998e0a 100644 --- a/app/templates/postcard_form.html +++ b/app/templates/postcard_form.html @@ -35,10 +35,18 @@ {% else %} {# ── 寄出表单 ── #} {% if is_new %} - {# 新建寄出:状态由日期自动决定,隐藏选择 #} - + {# 新建寄出:状态默认由日期自动判定,可手动覆盖 #} -
+
+ + +
+ {% else %} {# 编辑时:显示状态选择 #} @@ -80,33 +88,51 @@ (function() { var sendTime = document.getElementById('input-send-time'); 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 labelArrival = document.getElementById('label-arrival'); var today = new Date().toISOString().slice(0, 10); - // 如果没填日期,自动填今天 if (!sendTime.value) sendTime.value = today; - function updateAutoStatus() { + + function autoFromSendTime() { var v = sendTime.value; - if (!v) { display.textContent = ''; return; } - if (v > today) { - hiddenStatus.value = 'pending'; - display.textContent = '📋 {{ "status.pending"|t(user.language) }}'; - display.style.borderLeft = '3px solid var(--primary)'; + if (!v) return 'sent'; + return v > today ? 'pending' : 'sent'; + } + + function updateArrival(s) { + if (s === 'delivered') { + arrival.disabled = false; + arrival.value = arrival.value || today; + labelArrival.textContent = '{{ "pc_form.arrival_time"|t(user.language) }} *'; } 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.value = ''; + labelArrival.textContent = '{{ "pc_form.arrival_time"|t(user.language) }}'; } } - sendTime.addEventListener('change', updateAutoStatus); - sendTime.addEventListener('input', updateAutoStatus); - updateAutoStatus(); + + function syncHint() { + 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 %} // ── 编辑寄出:根据状态切换 arrival 可用性 ──