feat(order-delivery-reply): 新增订单交期回复工作台
This commit is contained in:
1 parent
de9db2ea77
commit
49f6a0f222
57 files changed
+6502
-67
No files matched your search
@@ -0,0 +1,149 @@
|
||||
/**
|
||||
* 订单交期回复 API 类型与请求封装。
|
||||
* 依赖:统一 requestJson(失败抛 BusinessError);后端 /api/order-delivery-reply。
|
||||
* 逻辑:列表筛选分页、保存批次(单行/联合)、单行与批量通知、手动同步与最近同步状态。
|
||||
*/
|
||||
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
|
||||
/** 已保存的交期批次(计划交期 + 数量 + 可选备注)。 */
|
||||
export interface DeliveryBatch {
|
||||
seq?: number;
|
||||
planned_date: string;
|
||||
qty: string;
|
||||
remark?: string | null;
|
||||
}
|
||||
|
||||
/** 工作台订单行:ERP 快照 + 读时推导的回复状态。 */
|
||||
export interface OrderDeliveryLine {
|
||||
id: number;
|
||||
order_no: string;
|
||||
line_no: number;
|
||||
order_date?: string | null;
|
||||
customer_no?: string | null;
|
||||
customer_short_name?: string | null;
|
||||
customer_full_name?: string | null;
|
||||
salesperson_code?: string | null;
|
||||
salesperson_name?: string | null;
|
||||
dept_code?: string | null;
|
||||
dept_name?: string | null;
|
||||
customer_po?: string | null;
|
||||
part_no?: string | null;
|
||||
part_name?: string | null;
|
||||
spec?: string | null;
|
||||
customer_part_no?: string | null;
|
||||
agreed_date?: string | null;
|
||||
unit?: string | null;
|
||||
qty?: string | null;
|
||||
delivered_qty?: string | null;
|
||||
undelivered_qty?: string | null;
|
||||
status: 'not_replied' | 'partial_replied' | 'replied';
|
||||
locked: boolean;
|
||||
batches: DeliveryBatch[];
|
||||
notified_employee_id?: string | null;
|
||||
notified_user_name?: string | null;
|
||||
notified_at?: string | null;
|
||||
}
|
||||
|
||||
export interface OrderDeliveryListParams {
|
||||
order_no?: string;
|
||||
product_q?: string;
|
||||
customer_q?: string;
|
||||
order_date?: string;
|
||||
status?: '' | 'replied' | 'not_fully_replied';
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
}
|
||||
|
||||
export interface OrderDeliveryListResponse {
|
||||
items: OrderDeliveryLine[];
|
||||
page: number;
|
||||
page_size: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface OrderDeliverySyncRun {
|
||||
id: number;
|
||||
trigger: 'scheduled' | 'manual';
|
||||
status: 'running' | 'success' | 'failed';
|
||||
started_at?: string | null;
|
||||
finished_at?: string | null;
|
||||
line_count: number;
|
||||
error_message?: string | null;
|
||||
}
|
||||
|
||||
/** 批量操作逐行结果:ok=false 带 error 文案;skipped 带 reason(already_locked / no_batches)。 */
|
||||
export interface BatchItemResult {
|
||||
order_no?: string;
|
||||
line_no?: number;
|
||||
ok: boolean;
|
||||
skipped?: boolean;
|
||||
reason?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface BatchSummary {
|
||||
succeeded: number;
|
||||
failed: number;
|
||||
skipped: number;
|
||||
items: BatchItemResult[];
|
||||
}
|
||||
|
||||
/** 分页查询已同步订单行(erp_missing 行由后端排除)。 */
|
||||
export const listOrderDeliveryLines = (params?: OrderDeliveryListParams) => {
|
||||
const query = new URLSearchParams();
|
||||
if (params?.order_no) query.set('order_no', params.order_no);
|
||||
if (params?.product_q) query.set('product_q', params.product_q);
|
||||
if (params?.customer_q) query.set('customer_q', params.customer_q);
|
||||
if (params?.order_date) query.set('order_date', params.order_date);
|
||||
if (params?.status) query.set('status', params.status);
|
||||
if (params?.page) query.set('page', String(params.page));
|
||||
if (params?.page_size) query.set('page_size', String(params.page_size));
|
||||
const suffix = query.toString() ? `?${query.toString()}` : '';
|
||||
return requestJson<OrderDeliveryListResponse>(`/api/order-delivery-reply/lines${suffix}`);
|
||||
};
|
||||
|
||||
/** 保存单行交期批次(未锁定行整表替换)。 */
|
||||
export const saveOrderDeliveryBatches = (
|
||||
orderNo: string,
|
||||
lineNo: number,
|
||||
batches: { planned_date: string; qty: string | number; remark?: string | null }[],
|
||||
) =>
|
||||
requestJson<{ order_no: string; line_no: number; batches: DeliveryBatch[]; total_qty: string }>(
|
||||
`/api/order-delivery-reply/lines/${encodeURIComponent(orderNo)}/${lineNo}/batches`,
|
||||
{ method: 'PUT', body: JSON.stringify({ batches }) },
|
||||
);
|
||||
|
||||
/** 联合回复:对多行逐行保存批次(只保存,不通知不锁定)。 */
|
||||
export const batchReplyOrderDelivery = (
|
||||
items: { order_no: string; line_no: number; batches: { planned_date: string; qty: string | number; remark?: string | null }[] }[],
|
||||
) =>
|
||||
requestJson<BatchSummary>('/api/order-delivery-reply/batch-reply', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ items }),
|
||||
});
|
||||
|
||||
/** 单行发送通知业务部门(企微),成功后行级锁定。 */
|
||||
export const notifyOrderDeliveryLine = (orderNo: string, lineNo: number) =>
|
||||
requestJson<{ order_no: string; line_no: number; locked: boolean; notified_user_name?: string | null; notified_at?: string | null }>(
|
||||
`/api/order-delivery-reply/lines/${encodeURIComponent(orderNo)}/${lineNo}/notify`,
|
||||
{ method: 'POST' },
|
||||
);
|
||||
|
||||
/** 批量通知勾选行;无批次/已锁定跳过,单行失败不回滚其它行。 */
|
||||
export const notifyOrderDeliveryBatch = (lines: { order_no: string; line_no: number }[]) =>
|
||||
requestJson<BatchSummary>('/api/order-delivery-reply/notify-batch', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ lines }),
|
||||
});
|
||||
|
||||
/** 手动触发 ERP 全量同步(范围与 07:00 排程一致)。 */
|
||||
export const runOrderDeliverySync = () =>
|
||||
requestJson<{ run_id: number | null; status: 'success' | 'skipped'; line_count: number }>(
|
||||
'/api/order-delivery-reply/sync',
|
||||
{ method: 'POST' },
|
||||
);
|
||||
|
||||
/** 最近一次同步运行记录;从未同步过返回 null。 */
|
||||
export const getLatestOrderDeliverySync = () =>
|
||||
requestJson<OrderDeliverySyncRun | null>('/api/order-delivery-reply/sync/latest');
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* features/order-delivery-reply/constants.ts
|
||||
* 用途:订单交期回复域共享常量(功能权限键)。
|
||||
* 依赖:与后端 app/models/user.py._role_default_feature_permissions 的键名一一对应。
|
||||
* 逻辑:manage=生管可写(保存/通知/同步),access=业务只读;manage 命中视为有 access。
|
||||
*/
|
||||
|
||||
export const ORDER_DELIVERY_REPLY_MANAGE_PERMISSION = 'order_delivery_reply.manage';
|
||||
export const ORDER_DELIVERY_REPLY_ACCESS_PERMISSION = 'order_delivery_reply.access';
|
||||
@@ -0,0 +1,569 @@
|
||||
/**
|
||||
* features/order-delivery-reply/views/OrderDeliveryReplyPage.vue
|
||||
* 用途:订单交期回复工作台操作页——筛选分页、单行/联合回复批次、单行/批量通知、手动同步。
|
||||
* 依赖:api/orderDeliveryReply.api(统一 requestJson)、useMessage、auth store(manage/access 权限)。
|
||||
* 逻辑:所有数据只读本地快照;保存与通知是两步(联合回复只保存,批量通知才发送并锁定);
|
||||
* 保存/通知成功后即时刷新列表(需求 §9);仅 access 用户隐藏全部写操作。
|
||||
* 列顺序:客户编号(简称副文案) → 订单日期 → 订单单号:项次 → 产品编号(品名副文案) →
|
||||
* 客户产品编号 → 数量 → 约定交货日 → 交期回复状态 → 交期回复 → 交期回复人员 →
|
||||
* 业务员(部门副文案) → 客户订单 → 规格 → 单位;独立的部门列/品名列已并入合并展示。
|
||||
*/
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, 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 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({ order_no: '', product_q: '', customer_q: '', 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() {
|
||||
Object.assign(appliedFilters, filters);
|
||||
page.value = 1;
|
||||
void loadLines();
|
||||
}
|
||||
|
||||
function doReset() {
|
||||
Object.assign(filters, { order_no: '', product_q: '', customer_q: '', 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; }));
|
||||
}
|
||||
|
||||
/** 拆分合计超出未交数量时仅提醒不拦截(需求 §9)。 */
|
||||
const overQtyEntries = computed(() =>
|
||||
modalLines.value
|
||||
.filter((entry) => entry.batches.some((batch) => batch.planned_date && Number(batch.qty) > 0))
|
||||
.map((entry) => ({
|
||||
entry,
|
||||
total: entry.batches.reduce((sum, batch) => sum + (batch.planned_date && Number(batch.qty) > 0 ? Number(batch.qty) : 0), 0),
|
||||
}))
|
||||
.filter(({ entry, total }) => total > undelivered(entry.line)),
|
||||
);
|
||||
|
||||
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 });
|
||||
}
|
||||
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');
|
||||
|
||||
onMounted(() => {
|
||||
// 企微卡片 jump_path 带 order_no/line_no 直达:自动填入筛选并命中该行。
|
||||
const query = useRoute().query;
|
||||
if (typeof query.order_no === 'string' && query.order_no) {
|
||||
filters.order_no = query.order_no;
|
||||
Object.assign(appliedFilters, filters);
|
||||
}
|
||||
void loadLines();
|
||||
void loadLatestSync();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 全页统一字号:与表头一致(text-xs 12px),根容器设定基准,子元素不再覆写 -->
|
||||
<div class="flex min-h-screen flex-col gap-4 p-6 text-xs">
|
||||
<!-- 页头:标题 + 最近同步 + 手动刷新 -->
|
||||
<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 text-xs" :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>
|
||||
|
||||
<!-- 搜索区 -->
|
||||
<div class="flex flex-wrap items-end gap-4 rounded-2xl border border-default bg-surface px-4 py-4">
|
||||
<label class="flex flex-col gap-1 text-xs text-muted">
|
||||
{{ t('workspace.orderDeliveryReply.filterOrderNo') }}
|
||||
<input v-model="filters.order_no" class="h-9 min-w-[168px] rounded-lg border border-default px-3 text-primary outline-none focus:border-blue-500" :placeholder="t('workspace.orderDeliveryReply.filterOrderNoPh')" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1 text-xs text-muted">
|
||||
{{ t('workspace.orderDeliveryReply.filterProduct') }}
|
||||
<input v-model="filters.product_q" class="h-9 min-w-[200px] rounded-lg border border-default px-3 text-primary outline-none focus:border-blue-500" :placeholder="t('workspace.orderDeliveryReply.filterProductPh')" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1 text-xs text-muted">
|
||||
{{ t('workspace.orderDeliveryReply.filterCustomer') }}
|
||||
<input v-model="filters.customer_q" class="h-9 min-w-[150px] rounded-lg border border-default px-3 text-primary outline-none focus:border-blue-500" :placeholder="t('workspace.orderDeliveryReply.filterCustomerPh')" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1 text-xs text-muted">
|
||||
{{ t('workspace.orderDeliveryReply.filterOrderDate') }}
|
||||
<input v-model="filters.order_date" type="date" class="h-9 rounded-lg border border-default px-3 text-primary outline-none focus:border-blue-500" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1 text-xs text-muted">
|
||||
{{ t('workspace.orderDeliveryReply.filterStatus') }}
|
||||
<!-- 状态筛选选择即生效(无需再点查询);其余条件仍由「查询」统一提交 -->
|
||||
<select v-model="filters.status" class="h-9 min-w-[140px] rounded-lg border border-default bg-white px-3 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-9" @click="doSearch">{{ t('workspace.orderDeliveryReply.search') }}</button>
|
||||
<button type="button" class="btn-ghost h-9" @click="doReset">{{ t('workspace.orderDeliveryReply.reset') }}</button>
|
||||
<div class="flex-1" />
|
||||
<span class="text-xs text-muted">{{ t('workspace.orderDeliveryReply.totalCount', { count: total }) }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 工具栏:全选 + 联合回复 + 批量通知 -->
|
||||
<div class="flex flex-wrap items-center gap-3 rounded-2xl border border-default bg-surface px-4 py-3">
|
||||
<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-9" :disabled="selectedLines.length === 0" @click="openBatchReply">
|
||||
{{ t('workspace.orderDeliveryReply.batchReply') }}
|
||||
</button>
|
||||
<button type="button" class="btn-primary h-9" :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-xs 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">
|
||||
<thead class="sticky top-0 z-10 bg-slate-50 text-xs text-muted [&_th]:whitespace-nowrap">
|
||||
<tr>
|
||||
<th class="w-10 px-2 py-2" />
|
||||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colCustomer') }}</th>
|
||||
<th class="px-2 py-2 text-left">{{ t('workspace.orderDeliveryReply.colOrderDate') }}</th>
|
||||
<th class="px-2 py-2 text-left">{{ 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)"
|
||||
class="border-t border-default hover:bg-slate-50"
|
||||
:class="selected.includes(lineKey(line)) ? 'bg-blue-50/60' : ''"
|
||||
>
|
||||
<td class="px-2 py-2">
|
||||
<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="px-2 py-2" :title="line.customer_full_name || line.customer_short_name || ''">
|
||||
<div>{{ line.customer_no || '—' }}</div>
|
||||
<div class="text-xs text-muted">{{ line.customer_short_name || '' }}</div>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-2 py-2">{{ line.order_date || '—' }}</td>
|
||||
<td class="whitespace-nowrap px-2 py-2 font-mono text-xs">{{ line.order_no }}:{{ line.line_no }}</td>
|
||||
<td class="px-2 py-2" :title="line.part_name || ''">
|
||||
<div class="whitespace-nowrap font-mono text-xs">{{ line.part_no || '—' }}</div>
|
||||
<div class="text-xs text-muted">{{ line.part_name || '' }}</div>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-2 py-2 font-mono text-xs">{{ 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-2">{{ line.agreed_date || '—' }}</td>
|
||||
<td class="px-2 py-2">
|
||||
<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-2 align-top">
|
||||
<template v-if="line.batches.length === 0">
|
||||
<span class="text-muted">{{ t('workspace.orderDeliveryReply.statusNotReplied') }}</span>
|
||||
<div v-if="canManage" class="mt-1">
|
||||
<button type="button" class="rounded-md border border-blue-200 bg-blue-50 px-2 py-0.5 text-xs 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="rounded-full border border-default bg-slate-50 px-2 py-0.5 text-xs 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-xs 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-1 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="rounded border-l-[3px] border-blue-500 bg-blue-50/50 px-2 py-0.5 text-xs 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-1">
|
||||
<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-xs text-blue-600" @click="openSingleReply(line)">
|
||||
{{ t('workspace.orderDeliveryReply.editReplyAction') }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</td>
|
||||
<!-- 交期回复人员:锁定行附带已通知对象与时间(原「通知业务部门」列已取消,信息并入此处) -->
|
||||
<td class="px-2 py-2">
|
||||
<template v-if="line.notified_employee_id || line.notified_user_name">
|
||||
<div class="font-mono text-xs">{{ line.notified_employee_id || '' }}</div>
|
||||
<div class="text-xs text-muted">{{ line.notified_user_name || '' }}</div>
|
||||
<div v-if="line.locked" class="text-xs 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-2" :title="line.salesperson_code || ''">
|
||||
<div class="whitespace-nowrap">{{ line.salesperson_name || line.salesperson_code || '—' }}</div>
|
||||
<div class="text-xs text-muted">{{ line.dept_name || line.dept_code || '' }}</div>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-2 py-2 font-mono text-xs">{{ line.customer_po || '—' }}</td>
|
||||
<td class="px-2 py-2">{{ line.spec || '—' }}</td>
|
||||
<td class="px-2 py-2">{{ 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-xs"
|
||||
: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-xs 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-xs 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 text-xs">
|
||||
<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">
|
||||
{{ t('workspace.orderDeliveryReply.undeliveredLabel', { remain: undelivered(entry.line), 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>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="overQtyEntries.length" class="text-xs text-orange-500">
|
||||
{{ t('workspace.orderDeliveryReply.overWarning', { detail: overQtyEntries.map(({ entry, total }) => `${entry.line.order_no}:${entry.line.line_no} ${total} > ${undelivered(entry.line)}`).join(';') }) }}
|
||||
</p>
|
||||
</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>
|
||||
Reference in new issue
Block a user