692 lines
38 KiB
Vue
692 lines
38 KiB
Vue
/**
|
||
* features/order-delivery-reply/views/OrderDeliveryReplyPage.vue
|
||
* 用途:订单交期回复工作台操作页——筛选分页、单行/联合回复批次、单行/批量通知、手动同步。
|
||
* 依赖:api/orderDeliveryReply.api(统一 requestJson)、useMessage、auth store(manage/access 权限)。
|
||
* 逻辑:所有数据只读本地快照;保存与通知是两步(联合回复只保存,批量通知才发送并锁定);
|
||
* 保存/通知成功后即时刷新列表(需求 §9);仅 access 用户隐藏全部写操作。
|
||
* 回复弹窗数量守恒(2026-09-23 由「超额仅提醒」修订):每行各批次合计必须等于订单数量
|
||
* 才能保存,弹窗实时红字提示 + 保存拦截,后端 422 兜底。
|
||
* 企微卡片直达:登录回跳后 query 仍在,按 status/order_no/line_no 还原筛选并滚动高亮目标行,
|
||
* wecom_trace 上报打开回执——保证「点卡片 → 登录 → 直达该 Agent 对应内容与位置」。
|
||
* 列顺序:客户编号(简称副文案) → 订单日期 → 订单单号:项次 → 产品编号(品名副文案) →
|
||
* 客户产品编号 → 数量 → 约定交货日 → 交期回复状态 → 交期回复 → 交期回复人员 →
|
||
* 业务员(部门副文案) → 客户订单 → 规格 → 单位;独立的部门列/品名列已并入合并展示。
|
||
* 浏览体验:页面高度收敛至视口(滚动全部发生在表格容器内 → 列头 sticky 固定、横向滚动条
|
||
* 常驻表格底缘);左侧冻结前四列标识区(勾选/客户编号/订单日期/订单单号:项次,
|
||
* 冻结单元格用实色背景防透出);筛选区与工具栏字号与表格统一(text-sm 14px)并压缩高度。
|
||
*/
|
||
|
||
<script setup lang="ts">
|
||
import { computed, nextTick, onMounted, reactive, ref } from 'vue';
|
||
import { useRoute } from 'vue-router';
|
||
import { useI18n } from 'vue-i18n';
|
||
import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||
import { useMessage } from '@/shared/composables/useMessage';
|
||
import { requestJson } from '@/shared/api/client';
|
||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||
import {
|
||
ORDER_DELIVERY_REPLY_MANAGE_PERMISSION,
|
||
} from '@/features/order-delivery-reply/constants';
|
||
import {
|
||
batchReplyOrderDelivery,
|
||
getLatestOrderDeliverySync,
|
||
listOrderDeliveryLines,
|
||
notifyOrderDeliveryBatch,
|
||
runOrderDeliverySync,
|
||
saveOrderDeliveryBatches,
|
||
type BatchSummary,
|
||
type OrderDeliveryLine,
|
||
type OrderDeliverySyncRun,
|
||
} from '@/features/order-delivery-reply/api/orderDeliveryReply.api';
|
||
|
||
const { t } = useI18n();
|
||
const msg = useMessage();
|
||
const auth = useAuthStore();
|
||
|
||
/** manage 可写(保存/通知/同步);access 或 manage 可看(路由与侧栏已按 access 守卫)。 */
|
||
const canManage = computed(() => auth.hasFeaturePermission(ORDER_DELIVERY_REPLY_MANAGE_PERMISSION));
|
||
|
||
/* ============ 列表查询 ============ */
|
||
const filters = reactive({ keyword: '', order_date: '', status: '' as '' | 'replied' | 'not_fully_replied' });
|
||
const appliedFilters = reactive({ ...filters });
|
||
const items = ref<OrderDeliveryLine[]>([]);
|
||
const total = ref(0);
|
||
const page = ref(1);
|
||
const pageSize = ref(50);
|
||
const pageSizeOptions = [20, 50, 100, 200];
|
||
const loading = ref(false);
|
||
const latestSync = ref<OrderDeliverySyncRun | null>(null);
|
||
|
||
async function loadLines() {
|
||
loading.value = true;
|
||
try {
|
||
const data = await listOrderDeliveryLines({ ...appliedFilters, page: page.value, page_size: pageSize.value });
|
||
items.value = data.items;
|
||
total.value = data.total;
|
||
if (data.page !== page.value) page.value = data.page;
|
||
} catch (error) {
|
||
msg.error(error instanceof Error ? error.message : t('workspace.orderDeliveryReply.loadFailed'));
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
}
|
||
|
||
async function loadLatestSync() {
|
||
try {
|
||
latestSync.value = await getLatestOrderDeliverySync();
|
||
} catch {
|
||
latestSync.value = null;
|
||
}
|
||
}
|
||
|
||
function doSearch() {
|
||
clearHighlight();
|
||
Object.assign(appliedFilters, filters);
|
||
page.value = 1;
|
||
void loadLines();
|
||
}
|
||
|
||
function doReset() {
|
||
Object.assign(filters, { keyword: '', order_date: '', status: '' });
|
||
doSearch();
|
||
}
|
||
|
||
/** 分页条:页码跳转(与管理控制台数据报表同一 PaginationBar 组件)。 */
|
||
function goToPage(next: number) {
|
||
if (next === page.value) return;
|
||
page.value = next;
|
||
void loadLines();
|
||
}
|
||
|
||
/** 切换每页条数:回到第 1 页并重查。 */
|
||
function changePageSize(size: number) {
|
||
if (size === pageSize.value) return;
|
||
pageSize.value = size;
|
||
page.value = 1;
|
||
void loadLines();
|
||
}
|
||
|
||
/** 手动同步(manage):同步执行完成后刷新列表与最近同步时间。 */
|
||
const syncing = ref(false);
|
||
async function doSync() {
|
||
syncing.value = true;
|
||
try {
|
||
const result = await runOrderDeliverySync();
|
||
if (result.status === 'skipped') {
|
||
msg.warning(t('workspace.orderDeliveryReply.syncSkipped'));
|
||
} else {
|
||
msg.success(t('workspace.orderDeliveryReply.syncDone', { count: result.line_count }));
|
||
}
|
||
await Promise.all([loadLines(), loadLatestSync()]);
|
||
} catch (error) {
|
||
msg.error(error instanceof Error ? error.message : t('workspace.orderDeliveryReply.syncFailedTitle'));
|
||
} finally {
|
||
syncing.value = false;
|
||
}
|
||
}
|
||
|
||
/* ============ 勾选(全选仅本页) ============ */
|
||
const selected = ref<string[]>([]);
|
||
const expanded = ref<string[]>([]);
|
||
const lineKey = (line: OrderDeliveryLine) => `${line.order_no}:${line.line_no}`;
|
||
const selectedLines = computed(() => items.value.filter((line) => selected.value.includes(lineKey(line))));
|
||
const allChecked = computed(() => items.value.length > 0 && items.value.every((line) => selected.value.includes(lineKey(line))));
|
||
const someChecked = computed(() => !allChecked.value && items.value.some((line) => selected.value.includes(lineKey(line))));
|
||
/** 勾选中「已有批次且未锁定」的行才可批量通知(无批次/已锁定会被后端 skipped)。 */
|
||
const notifiableSelected = computed(() => selectedLines.value.filter((line) => line.batches.length > 0 && !line.locked));
|
||
|
||
function toggleLine(line: OrderDeliveryLine, on: boolean) {
|
||
const key = lineKey(line);
|
||
selected.value = on ? [...selected.value, key] : selected.value.filter((k) => k !== key);
|
||
}
|
||
|
||
function togglePageAll(on: boolean) {
|
||
if (on) {
|
||
const keys = new Set(selected.value);
|
||
items.value.forEach((line) => keys.add(lineKey(line)));
|
||
selected.value = [...keys];
|
||
} else {
|
||
const pageKeys = new Set(items.value.map(lineKey));
|
||
selected.value = selected.value.filter((k) => !pageKeys.has(k));
|
||
}
|
||
}
|
||
|
||
function toggleExpand(key: string) {
|
||
expanded.value = expanded.value.includes(key)
|
||
? expanded.value.filter((k) => k !== key)
|
||
: [...expanded.value, key];
|
||
}
|
||
|
||
/* ============ 派生展示 ============ */
|
||
const repliedQty = (line: OrderDeliveryLine) =>
|
||
line.batches.reduce((sum, batch) => sum + Number(batch.qty || 0), 0);
|
||
const undelivered = (line: OrderDeliveryLine) => Number(line.undelivered_qty || 0);
|
||
type LineStatus = OrderDeliveryLine['status'];
|
||
const statusMeta = (status: LineStatus) => {
|
||
const map: Record<LineStatus, { label: string; cls: string }> = {
|
||
not_replied: { label: t('workspace.orderDeliveryReply.statusNotReplied'), cls: 'bg-rose-50 text-rose-600' },
|
||
partial_replied: { label: t('workspace.orderDeliveryReply.statusPartial'), cls: 'bg-orange-50 text-orange-600' },
|
||
replied: { label: t('workspace.orderDeliveryReply.statusReplied'), cls: 'bg-emerald-50 text-emerald-600' },
|
||
};
|
||
return map[status];
|
||
};
|
||
|
||
/* ============ 回复弹窗(单行 / 联合) ============ */
|
||
interface EditableBatch { planned_date: string; qty: string; remark: string }
|
||
interface EditableLine { line: OrderDeliveryLine; batches: EditableBatch[] }
|
||
|
||
const modalVisible = ref(false);
|
||
const modalTitle = ref('');
|
||
const modalLines = ref<EditableLine[]>([]);
|
||
const quickDate = ref('');
|
||
const saving = ref(false);
|
||
|
||
function openReplyModal(lines: OrderDeliveryLine[], title: string) {
|
||
modalLines.value = lines.map((line) => ({
|
||
line,
|
||
batches: line.batches.map((batch) => ({
|
||
planned_date: batch.planned_date,
|
||
qty: String(Number(batch.qty)),
|
||
remark: batch.remark || '',
|
||
})),
|
||
}));
|
||
// 无批次的行默认给一条空批次,便于快速填写。
|
||
modalLines.value.forEach((entry) => {
|
||
if (entry.batches.length === 0) entry.batches.push({ planned_date: '', qty: '', remark: '' });
|
||
});
|
||
modalTitle.value = title;
|
||
quickDate.value = '';
|
||
modalVisible.value = true;
|
||
}
|
||
|
||
function openSingleReply(line: OrderDeliveryLine) {
|
||
openReplyModal([line], t('workspace.orderDeliveryReply.modalTitleSingle', { order: line.order_no, item: line.line_no }));
|
||
}
|
||
|
||
function openBatchReply() {
|
||
const lines = selectedLines.value.filter((line) => !line.locked);
|
||
if (!lines.length) return;
|
||
openReplyModal(lines, t('workspace.orderDeliveryReply.modalTitleBatch', { count: lines.length }));
|
||
}
|
||
|
||
function applyQuickDate() {
|
||
if (!quickDate.value) return;
|
||
modalLines.value.forEach((entry) => entry.batches.forEach((batch) => { batch.planned_date = quickDate.value; }));
|
||
}
|
||
|
||
/**
|
||
* 行填写问题文案(实时校验,2026-09-23):
|
||
* [规则 1] 已填数量但未填交期的批次 → 「第 N 批未填交期」;
|
||
* [规则 2] 已填交期但未填数量的批次 → 「第 N 批未填数量」;
|
||
* [规则 3] 同一订单行不同批次交期重复 → 「同一订单单号:项次的不同批次交期时间不能相同」;
|
||
* [规则 4] 批次填写完整时合计 ≠ 订单数量 → 「各批次合计 X,须等于订单数量 Y」。
|
||
* 只有交期与数量都齐全的批次计入合计;完全空白的批次忽略;缺填/重复错误优先于数量错误展示,
|
||
* 保证报错随填写内容实时切换。锁定行不可编辑不校验。
|
||
*/
|
||
function lineIssueText(entry: EditableLine): string {
|
||
if (entry.line.locked) return '';
|
||
const missingDates: number[] = [];
|
||
const missingQtys: number[] = [];
|
||
let total = 0;
|
||
let hasInput = false;
|
||
entry.batches.forEach((batch, idx) => {
|
||
const hasDate = !!batch.planned_date;
|
||
const hasQty = batch.qty !== '' && Number(batch.qty) > 0;
|
||
if (!hasDate && !hasQty) return; // 空白批次忽略
|
||
hasInput = true;
|
||
if (hasDate && hasQty) {
|
||
total += Number(batch.qty);
|
||
} else if (!hasDate) {
|
||
missingDates.push(idx + 1);
|
||
} else {
|
||
missingQtys.push(idx + 1);
|
||
}
|
||
});
|
||
if (!hasInput) return '';
|
||
const parts: string[] = [];
|
||
if (missingDates.length) parts.push(t('workspace.orderDeliveryReply.batchMissingDate', { batches: missingDates.join('、') }));
|
||
if (missingQtys.length) parts.push(t('workspace.orderDeliveryReply.batchMissingQty', { batches: missingQtys.join('、') }));
|
||
// 同单不同批次交期重复(后端 _parse_batches 亦拒绝重复交期,此处实时提示)
|
||
const filledDates = entry.batches.filter((batch) => batch.planned_date).map((batch) => batch.planned_date);
|
||
const duplicatedDates = [...new Set(filledDates.filter((d, i) => filledDates.indexOf(d) !== i))];
|
||
if (duplicatedDates.length) parts.push(t('workspace.orderDeliveryReply.batchDuplicateDate', { dates: duplicatedDates.join('、') }));
|
||
if (!parts.length && Math.abs(total - Number(entry.line.qty || 0)) > 1e-6) {
|
||
parts.push(t('workspace.orderDeliveryReply.qtyTotalMismatchLine', { total, qty: Number(entry.line.qty || 0) }));
|
||
}
|
||
return parts.join(';');
|
||
}
|
||
|
||
async function saveReplies() {
|
||
const validItems: { order_no: string; line_no: number; batches: { planned_date: string; qty: string; remark: string | null }[] }[] = [];
|
||
for (const { line, batches } of modalLines.value) {
|
||
const cleaned = batches
|
||
.filter((batch) => batch.planned_date && Number(batch.qty) > 0)
|
||
.map((batch) => ({ planned_date: batch.planned_date, qty: batch.qty, remark: batch.remark.trim() || null }));
|
||
if (line.locked) continue; // 锁定行不允许再改(后端也会 409)
|
||
if (!cleaned.length) continue;
|
||
validItems.push({ order_no: line.order_no, line_no: line.line_no, batches: cleaned });
|
||
}
|
||
// 填写校验(2026-09-23,与实时提示同口径):缺交期/缺数量、合计≠订单数量都按行拦截。
|
||
const issueTexts: string[] = [];
|
||
for (const entry of modalLines.value) {
|
||
if (entry.line.locked) continue;
|
||
const text = lineIssueText(entry);
|
||
if (text) issueTexts.push(`${entry.line.order_no}:${entry.line.line_no} ${text}`);
|
||
}
|
||
if (issueTexts.length) {
|
||
msg.warning(t('workspace.orderDeliveryReply.saveBlocked', { detail: issueTexts.join(';') }));
|
||
return;
|
||
}
|
||
if (!validItems.length) {
|
||
msg.warning(t('workspace.orderDeliveryReply.noValidBatches'));
|
||
return;
|
||
}
|
||
saving.value = true;
|
||
try {
|
||
const [singleItem] = validItems;
|
||
if (validItems.length === 1 && singleItem) {
|
||
// 仅一行时走单行接口;多行必须走批量接口逐行保存(此前误判为 if (singleItem),
|
||
// 恒为真导致联合回复只保存第一行,批量分支成死代码)。
|
||
await saveOrderDeliveryBatches(singleItem.order_no, singleItem.line_no, singleItem.batches);
|
||
msg.success(t('workspace.orderDeliveryReply.saveSingleDone'));
|
||
} else {
|
||
const summary: BatchSummary = await batchReplyOrderDelivery(validItems);
|
||
if (summary.failed > 0) {
|
||
const failedText = summary.items.filter((item) => !item.ok).map((item) => `${item.order_no}:${item.line_no} ${item.error || ''}`).join(';');
|
||
msg.warning(t('workspace.orderDeliveryReply.saveBatchPartial', { ok: summary.succeeded, fail: summary.failed, detail: failedText }));
|
||
} else {
|
||
msg.success(t('workspace.orderDeliveryReply.saveBatchDone', { ok: summary.succeeded }));
|
||
}
|
||
}
|
||
modalVisible.value = false;
|
||
selected.value = [];
|
||
await loadLines(); // 保存或通知后即时刷新(需求 §9)
|
||
} catch (error) {
|
||
msg.error(error instanceof Error ? error.message : t('workspace.orderDeliveryReply.saveFailedTitle'));
|
||
// 行已不在同步范围(erp_missing/被新同步剔除):旧列表过期,自动刷新让该行消失。
|
||
const message = error instanceof Error ? error.message : '';
|
||
if (message.includes('LINE_NOT_FOUND') || message.includes('不在同步范围') || message.includes('not found')) {
|
||
await loadLines();
|
||
}
|
||
} finally {
|
||
saving.value = false;
|
||
}
|
||
}
|
||
|
||
/* ============ 通知 ============ */
|
||
const notifying = ref(false);
|
||
|
||
/** 批量通知:部分成功 warning 汇总,全部失败 error;提示后刷新列表让锁定即时生效。 */
|
||
async function doNotifyBatch() {
|
||
const lines = notifiableSelected.value;
|
||
if (!lines.length) return;
|
||
const ok = window.confirm(t('workspace.orderDeliveryReply.notifyBatchConfirm', { count: lines.length }));
|
||
if (!ok) return;
|
||
notifying.value = true;
|
||
try {
|
||
const summary = await notifyOrderDeliveryBatch(lines.map((line) => ({ order_no: line.order_no, line_no: line.line_no })));
|
||
const failedText = summary.items.filter((item) => !item.ok).map((item) => `${item.order_no}:${item.line_no} ${item.error || ''}`).join(';');
|
||
if (summary.failed > 0 && summary.succeeded > 0) {
|
||
msg.warning(t('workspace.orderDeliveryReply.notifyPartial', { ok: summary.succeeded, fail: summary.failed, skip: summary.skipped, detail: failedText }));
|
||
} else if (summary.failed > 0 && summary.succeeded === 0) {
|
||
msg.error(t('workspace.orderDeliveryReply.notifyAllFailed', { fail: summary.failed, detail: failedText }));
|
||
} else {
|
||
msg.success(t('workspace.orderDeliveryReply.notifyBatchDone', { ok: summary.succeeded, skip: summary.skipped }));
|
||
}
|
||
selected.value = [];
|
||
await loadLines();
|
||
} catch (error) {
|
||
msg.error(error instanceof Error ? error.message : t('workspace.orderDeliveryReply.notifyFailedTitle'));
|
||
} finally {
|
||
notifying.value = false;
|
||
}
|
||
}
|
||
|
||
/* ============ 同步状态展示 ============ */
|
||
const latestSyncText = computed(() => {
|
||
const run = latestSync.value;
|
||
if (!run) return t('workspace.orderDeliveryReply.syncNever');
|
||
const time = (run.finished_at || run.started_at || '').replace('T', ' ').slice(0, 19);
|
||
if (run.status === 'success') return t('workspace.orderDeliveryReply.syncAt', { time });
|
||
if (run.status === 'running') return t('workspace.orderDeliveryReply.syncRunning');
|
||
return t('workspace.orderDeliveryReply.syncFailedAt', { time });
|
||
});
|
||
const latestSyncFailed = computed(() => latestSync.value?.status === 'failed');
|
||
|
||
/* ============ 企微卡片直达定位 ============ */
|
||
// 企微卡片「查看详情」→(未登录先登录,守卫以 redirect 原样回跳)→ 本页按 query 还原内容与位置:
|
||
// status=交期回复状态筛选(提醒卡)、order_no=关键词筛选、line_no=滚动定位并高亮该行(行通知卡);
|
||
// wecom_trace 上报卡片打开回执(与工作台 deeplink 同一后端接口,失败静默只留痕)。
|
||
const route = useRoute();
|
||
const highlightKey = ref('');
|
||
let highlightTimer: ReturnType<typeof setTimeout> | null = null;
|
||
|
||
function clearHighlight() {
|
||
if (highlightTimer) {
|
||
clearTimeout(highlightTimer);
|
||
highlightTimer = null;
|
||
}
|
||
highlightKey.value = '';
|
||
}
|
||
|
||
const isLineHighlighted = (line: OrderDeliveryLine) => highlightKey.value === lineKey(line);
|
||
const rowCls = (line: OrderDeliveryLine) =>
|
||
isLineHighlighted(line) ? 'bg-amber-50' : selected.value.includes(lineKey(line)) ? 'bg-blue-50/60' : '';
|
||
/** 冻结单元格必须实色背景(防透出滚动内容),且与整行高亮/勾选色联动;高亮优先于勾选。 */
|
||
const frozenCellCls = (line: OrderDeliveryLine) =>
|
||
isLineHighlighted(line)
|
||
? 'bg-amber-100 group-hover:bg-amber-200'
|
||
: selected.value.includes(lineKey(line))
|
||
? 'bg-blue-100 group-hover:bg-blue-200'
|
||
: 'bg-white group-hover:bg-slate-100';
|
||
|
||
/** 列表就绪后定位目标行:滚动到视口中央 + 高亮 8 秒;行不在当前筛选结果中时静默跳过。 */
|
||
async function focusTargetLine(orderNo: string, lineNo: number) {
|
||
const key = `${orderNo}:${lineNo}`;
|
||
if (!items.value.some((line) => lineKey(line) === key)) return;
|
||
highlightKey.value = key;
|
||
await nextTick();
|
||
document.querySelector(`[data-line-key="${key}"]`)?.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||
msg.success(t('workspace.orderDeliveryReply.deepLinkLocated', { order: orderNo, item: lineNo }));
|
||
if (highlightTimer) clearTimeout(highlightTimer);
|
||
highlightTimer = setTimeout(clearHighlight, 8000);
|
||
}
|
||
|
||
/** 上报企微卡片打开回执(WecomNotifyAudit.opened_at);仅留痕,失败不影响页面使用。 */
|
||
async function reportWecomTraceOpened(traceId: string) {
|
||
try {
|
||
await requestJson('/api/user/wecom/deeplink-opened', {
|
||
method: 'POST',
|
||
body: JSON.stringify({ trace_id: traceId }),
|
||
});
|
||
} catch {
|
||
// 回执只留痕:失败不打扰用户。
|
||
}
|
||
}
|
||
|
||
onMounted(async () => {
|
||
const query = route.query;
|
||
const orderNo = typeof query.order_no === 'string' ? query.order_no.trim() : '';
|
||
const lineNo = typeof query.line_no === 'string' ? Number(query.line_no) : NaN;
|
||
const status = typeof query.status === 'string' ? query.status : '';
|
||
const traceId = typeof query.wecom_trace === 'string' ? query.wecom_trace : '';
|
||
|
||
// [STEP 1] 还原筛选(登录回跳后 query 仍在):关键词命中订单单号;状态筛选定位提醒卡对应视图。
|
||
if (orderNo) filters.keyword = orderNo;
|
||
if (status === 'replied' || status === 'not_fully_replied') filters.status = status;
|
||
if (orderNo || status) Object.assign(appliedFilters, filters);
|
||
|
||
if (traceId) void reportWecomTraceOpened(traceId);
|
||
|
||
// [STEP 2] 加载列表后按 line_no 滚动定位 + 高亮(行级通知卡直达场景)。
|
||
await loadLines();
|
||
void loadLatestSync();
|
||
if (orderNo && Number.isInteger(lineNo) && lineNo > 0) await focusTargetLine(orderNo, lineNo);
|
||
});
|
||
</script>
|
||
|
||
<template>
|
||
<!-- 全页统一字号:与表头一致(text-sm 14px),根容器设定基准,子元素不再覆写;
|
||
唯一例外:交期回复状态/交期已锁定徽标保持 text-xs(12px)加粗 -->
|
||
<!-- 高度收敛至视口(h-screen + overflow-hidden):页面自身不滚动,滚动全部在表格容器内,
|
||
列头 sticky 固定、横向滚动条常驻表格底缘;聊天壳 iframe 与独立路由均适用 -->
|
||
<div class="flex h-screen flex-col gap-4 overflow-hidden p-6 text-sm">
|
||
<!-- 页头:标题 + 最近同步 + 手动刷新 -->
|
||
<div class="flex flex-wrap items-center gap-3">
|
||
<h1 class="font-bold text-primary">{{ t('workspace.nav.orderDeliveryReply') }}</h1>
|
||
<span class="rounded-full px-3 py-1" :class="latestSyncFailed ? 'bg-rose-50 text-rose-600' : 'bg-blue-50 text-blue-600'">
|
||
{{ latestSyncText }}
|
||
</span>
|
||
<div class="flex-1" />
|
||
<button v-if="canManage" type="button" class="btn-ghost" :disabled="syncing" @click="doSync">
|
||
{{ syncing ? t('workspace.orderDeliveryReply.syncing') : t('workspace.orderDeliveryReply.syncNow') }}
|
||
</button>
|
||
</div>
|
||
|
||
<!-- 搜索区:合并关键词搜索(订单/产品/客户命中任一字段),字号与表格统一(text-sm),shrink-0 防压缩 -->
|
||
<div class="flex shrink-0 flex-wrap items-end gap-3 rounded-2xl border border-default bg-surface px-4 py-2.5">
|
||
<label class="flex flex-col gap-1 text-muted">
|
||
{{ t('workspace.orderDeliveryReply.filterKeyword') }}
|
||
<input v-model="filters.keyword" class="h-8 min-w-[340px] rounded-lg border border-default px-3 text-primary outline-none focus:border-blue-500" :placeholder="t('workspace.orderDeliveryReply.filterKeywordPh')" @keyup.enter="doSearch" />
|
||
</label>
|
||
<label class="flex flex-col gap-1 text-muted">
|
||
{{ t('workspace.orderDeliveryReply.filterOrderDate') }}
|
||
<input v-model="filters.order_date" type="date" class="h-8 rounded-lg border border-default px-3 text-primary outline-none focus:border-blue-500" />
|
||
</label>
|
||
<label class="flex flex-col gap-1 text-muted">
|
||
{{ t('workspace.orderDeliveryReply.filterStatus') }}
|
||
<!-- 状态筛选选择即生效(无需再点查询);其余条件仍由「查询」统一提交 -->
|
||
<select v-model="filters.status" class="min-w-[140px] rounded-lg border border-default bg-white px-3 py-[5px] text-sm leading-5 text-primary outline-none focus:border-blue-500" @change="doSearch">
|
||
<option value="">{{ t('workspace.orderDeliveryReply.statusAll') }}</option>
|
||
<option value="replied">{{ t('workspace.orderDeliveryReply.statusReplied') }}</option>
|
||
<option value="not_fully_replied">{{ t('workspace.orderDeliveryReply.statusNotFully') }}</option>
|
||
</select>
|
||
</label>
|
||
<button type="button" class="btn-primary h-8" @click="doSearch">{{ t('workspace.orderDeliveryReply.search') }}</button>
|
||
<button type="button" class="btn-ghost h-8" @click="doReset">{{ t('workspace.orderDeliveryReply.reset') }}</button>
|
||
<div class="flex-1" />
|
||
<span class="text-muted">{{ t('workspace.orderDeliveryReply.totalCount', { count: total }) }}</span>
|
||
</div>
|
||
|
||
<!-- 工具栏:全选 + 联合回复 + 批量通知(shrink-0 防压缩,py-2 紧凑高度) -->
|
||
<div class="flex shrink-0 flex-wrap items-center gap-3 rounded-2xl border border-default bg-surface px-4 py-2">
|
||
<label class="flex items-center gap-2 text-primary">
|
||
<input type="checkbox" class="h-4 w-4 rounded border-default text-blue-600" :checked="allChecked" :indeterminate.prop="someChecked" @change="togglePageAll(($event.target as HTMLInputElement).checked)" />
|
||
{{ t('workspace.orderDeliveryReply.selectAll') }}
|
||
</label>
|
||
<span class="text-muted">{{ t('workspace.orderDeliveryReply.selectedCount', { count: selectedLines.length }) }}</span>
|
||
<template v-if="canManage">
|
||
<button type="button" class="btn-primary h-8" :disabled="selectedLines.length === 0" @click="openBatchReply">
|
||
{{ t('workspace.orderDeliveryReply.batchReply') }}
|
||
</button>
|
||
<button type="button" class="btn-primary h-8" :disabled="notifiableSelected.length === 0 || notifying" @click="doNotifyBatch">
|
||
{{ t('workspace.orderDeliveryReply.batchNotify') }}
|
||
</button>
|
||
</template>
|
||
<div class="flex-1" />
|
||
<span class="whitespace-nowrap rounded-full bg-slate-100 px-3 py-1 text-muted">{{ t('workspace.orderDeliveryReply.toolbarHint') }}</span>
|
||
</div>
|
||
|
||
<!-- 列表 -->
|
||
<div class="min-h-0 flex-1 overflow-auto rounded-2xl border border-default bg-surface">
|
||
<table class="w-full border-collapse">
|
||
<!-- z-30 高于表体冻结单元格(z-20):纵向滚动时冻结列不会盖住表头 -->
|
||
<thead class="sticky top-0 z-30 bg-slate-50 text-muted [&_th]:whitespace-nowrap">
|
||
<tr>
|
||
<!-- 左侧冻结标识区(前四列):勾选/客户编号/订单日期/订单单号:项次,宽度固定保证偏移对齐 -->
|
||
<th class="sticky left-0 z-30 w-8 bg-slate-50 px-2 py-2" />
|
||
<th class="sticky left-8 z-30 w-32 min-w-[8rem] bg-slate-50 px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colCustomer') }}</th>
|
||
<th class="sticky left-[10rem] z-30 w-24 bg-slate-50 px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colOrderDate') }}</th>
|
||
<th class="sticky left-[16rem] z-30 w-40 min-w-[10rem] border-r border-default bg-slate-50 px-2 py-2 text-left shadow-[2px_0_6px_-2px_rgba(15,23,42,0.12)]">{{ t('workspace.orderDeliveryReply.colOrderLine') }}</th>
|
||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colPartNo') }}</th>
|
||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colCustomerPartNo') }}</th>
|
||
<th class="px-2 py-2 text-right">{{ t('workspace.orderDeliveryReply.colQty') }}</th>
|
||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colAgreedDate') }}</th>
|
||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colStatus') }}</th>
|
||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colReply') }}</th>
|
||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colReplyPerson') }}</th>
|
||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colSalesperson') }}</th>
|
||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colCustomerPo') }}</th>
|
||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colSpec') }}</th>
|
||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colUnit') }}</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr
|
||
v-for="line in items"
|
||
:key="lineKey(line)"
|
||
:data-line-key="lineKey(line)"
|
||
class="group border-t border-default hover:bg-slate-50"
|
||
:class="rowCls(line)"
|
||
>
|
||
<!-- 冻结单元格必须实色背景(半透明会透出滚动内容),并用 group-hover 与整行悬停/选中/直达高亮联动 -->
|
||
<td
|
||
class="sticky left-0 z-20 px-2 py-1.5"
|
||
:class="frozenCellCls(line)"
|
||
>
|
||
<input type="checkbox" class="h-4 w-4 rounded border-default text-blue-600" :checked="selected.includes(lineKey(line))" @change="toggleLine(line, ($event.target as HTMLInputElement).checked)" />
|
||
</td>
|
||
<td
|
||
class="sticky left-8 z-20 w-32 min-w-[8rem] max-w-[8rem] px-2 py-1.5"
|
||
:class="frozenCellCls(line)"
|
||
:title="line.customer_full_name || line.customer_short_name || ''"
|
||
>
|
||
<div>{{ line.customer_no || '—' }}</div>
|
||
<div class="truncate text-muted">{{ line.customer_short_name || '' }}</div>
|
||
</td>
|
||
<td
|
||
class="sticky left-[10rem] z-20 w-24 min-w-[6rem] max-w-[6rem] overflow-hidden px-2 py-1.5"
|
||
:class="frozenCellCls(line)"
|
||
>{{ line.order_date || '—' }}</td>
|
||
<td
|
||
class="sticky left-[16rem] z-20 w-40 min-w-[10rem] max-w-[10rem] overflow-hidden whitespace-nowrap border-r border-default px-2 py-1.5 font-mono shadow-[2px_0_6px_-2px_rgba(15,23,42,0.12)]"
|
||
:class="frozenCellCls(line)"
|
||
>{{ line.order_no }}:{{ line.line_no }}</td>
|
||
<td class="px-2 py-1.5" :title="line.part_name || ''">
|
||
<div class="max-w-[10rem] truncate font-mono">{{ line.part_no || '—' }}</div>
|
||
<div class="max-w-[14rem] truncate text-muted">{{ line.part_name || '' }}</div>
|
||
</td>
|
||
<td class="whitespace-nowrap px-2 py-1.5 font-mono">{{ line.customer_part_no || '—' }}</td>
|
||
<td class="px-2 py-2 text-right tabular-nums">{{ line.qty ?? '—' }}</td>
|
||
<td class="whitespace-nowrap px-2 py-1.5">{{ line.agreed_date || '—' }}</td>
|
||
<td class="px-2 py-1.5">
|
||
<span class="whitespace-nowrap rounded-full px-2.5 py-0.5 text-xs font-semibold" :class="statusMeta(line.status).cls">
|
||
{{ statusMeta(line.status).label }}
|
||
</span>
|
||
</td>
|
||
<!-- 交期回复:无批次=回复交期;有批次可展开;锁定=已锁定 -->
|
||
<td class="px-2 py-1.5 align-top">
|
||
<template v-if="line.batches.length === 0">
|
||
<span class="text-muted">{{ t('workspace.orderDeliveryReply.statusNotReplied') }}</span>
|
||
<div v-if="canManage" class="mt-0.5">
|
||
<button type="button" class="rounded-md border border-blue-200 bg-blue-50 px-2 py-0.5 text-blue-600" @click="openSingleReply(line)">
|
||
{{ t('workspace.orderDeliveryReply.replyAction') }}
|
||
</button>
|
||
</div>
|
||
</template>
|
||
<template v-else>
|
||
<div class="flex items-center gap-2">
|
||
<span class="whitespace-nowrap rounded-full border border-default bg-slate-50 px-2 py-0.5 text-muted">
|
||
{{ t('workspace.orderDeliveryReply.batchCount', { count: line.batches.length }) }} ·
|
||
{{ t('workspace.orderDeliveryReply.repliedOf', { replied: repliedQty(line), remain: undelivered(line) }) }}
|
||
<span v-if="repliedQty(line) > undelivered(line)" class="ml-1 font-semibold text-orange-500">{{ t('workspace.orderDeliveryReply.overTag') }}</span>
|
||
</span>
|
||
<button v-if="line.batches.length > 1" type="button" class="rounded-full border border-default px-2 py-0.5 text-blue-600" @click="toggleExpand(lineKey(line))">
|
||
{{ expanded.includes(lineKey(line)) ? t('workspace.orderDeliveryReply.collapse') : t('workspace.orderDeliveryReply.expand', { count: line.batches.length - 1 }) }}
|
||
</button>
|
||
</div>
|
||
<div class="mt-0.5 flex flex-col gap-0.5">
|
||
<div
|
||
v-for="(batch, idx) in line.batches"
|
||
:key="batch.seq ?? idx"
|
||
v-show="expanded.includes(lineKey(line)) || idx === 0"
|
||
class="max-w-[230px] truncate rounded border-l-[3px] border-blue-500 bg-blue-50/50 px-2 py-0.5 text-secondary"
|
||
>
|
||
{{ batch.planned_date }} · <b class="text-blue-600">{{ batch.qty }}</b> {{ line.unit }}
|
||
<i v-if="batch.remark" class="ml-1 not-italic text-muted">{{ batch.remark }}</i>
|
||
</div>
|
||
</div>
|
||
<div class="mt-0.5">
|
||
<span v-if="line.locked" class="rounded-full bg-emerald-50 px-2.5 py-0.5 text-xs font-semibold text-emerald-600">{{ t('workspace.orderDeliveryReply.lockedTag') }}</span>
|
||
<button v-else-if="canManage" type="button" class="rounded-md border border-blue-200 bg-blue-50 px-2 py-0.5 text-blue-600" @click="openSingleReply(line)">
|
||
{{ t('workspace.orderDeliveryReply.editReplyAction') }}
|
||
</button>
|
||
</div>
|
||
</template>
|
||
</td>
|
||
<!-- 交期回复人员:锁定行附带已通知对象与时间(原「通知业务部门」列已取消,信息并入此处) -->
|
||
<td class="px-2 py-1.5">
|
||
<template v-if="line.notified_employee_id || line.notified_user_name">
|
||
<div class="font-mono">{{ line.notified_employee_id || '' }}</div>
|
||
<div class="text-muted">{{ line.notified_user_name || '' }}</div>
|
||
<div v-if="line.locked" class="text-emerald-600">
|
||
{{ t('workspace.orderDeliveryReply.notifiedTag', { name: line.salesperson_name || line.salesperson_code || '' }) }}
|
||
<span class="text-muted">{{ line.notified_at || '' }}</span>
|
||
</div>
|
||
</template>
|
||
<span v-else class="text-muted">{{ t('workspace.orderDeliveryReply.pendingNotify') }}</span>
|
||
</td>
|
||
<!-- 业务员(副文案部门):与客户编号/简称同款合并展示,独立部门列已取消 -->
|
||
<td class="px-2 py-1.5" :title="line.salesperson_code || ''">
|
||
<div class="whitespace-nowrap">{{ line.salesperson_name || line.salesperson_code || '—' }}</div>
|
||
<div class="text-muted">{{ line.dept_name || line.dept_code || '' }}</div>
|
||
</td>
|
||
<td class="px-2 py-1.5 font-mono" :title="line.customer_po || ''"><span class="block max-w-[10rem] truncate">{{ line.customer_po || '—' }}</span></td>
|
||
<td class="px-2 py-1.5" :title="line.spec || ''"><span class="block max-w-[10rem] truncate">{{ line.spec || '—' }}</span></td>
|
||
<td class="px-2 py-1.5">{{ line.unit || '—' }}</td>
|
||
</tr>
|
||
<tr v-if="!loading && items.length === 0">
|
||
<td colspan="15" class="px-4 py-16 text-center text-muted">{{ t('workspace.orderDeliveryReply.empty') }}</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<!-- 分页:复用管理控制台-数据报表的 PaginationBar(摘要 + 每页条数 + 页码按钮) -->
|
||
<PaginationBar
|
||
class="[&_*]:!text-sm"
|
||
:page="page"
|
||
:page-size="pageSize"
|
||
:total="total"
|
||
:page-size-options="pageSizeOptions"
|
||
@update:page="goToPage"
|
||
@update:page-size="changePageSize"
|
||
/>
|
||
|
||
<!-- 回复弹窗 -->
|
||
<div v-if="modalVisible" class="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/40" @click.self="modalVisible = false">
|
||
<div class="flex max-h-[88vh] w-[min(960px,94vw)] flex-col overflow-hidden rounded-2xl bg-white shadow-2xl">
|
||
<div class="flex items-center gap-3 border-b border-default px-5 py-4">
|
||
<h3 class="font-bold text-primary">{{ modalTitle }}</h3>
|
||
<div class="flex-1" />
|
||
<button type="button" class="text-muted" @click="modalVisible = false">×</button>
|
||
</div>
|
||
<div class="flex-1 overflow-auto px-5 py-4">
|
||
<!-- 快速统一交期 -->
|
||
<div class="mb-4 flex flex-wrap items-end gap-3 rounded-xl border border-default bg-blue-50/40 px-4 py-3">
|
||
<label class="flex flex-col gap-1 text-muted">
|
||
{{ t('workspace.orderDeliveryReply.quickDate') }}
|
||
<input v-model="quickDate" type="date" class="h-9 rounded-lg border border-default px-3 text-primary" />
|
||
</label>
|
||
<button type="button" class="h-9 rounded-lg border border-default px-3 text-primary" @click="applyQuickDate">
|
||
{{ t('workspace.orderDeliveryReply.applyQuickDate') }}
|
||
</button>
|
||
<span class="text-muted">{{ t('workspace.orderDeliveryReply.modalHint') }}</span>
|
||
</div>
|
||
<!-- 每行批次编辑器 -->
|
||
<div v-for="entry in modalLines" :key="lineKey(entry.line)" class="mb-4 overflow-hidden rounded-xl border border-default">
|
||
<div class="flex flex-wrap items-center gap-2 bg-slate-50 px-3 py-2">
|
||
<span class="rounded bg-indigo-50 px-2 py-0.5 font-semibold text-indigo-600">{{ entry.line.order_no }}</span>
|
||
<span>{{ t('workspace.orderDeliveryReply.itemLabel', { item: entry.line.line_no }) }}</span>
|
||
<span class="text-muted">{{ entry.line.customer_no }} · {{ entry.line.customer_short_name }}</span>
|
||
<span class="text-muted">{{ entry.line.part_no }} · {{ entry.line.part_name }}</span>
|
||
<span class="ml-auto whitespace-nowrap">
|
||
{{ t('workspace.orderDeliveryReply.orderQtyLabel', { qty: entry.line.qty ?? 0, unit: entry.line.unit || '' }) }}
|
||
</span>
|
||
</div>
|
||
<div class="flex flex-col gap-2 px-3 py-3">
|
||
<div v-for="(batch, idx) in entry.batches" :key="idx" class="grid grid-cols-[170px_120px_1fr_36px] items-center gap-2">
|
||
<input v-model="batch.planned_date" type="date" class="h-9 rounded-lg border border-default px-2 text-primary" />
|
||
<input v-model="batch.qty" type="number" min="0" :placeholder="t('workspace.orderDeliveryReply.qtyPh')" class="h-9 rounded-lg border border-default px-2 text-primary" />
|
||
<input v-model="batch.remark" :placeholder="t('workspace.orderDeliveryReply.remarkPh')" class="h-9 rounded-lg border border-default px-2 text-primary" />
|
||
<button type="button" class="h-9 rounded-lg bg-rose-50 text-rose-600" :title="t('workspace.orderDeliveryReply.removeBatch')" @click="entry.batches.splice(idx, 1)">✕</button>
|
||
</div>
|
||
<button type="button" class="w-full rounded-lg border border-dashed border-slate-300 py-2 text-blue-600" @click="entry.batches.push({ planned_date: '', qty: '', remark: '' })">
|
||
{{ t('workspace.orderDeliveryReply.addBatch') }}
|
||
</button>
|
||
<!-- 行级实时校验提示:缺交期/缺数量按批次序号指出,合计不等给出已填/应填;随填写实时切换 -->
|
||
<p v-if="lineIssueText(entry)" class="text-rose-500">{{ lineIssueText(entry) }}</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="flex justify-end gap-3 border-t border-default bg-slate-50 px-5 py-3">
|
||
<button type="button" class="btn-ghost" @click="modalVisible = false">{{ t('common.cancel') }}</button>
|
||
<button type="button" class="btn-primary" :disabled="saving" @click="saveReplies">
|
||
{{ saving ? t('workspace.orderDeliveryReply.saving') : t('workspace.orderDeliveryReply.saveReply') }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|