Files
syops/frontend/src/features/equipment-acceptance/views/EquipmentAcceptanceDetailPage.vue
T

315 lines
12 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!--
features/equipment-acceptance/views/EquipmentAcceptanceDetailPage.vue
用途:一张验收单的详情卡片,展示状态徽章、停留进度、当前节点和操作人。
依赖:equipment-acceptance.api、vue-i18n、统一消息提示。
逻辑:由 Chat 作业面在选中某行后展示。操作人只显示姓名和工号。
进度条只按签核天数画到 30/37/44/51,不表示已经发送。
-->
<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { BusinessError } from '@/shared/api/client';
import { useMessage } from '@/shared/composables/useMessage';
import {
getEquipmentAcceptanceOrder,
type EquipmentAcceptanceOrder,
} from '../api/equipment-acceptance.api';
const props = defineProps<{
orderId: number;
}>();
const emit = defineEmits<{
back: [];
}>();
type BadgeTone = 'red' | 'green' | 'gray';
const STOPPED_STATUSES = new Set([
'stopped_returned',
'stopped_cannot_accept',
'stopped_archived',
'stopped_force_finished',
'stopped_voided',
'stopped_revoked',
]);
const FLOW_STATUS_KEYS: Record<number, string> = {
0: 'draft',
1: 'approving',
3: 'archived',
4: 'forceFinished',
5: 'voided',
6: 'pendingSubmit',
7: 'withdrawn',
8: 'withdrawn',
99: 'withdrawn',
[-99]: 'withdrawn',
};
const REMINDER_DAYS = [30, 37, 44, 51];
const { t } = useI18n();
const msg = useMessage();
const loading = ref(false);
const order = ref<EquipmentAcceptanceOrder | null>(null);
/**
* 读取当前验收单详情。
* 核心逻辑:orderId 变化时重新请求。失败清空详情,避免上一张单残留。
*/
async function load(): Promise<void> {
loading.value = true;
try {
order.value = await getEquipmentAcceptanceOrder(props.orderId);
} catch (error) {
order.value = null;
msg.error(error instanceof BusinessError ? error.message : t('admin.equipmentAcceptance.detailLoadFailed'));
} finally {
loading.value = false;
}
}
/**
* 只取日期部分。没有值时显示横线。
* @param value - 接口时间字符串
* @returns 日期文本
*/
function dateText(value?: string | null): string {
if (!value) return '—';
return value.slice(0, 10);
}
/**
* 把 0/1 写成否/是。可以验收为空时显示未标明,退回在同步时已把空收成否。
* @param value - 标准 0 否、1 是
* @param emptyLabel - 空值文案
* @returns 展示文案
*/
function yesNo(value: number | null | undefined, emptyLabel: string): string {
if (value === 1) return t('common.yes');
if (value === 0) return t('common.no');
return emptyLabel;
}
/**
* 把流程状态原值写成名称。7、8、99、-99 都显示为撤销,字典没有的数字仍显示原值。
* @param value - flowstatus
* @returns 流程状态文案
*/
function flowText(value?: number | null): string {
if (value === undefined || value === null) return '—';
const key = FLOW_STATUS_KEYS[value];
return key ? t(`admin.equipmentAcceptance.flowStatusName.${key}`) : String(value);
}
/**
* 未开始或没有天数时显示横线,其余显示「N 天」。
* @param item - 当前验收单
* @returns 签核天数文案
*/
function dwellText(item: EquipmentAcceptanceOrder): string {
if (item.monitor_status === 'not_started' || item.dwell_days == null) return '—';
return t('admin.equipmentAcceptance.daysValue', { days: item.dwell_days });
}
/**
* 当前节点名称。没有节点时为空,模板改显示横线。
* @param item - 当前验收单
* @returns 节点名称列表
*/
function nodeNames(item: EquipmentAcceptanceOrder): string[] {
return (item.nodes || []).map((node) => node.node_name).filter((name): name is string => Boolean(name));
}
/**
* 当前处理人去重后拼成一行。
* @param item - 当前验收单
* @returns 处理人姓名
*/
function handlerNames(item: EquipmentAcceptanceOrder): string {
const names = Array.from(new Set(
(item.operators || []).map((person) => person.handler_name).filter((name): name is string => Boolean(name)),
));
return names.length ? names.join('、') : '—';
}
/**
* 与列表相同的徽章颜色。红是已逾期,绿是不再提醒,灰是未开始和未超时。
* @param item - 当前验收单
* @returns 文案和颜色
*/
function statusBadge(item: EquipmentAcceptanceOrder): { label: string; tone: BadgeTone } {
if (item.monitor_status === 'watching' && item.overdue) {
return { label: t('admin.equipmentAcceptance.badgeOverdue'), tone: 'red' };
}
if (item.monitor_status === 'watching') {
return { label: t('admin.equipmentAcceptance.badgeOnTime'), tone: 'gray' };
}
return {
label: t(`admin.equipmentAcceptance.statusLabel.${item.monitor_status}`),
tone: STOPPED_STATUSES.has(item.monitor_status) ? 'green' : 'gray',
};
}
/**
* 徽章底色。
* @param tone - 徽章颜色
* @returns Tailwind 类名
*/
function badgeClass(tone: BadgeTone): string {
if (tone === 'red') return 'bg-[#fff0ef] text-[#b42318]';
if (tone === 'green') return 'bg-[#eafaf1] text-[#067647]';
return 'bg-[#edf1f6] text-[#475569]';
}
/**
* 按签核天数在 0 到第 4 档之间画进度。没有天数时不画。
* 核心逻辑:刻度至少到 60 天,避免 51 天贴在条的尽头。
*/
const track = computed(() => {
const days = order.value?.dwell_days;
if (order.value?.monitor_status === 'not_started' || days == null) return null;
const lastMark = REMINDER_DAYS[REMINDER_DAYS.length - 1] ?? 51;
const scale = Math.max(60, lastMark + 9, days);
return {
width: `${Math.min(100, Math.round((days / scale) * 100))}%`,
marks: [0, ...REMINDER_DAYS, scale].map((day) => ({
day,
left: `${(day / scale) * 100}%`,
label: day === scale ? t('admin.equipmentAcceptance.daysValue', { days: scale }) : String(day),
})),
};
});
onMounted(() => {
void load();
});
watch(() => props.orderId, () => {
void load();
});
</script>
<template>
<section class="min-h-0 flex-1 overflow-auto px-5 pb-6 pt-3">
<button
class="mb-3 rounded-lg border border-[#dce4ef] bg-white px-3 py-1.5 text-xs font-bold text-[#142033]"
type="button"
@click="emit('back')"
>
{{ t('admin.equipmentAcceptance.back') }}
</button>
<p v-if="loading && !order" class="text-sm text-[#64748b]">{{ t('admin.equipmentAcceptance.loading') }}</p>
<article v-else-if="order" class="overflow-hidden rounded-xl border border-[#dce4ef] bg-white">
<div class="flex items-start justify-between gap-3 px-4 pt-4">
<h2 class="text-lg font-bold text-[#142033]">{{ order.acceptance_no || '—' }}</h2>
<span
class="inline-flex shrink-0 rounded-full px-2 py-0.5 text-[11px] font-extrabold"
:class="badgeClass(statusBadge(order).tone)"
>
{{ statusBadge(order).label }}
</span>
</div>
<div v-if="track" class="px-7 pt-5">
<div class="h-2 overflow-hidden rounded-full bg-[#e7edf5]">
<i class="block h-full rounded-full bg-gradient-to-r from-[#93c5fd] to-[#2563eb]" :style="{ width: track.width }"></i>
</div>
<div class="relative mt-1 h-4 text-[11px] text-[#64748b]">
<span
v-for="mark in track.marks"
:key="mark.day"
class="absolute -translate-x-1/2 whitespace-nowrap"
:style="{ left: mark.left }"
>
{{ mark.label }}
</span>
</div>
</div>
<div class="flex flex-wrap gap-1.5 px-4 pb-1 pt-4">
<span
v-for="(name, index) in nodeNames(order)"
:key="`${name}-${index}`"
class="rounded-full bg-[#dbeafe] px-2 py-1 text-[11px] font-extrabold text-[#1d4ed8]"
>
{{ name }}
</span>
<span v-if="!nodeNames(order).length" class="text-sm text-[#64748b]">—</span>
</div>
<dl class="mt-3 grid border-t border-[#dce4ef] px-4 sm:grid-cols-2">
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.purchaseOrderNo') }}</dt>
<dd class="text-[#142033]">{{ order.purchase_order_no || '—' }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs sm:pl-4">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.applicant') }}</dt>
<dd class="text-[#142033]">{{ order.applicant_name || '—' }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.dwellDays') }}</dt>
<dd class="text-[#142033]">{{ dwellText(order) }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs sm:pl-4">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.timerStart') }}</dt>
<dd class="text-[#142033]">{{ dateText(order.timer_started_at) }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs sm:col-span-2">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.currentHandlers') }}</dt>
<dd class="text-[#142033]">{{ handlerNames(order) }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.canAccept') }}</dt>
<dd class="text-[#142033]">{{ yesNo(order.can_accept, t('admin.equipmentAcceptance.unspecified')) }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs sm:col-span-2">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.cannotAcceptNote') }}</dt>
<dd class="whitespace-pre-wrap text-[#142033]">{{ order.cannot_accept_note || '—' }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs sm:pl-4">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.returnFlag') }}</dt>
<dd class="text-[#142033]">{{ yesNo(order.is_returned, t('common.no')) }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.flowStatus') }}</dt>
<dd class="text-[#142033]">{{ flowText(order.flow_status_raw) }}</dd>
</div>
<div class="grid grid-cols-[108px_minmax(0,1fr)] gap-2 border-b border-[#dce4ef] py-2.5 text-xs sm:pl-4">
<dt class="font-bold text-[#64748b]">{{ t('admin.equipmentAcceptance.finishedAt') }}</dt>
<dd class="text-[#142033]">{{ dateText(order.finished_at) }}</dd>
</div>
</dl>
<div class="px-4 pb-4 pt-4">
<h3 class="text-sm font-bold text-[#142033]">{{ t('admin.equipmentAcceptance.operators') }}</h3>
<p class="mt-1 text-xs text-[#64748b]">{{ t('admin.equipmentAcceptance.operatorsNote') }}</p>
<div class="mt-3 overflow-auto rounded-xl border border-[#dce4ef]">
<table class="w-full min-w-[640px] border-collapse text-left text-xs">
<thead class="bg-[#f8fbff] text-[#64748b]">
<tr>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.operatorName') }}</th>
<th class="px-3 py-2.5 font-bold">{{ t('admin.equipmentAcceptance.jobNum') }}</th>
</tr>
</thead>
<tbody>
<tr
v-for="(item, index) in order.operators"
:key="`${item.user_id}-${item.node_id}-${index}`"
class="border-t border-[#dce4ef]"
>
<td class="px-3 py-2.5 font-bold text-[#142033]">{{ item.handler_name || '—' }}</td>
<td class="px-3 py-2.5">{{ item.handler_job_num || '—' }}</td>
</tr>
<tr v-if="!order.operators.length">
<td colspan="2" class="px-3 py-6 text-center text-[#64748b]">—</td>
</tr>
</tbody>
</table>
</div>
</div>
</article>
</section>
</template>