123 lines
5.1 KiB
Vue
123 lines
5.1 KiB
Vue
/**
|
|
* features/chat/components/messages/MaintenanceDeviceResultCard.vue
|
|
* 用途:设备维保助手会话中的设备台账查询结果卡片。
|
|
* 依赖:chat.types、ledger/record 类型、vue-i18n。
|
|
* 逻辑:后端返回 maintenance-device-result payload 后,本组件按原型展示设备基础信息、匹配状态和快捷操作。
|
|
*/
|
|
<script setup lang="ts">
|
|
import { computed } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import type { ChatMessage } from '../../types/chat.types';
|
|
import type { MaintenanceDevice } from '@/features/maintenance/types/ledger.types';
|
|
import type { MaintenanceRecord } from '@/features/maintenance/types/record.types';
|
|
|
|
interface MaintenanceDeviceResultPayload {
|
|
matched?: boolean;
|
|
device?: MaintenanceDevice;
|
|
records?: MaintenanceRecord[];
|
|
actions?: Array<{ id: string; label: string }>;
|
|
}
|
|
|
|
const props = defineProps<{
|
|
message: ChatMessage;
|
|
}>();
|
|
|
|
const { t } = useI18n();
|
|
|
|
const payload = computed<MaintenanceDeviceResultPayload | null>(() => {
|
|
const raw = props.message.payload;
|
|
if (!raw || typeof raw !== 'object') return null;
|
|
return raw as MaintenanceDeviceResultPayload;
|
|
});
|
|
|
|
const device = computed(() => payload.value?.device || null);
|
|
const records = computed(() => payload.value?.records || []);
|
|
|
|
const statusLabel = computed(() => {
|
|
const status = device.value?.deviceStatus;
|
|
if (status === 'in_use') return t('maintenance.ledger.status.inUse');
|
|
if (status === 'disabled') return t('maintenance.ledger.status.disabled');
|
|
if (status === 'scrapped') return t('maintenance.ledger.status.scrapped');
|
|
if (status === 'sold') return t('maintenance.ledger.status.sold');
|
|
return status || '-';
|
|
});
|
|
|
|
const rows = computed(() => {
|
|
const item = device.value;
|
|
if (!item) return [];
|
|
return [
|
|
[
|
|
{ label: t('maintenance.ledger.fields.deviceCode'), value: item.deviceCode },
|
|
{ label: t('maintenance.ledger.fields.deviceName'), value: item.deviceName },
|
|
],
|
|
[
|
|
{ label: t('maintenance.ledger.fields.modelSpec'), value: item.modelSpec },
|
|
{ label: t('maintenance.ledger.fields.department'), value: item.department },
|
|
],
|
|
[
|
|
{ label: t('maintenance.ledger.fields.devicePosition'), value: item.installLocation },
|
|
{ label: t('maintenance.ledger.fields.deviceStatus'), value: statusLabel.value },
|
|
],
|
|
[
|
|
{ label: t('maintenance.ledger.fields.manufacturer'), value: item.manufacturer },
|
|
{ label: t('maintenance.ledger.fields.startDate'), value: item.startDate },
|
|
],
|
|
];
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<section v-if="device" class="mt-3 rounded-xl border border-slate-300 bg-white p-3 text-sm text-slate-800 shadow-sm">
|
|
<div class="flex items-center justify-between gap-3 rounded-t-lg border border-slate-200 bg-slate-50 px-3 py-2">
|
|
<h3 class="font-semibold">{{ t('maintenance.chat.deviceLedgerInfo') }}</h3>
|
|
<span class="rounded-full bg-emerald-50 px-2.5 py-0.5 text-xs font-semibold text-emerald-700">
|
|
{{ t('maintenance.chat.matched') }}
|
|
</span>
|
|
</div>
|
|
|
|
<div class="overflow-hidden border-x border-b border-slate-200">
|
|
<table class="w-full table-fixed text-sm">
|
|
<tbody>
|
|
<tr v-for="(row, rowIndex) in rows" :key="rowIndex" class="border-t border-slate-200 first:border-t-0">
|
|
<template v-for="cell in row" :key="cell.label">
|
|
<th class="w-[16%] bg-slate-100 px-3 py-2 text-left font-semibold text-slate-700">{{ cell.label }}</th>
|
|
<td class="w-[34%] px-3 py-2 text-slate-800">{{ cell.value || '-' }}</td>
|
|
</template>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div v-if="records.length" class="mt-3 overflow-hidden rounded-lg border border-slate-200">
|
|
<div class="bg-slate-50 px-3 py-2 text-xs font-semibold text-slate-600">
|
|
{{ t('maintenance.chat.recentRecords', { count: records.length }) }}
|
|
</div>
|
|
<table class="w-full text-left text-xs">
|
|
<thead class="bg-slate-50 text-slate-500">
|
|
<tr>
|
|
<th class="px-3 py-2">{{ t('maintenance.record.fields.reportDate') }}</th>
|
|
<th class="px-3 py-2">{{ t('maintenance.record.fields.faultDescription') }}</th>
|
|
<th class="px-3 py-2">{{ t('maintenance.record.fields.repairer') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-for="record in records.slice(0, 3)" :key="record.id" class="border-t border-slate-200">
|
|
<td class="px-3 py-2">{{ record.reportDate || '-' }}</td>
|
|
<td class="max-w-[260px] truncate px-3 py-2">{{ record.faultDescription || '-' }}</td>
|
|
<td class="px-3 py-2">{{ record.repairer || '-' }}</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="mt-3 flex flex-wrap gap-2">
|
|
<button type="button" class="rounded-lg bg-brand-600 px-3 py-2 text-xs font-semibold text-white">
|
|
{{ t('maintenance.chat.viewRepairHistory') }}
|
|
</button>
|
|
<button type="button" class="rounded-lg border border-slate-300 bg-white px-3 py-2 text-xs font-semibold text-slate-700">
|
|
{{ t('maintenance.chat.addRepairRecord') }}
|
|
</button>
|
|
</div>
|
|
</section>
|
|
</template>
|