2025-07-30 09:13:52 +08:00
|
|
|
|
<template>
|
2025-07-31 17:32:21 +08:00
|
|
|
|
<div class="equipment-center-container">
|
2025-08-01 15:14:24 +08:00
|
|
|
|
<!-- 搜索组件 -->
|
|
|
|
|
<EquipmentSearch
|
|
|
|
|
:loading="loading"
|
|
|
|
|
@search="handleSearch"
|
|
|
|
|
@reset="handleReset"
|
|
|
|
|
/>
|
2025-07-31 17:32:21 +08:00
|
|
|
|
|
|
|
|
|
<!-- 操作按钮 -->
|
|
|
|
|
<a-card class="table-card" :bordered="false">
|
|
|
|
|
<template #title>
|
|
|
|
|
<div class="card-title">
|
|
|
|
|
<span>设备中心</span>
|
|
|
|
|
<a-button type="primary" @click="handleAdd">
|
|
|
|
|
<template #icon>
|
|
|
|
|
<IconPlus />
|
|
|
|
|
</template>
|
|
|
|
|
新增设备
|
|
|
|
|
</a-button>
|
|
|
|
|
</div>
|
2025-07-30 09:13:52 +08:00
|
|
|
|
</template>
|
2025-07-31 17:32:21 +08:00
|
|
|
|
|
|
|
|
|
<!-- 数据表格 -->
|
|
|
|
|
<a-table
|
|
|
|
|
:columns="columns"
|
|
|
|
|
:data="tableData"
|
|
|
|
|
:loading="loading"
|
|
|
|
|
:pagination="pagination"
|
|
|
|
|
row-key="equipmentId"
|
|
|
|
|
@change="handleTableChange"
|
|
|
|
|
>
|
|
|
|
|
<template #equipmentType="{ record }">
|
|
|
|
|
<a-tag :color="getEquipmentTypeColor(record.equipmentType)">
|
|
|
|
|
{{ getEquipmentTypeText(record.equipmentType) }}
|
2025-07-30 09:13:52 +08:00
|
|
|
|
</a-tag>
|
2025-07-31 17:32:21 +08:00
|
|
|
|
</template>
|
|
|
|
|
<template #equipmentStatus="{ record }">
|
|
|
|
|
<a-space>
|
|
|
|
|
<div
|
|
|
|
|
:class="getStatusDotClass(record.equipmentStatus)"
|
|
|
|
|
class="status-dot"
|
|
|
|
|
/>
|
|
|
|
|
<a-tag :color="getEquipmentStatusColor(record.equipmentStatus)">
|
|
|
|
|
{{ getEquipmentStatusText(record.equipmentStatus) }}
|
|
|
|
|
</a-tag>
|
|
|
|
|
</a-space>
|
|
|
|
|
</template>
|
|
|
|
|
<template #locationStatus="{ record }">
|
|
|
|
|
<a-tag :color="getLocationStatusColor(record.locationStatus)">
|
|
|
|
|
{{ getLocationStatusText(record.locationStatus) }}
|
|
|
|
|
</a-tag>
|
|
|
|
|
</template>
|
|
|
|
|
<template #healthStatus="{ record }">
|
|
|
|
|
<a-tag :color="getHealthStatusColor(record.healthStatus)">
|
|
|
|
|
{{ getHealthStatusText(record.healthStatus) }}
|
|
|
|
|
</a-tag>
|
|
|
|
|
</template>
|
|
|
|
|
<template #useStatus="{ record }">
|
|
|
|
|
<a-tag :color="record.useStatus === '1' ? 'blue' : 'green'">
|
|
|
|
|
{{ record.useStatus === '1' ? '使用中' : '空闲' }}
|
|
|
|
|
</a-tag>
|
|
|
|
|
</template>
|
|
|
|
|
<template #purchasePrice="{ record }">
|
|
|
|
|
<span v-if="record.purchasePrice">
|
|
|
|
|
¥{{ formatPrice(record.purchasePrice) }}
|
|
|
|
|
</span>
|
|
|
|
|
<span v-else>-</span>
|
|
|
|
|
</template>
|
|
|
|
|
<template #currentNetValue="{ record }">
|
|
|
|
|
<span v-if="record.currentNetValue">
|
|
|
|
|
¥{{ formatPrice(record.currentNetValue) }}
|
|
|
|
|
</span>
|
|
|
|
|
<span v-else>-</span>
|
|
|
|
|
</template>
|
|
|
|
|
<template #createTime="{ record }">
|
|
|
|
|
{{ formatDateTime(record.createTime) }}
|
|
|
|
|
</template>
|
|
|
|
|
<template #action="{ record }">
|
|
|
|
|
<a-space>
|
|
|
|
|
<a-button type="text" size="small" @click="handleView(record)">
|
|
|
|
|
查看
|
|
|
|
|
</a-button>
|
|
|
|
|
<a-button type="text" size="small" @click="handleDetail(record)">
|
|
|
|
|
详情
|
|
|
|
|
</a-button>
|
|
|
|
|
<a-button type="text" size="small" @click="handleEdit(record)">
|
|
|
|
|
编辑
|
|
|
|
|
</a-button>
|
|
|
|
|
<a-button
|
|
|
|
|
v-if="record.useStatus === '0'"
|
|
|
|
|
type="text"
|
|
|
|
|
size="small"
|
|
|
|
|
@click="handleAssign(record)"
|
|
|
|
|
>
|
|
|
|
|
分配
|
|
|
|
|
</a-button>
|
|
|
|
|
<a-button
|
|
|
|
|
v-if="record.useStatus === '1'"
|
|
|
|
|
type="text"
|
|
|
|
|
size="small"
|
|
|
|
|
@click="handleReturn(record)"
|
|
|
|
|
>
|
|
|
|
|
归还
|
|
|
|
|
</a-button>
|
|
|
|
|
<a-button
|
|
|
|
|
type="text"
|
|
|
|
|
size="small"
|
|
|
|
|
danger
|
|
|
|
|
@click="handleDelete(record)"
|
|
|
|
|
>
|
|
|
|
|
删除
|
|
|
|
|
</a-button>
|
|
|
|
|
</a-space>
|
|
|
|
|
</template>
|
|
|
|
|
</a-table>
|
|
|
|
|
</a-card>
|
2025-07-30 09:13:52 +08:00
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
<!-- 新增/编辑弹窗 -->
|
|
|
|
|
<DeviceModal
|
|
|
|
|
v-model:visible="modalVisible"
|
|
|
|
|
:equipment-data="currentEquipment"
|
|
|
|
|
:mode="modalMode"
|
|
|
|
|
@success="handleModalSuccess"
|
2025-07-30 09:13:52 +08:00
|
|
|
|
/>
|
2025-07-31 17:32:21 +08:00
|
|
|
|
</div>
|
2025-07-30 09:13:52 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
import { onMounted, reactive, ref, watch } from 'vue'
|
|
|
|
|
import { Modal } from '@arco-design/web-vue'
|
|
|
|
|
import { IconPlus, IconRefresh, IconSearch } from '@arco-design/web-vue/es/icon'
|
|
|
|
|
import message from '@arco-design/web-vue/es/message'
|
|
|
|
|
import DeviceModal from './components/DeviceModal.vue'
|
2025-08-01 15:14:24 +08:00
|
|
|
|
import EquipmentSearch from './components/EquipmentSearch.vue'
|
2025-07-31 17:32:21 +08:00
|
|
|
|
import router from '@/router'
|
|
|
|
|
import {
|
|
|
|
|
assignEquipment,
|
|
|
|
|
deleteEquipment,
|
|
|
|
|
pageEquipment,
|
|
|
|
|
returnEquipment,
|
|
|
|
|
} from '@/apis/equipment'
|
|
|
|
|
import type { EquipmentPageQuery, EquipmentResp } from '@/types/equipment.d'
|
|
|
|
|
|
|
|
|
|
defineOptions({ name: 'EquipmentCenter' })
|
2025-07-30 09:13:52 +08:00
|
|
|
|
|
2025-08-01 16:24:33 +08:00
|
|
|
|
// 当前搜索参数
|
|
|
|
|
const currentSearchParams = ref<EquipmentPageQuery>({})
|
2025-07-30 09:13:52 +08:00
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 表格数据
|
|
|
|
|
const tableData = ref<EquipmentResp[]>([])
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
|
|
|
|
// 分页配置
|
|
|
|
|
const pagination = reactive<any>({
|
|
|
|
|
current: 1,
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
total: 0,
|
|
|
|
|
showPageSize: true,
|
|
|
|
|
showJumper: true,
|
|
|
|
|
showTotal: (total: number) => `共 ${total} 条记录`,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 弹窗控制
|
|
|
|
|
const modalVisible = ref(false)
|
|
|
|
|
const currentEquipment = ref<EquipmentResp | null>(null)
|
|
|
|
|
const modalMode = ref<'add' | 'edit' | 'view'>('add')
|
|
|
|
|
|
|
|
|
|
// 表格列配置
|
|
|
|
|
const columns = [
|
2025-07-30 09:13:52 +08:00
|
|
|
|
{
|
2025-07-31 17:32:21 +08:00
|
|
|
|
title: '资产编号',
|
|
|
|
|
dataIndex: 'assetCode',
|
|
|
|
|
key: 'assetCode',
|
|
|
|
|
width: 120,
|
2025-07-30 09:13:52 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2025-07-31 17:32:21 +08:00
|
|
|
|
title: '设备名称',
|
|
|
|
|
dataIndex: 'equipmentName',
|
|
|
|
|
key: 'equipmentName',
|
|
|
|
|
width: 150,
|
2025-07-30 09:13:52 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2025-07-31 17:32:21 +08:00
|
|
|
|
title: '设备类型',
|
|
|
|
|
dataIndex: 'equipmentType',
|
|
|
|
|
key: 'equipmentType',
|
|
|
|
|
slotName: 'equipmentType',
|
|
|
|
|
width: 120,
|
|
|
|
|
},
|
2025-07-30 09:13:52 +08:00
|
|
|
|
{
|
2025-07-31 17:32:21 +08:00
|
|
|
|
title: '设备型号',
|
|
|
|
|
dataIndex: 'equipmentModel',
|
|
|
|
|
key: 'equipmentModel',
|
|
|
|
|
width: 120,
|
2025-07-30 09:13:52 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2025-07-31 17:32:21 +08:00
|
|
|
|
title: '序列号',
|
|
|
|
|
dataIndex: 'equipmentSn',
|
|
|
|
|
key: 'equipmentSn',
|
|
|
|
|
width: 150,
|
2025-07-30 09:13:52 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2025-07-31 17:32:21 +08:00
|
|
|
|
title: '品牌',
|
|
|
|
|
dataIndex: 'brand',
|
|
|
|
|
key: 'brand',
|
|
|
|
|
width: 100,
|
2025-07-30 09:13:52 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2025-07-31 17:32:21 +08:00
|
|
|
|
title: '设备状态',
|
|
|
|
|
dataIndex: 'equipmentStatus',
|
|
|
|
|
key: 'equipmentStatus',
|
|
|
|
|
slotName: 'equipmentStatus',
|
|
|
|
|
width: 120,
|
2025-07-30 09:13:52 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2025-07-31 17:32:21 +08:00
|
|
|
|
title: '使用状态',
|
|
|
|
|
dataIndex: 'useStatus',
|
|
|
|
|
key: 'useStatus',
|
|
|
|
|
slotName: 'useStatus',
|
|
|
|
|
width: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '位置状态',
|
|
|
|
|
dataIndex: 'locationStatus',
|
|
|
|
|
key: 'locationStatus',
|
|
|
|
|
slotName: 'locationStatus',
|
|
|
|
|
width: 120,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '物理位置',
|
|
|
|
|
dataIndex: 'physicalLocation',
|
|
|
|
|
key: 'physicalLocation',
|
|
|
|
|
width: 150,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '健康状态',
|
|
|
|
|
dataIndex: 'healthStatus',
|
|
|
|
|
key: 'healthStatus',
|
|
|
|
|
slotName: 'healthStatus',
|
|
|
|
|
width: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '负责人',
|
|
|
|
|
dataIndex: 'responsiblePerson',
|
|
|
|
|
key: 'responsiblePerson',
|
|
|
|
|
width: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '当前使用人',
|
|
|
|
|
dataIndex: 'name',
|
|
|
|
|
key: 'name',
|
|
|
|
|
width: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '所属项目',
|
|
|
|
|
dataIndex: 'projectName',
|
|
|
|
|
key: 'projectName',
|
|
|
|
|
width: 150,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '采购价格',
|
|
|
|
|
dataIndex: 'purchasePrice',
|
|
|
|
|
key: 'purchasePrice',
|
|
|
|
|
width: 120,
|
|
|
|
|
slotName: 'purchasePrice',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '当前净值',
|
|
|
|
|
dataIndex: 'currentNetValue',
|
|
|
|
|
key: 'currentNetValue',
|
|
|
|
|
width: 120,
|
|
|
|
|
slotName: 'currentNetValue',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '维护人员',
|
|
|
|
|
dataIndex: 'maintenancePerson',
|
|
|
|
|
key: 'maintenancePerson',
|
|
|
|
|
width: 100,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '创建时间',
|
|
|
|
|
dataIndex: 'createTime',
|
|
|
|
|
key: 'createTime',
|
|
|
|
|
width: 160,
|
|
|
|
|
slotName: 'createTime',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '操作',
|
|
|
|
|
key: 'action',
|
|
|
|
|
slotName: 'action',
|
|
|
|
|
width: 280,
|
|
|
|
|
fixed: 'right',
|
|
|
|
|
},
|
|
|
|
|
]
|
2025-07-30 09:13:52 +08:00
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 下拉选项
|
|
|
|
|
|
|
|
|
|
// 获取设备类型文本
|
|
|
|
|
const getEquipmentTypeText = (type: string) => {
|
|
|
|
|
const typeMap: Record<string, string> = {
|
2025-08-01 15:14:24 +08:00
|
|
|
|
detection: '检测设备',
|
|
|
|
|
maintain: '维修设备',
|
|
|
|
|
security: '安全设备',
|
|
|
|
|
office: '办公设备',
|
|
|
|
|
car: '车辆',
|
2025-07-31 17:32:21 +08:00
|
|
|
|
}
|
|
|
|
|
return typeMap[type] || type
|
|
|
|
|
}
|
2025-07-30 09:13:52 +08:00
|
|
|
|
|
|
|
|
|
// 获取设备类型颜色
|
2025-07-31 17:32:21 +08:00
|
|
|
|
const getEquipmentTypeColor = (type: string) => {
|
|
|
|
|
const colorMap: Record<string, string> = {
|
2025-08-01 15:14:24 +08:00
|
|
|
|
detection: 'blue',
|
|
|
|
|
maintain: 'green',
|
|
|
|
|
security: 'orange',
|
|
|
|
|
office: 'purple',
|
|
|
|
|
car: 'red',
|
2025-07-31 17:32:21 +08:00
|
|
|
|
}
|
|
|
|
|
return colorMap[type] || 'default'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取设备状态文本
|
|
|
|
|
const getEquipmentStatusText = (status: string) => {
|
|
|
|
|
const statusMap: Record<string, string> = {
|
|
|
|
|
normal: '正常',
|
2025-08-01 15:14:24 +08:00
|
|
|
|
repair: '维修中',
|
|
|
|
|
maintain: '保养中',
|
|
|
|
|
scrap: '报废',
|
2025-07-31 17:32:21 +08:00
|
|
|
|
}
|
|
|
|
|
return statusMap[status] || status
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取设备状态颜色
|
|
|
|
|
const getEquipmentStatusColor = (status: string) => {
|
2025-07-30 09:13:52 +08:00
|
|
|
|
const colorMap: Record<string, string> = {
|
2025-07-31 17:32:21 +08:00
|
|
|
|
normal: 'green',
|
2025-08-01 15:14:24 +08:00
|
|
|
|
repair: 'orange',
|
|
|
|
|
maintain: 'blue',
|
|
|
|
|
scrap: 'red',
|
2025-07-31 17:32:21 +08:00
|
|
|
|
}
|
|
|
|
|
return colorMap[status] || 'default'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取位置状态文本
|
|
|
|
|
const getLocationStatusText = (status: string) => {
|
|
|
|
|
const statusMap: Record<string, string> = {
|
|
|
|
|
in_stock: '库存中',
|
|
|
|
|
allocated: '已分配',
|
|
|
|
|
repair: '维修中',
|
|
|
|
|
scrap: '待报废',
|
|
|
|
|
scrapped: '已报废',
|
|
|
|
|
borrowed: '外借中',
|
|
|
|
|
lost: '丢失',
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
2025-07-31 17:32:21 +08:00
|
|
|
|
return statusMap[status] || status
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 获取位置状态颜色
|
|
|
|
|
const getLocationStatusColor = (status: string) => {
|
2025-07-30 09:13:52 +08:00
|
|
|
|
const colorMap: Record<string, string> = {
|
2025-07-31 17:32:21 +08:00
|
|
|
|
in_stock: 'green',
|
|
|
|
|
allocated: 'blue',
|
|
|
|
|
repair: 'orange',
|
|
|
|
|
scrap: 'red',
|
|
|
|
|
scrapped: 'red',
|
|
|
|
|
borrowed: 'purple',
|
|
|
|
|
lost: 'red',
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
2025-07-31 17:32:21 +08:00
|
|
|
|
return colorMap[status] || 'default'
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 获取健康状态文本
|
|
|
|
|
const getHealthStatusText = (status: string) => {
|
|
|
|
|
const statusMap: Record<string, string> = {
|
|
|
|
|
excellent: '优秀',
|
|
|
|
|
good: '良好',
|
|
|
|
|
normal: '一般',
|
|
|
|
|
poor: '较差',
|
|
|
|
|
bad: '差',
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
2025-07-31 17:32:21 +08:00
|
|
|
|
return statusMap[status] || status
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取健康状态颜色
|
|
|
|
|
const getHealthStatusColor = (status: string) => {
|
|
|
|
|
const colorMap: Record<string, string> = {
|
|
|
|
|
excellent: 'green',
|
|
|
|
|
good: 'blue',
|
|
|
|
|
normal: 'orange',
|
|
|
|
|
poor: 'red',
|
|
|
|
|
bad: 'red',
|
|
|
|
|
}
|
|
|
|
|
return colorMap[status] || 'default'
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取状态点样式
|
|
|
|
|
const getStatusDotClass = (status: string) => {
|
|
|
|
|
const classMap: Record<string, string> = {
|
2025-07-31 17:32:21 +08:00
|
|
|
|
normal: 'normal-dot',
|
2025-08-01 15:14:24 +08:00
|
|
|
|
repair: 'maintenance-dot',
|
|
|
|
|
maintain: 'maintenance-dot',
|
|
|
|
|
scrap: 'scrapped-dot',
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
2025-07-31 17:32:21 +08:00
|
|
|
|
return classMap[status] || 'normal-dot'
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 格式化价格
|
|
|
|
|
const formatPrice = (price: number) => {
|
|
|
|
|
if (!price) return '0.00'
|
|
|
|
|
return price.toLocaleString('zh-CN', {
|
|
|
|
|
minimumFractionDigits: 2,
|
|
|
|
|
maximumFractionDigits: 2,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 格式化日期时间
|
|
|
|
|
const formatDateTime = (dateTime: string) => {
|
|
|
|
|
if (!dateTime) return '-'
|
|
|
|
|
try {
|
|
|
|
|
const date = new Date(dateTime)
|
|
|
|
|
return date.toLocaleString('zh-CN', {
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
month: '2-digit',
|
|
|
|
|
day: '2-digit',
|
|
|
|
|
hour: '2-digit',
|
|
|
|
|
minute: '2-digit',
|
|
|
|
|
})
|
|
|
|
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return dateTime
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 数据转换函数
|
|
|
|
|
const transformBackendData = (data: any[]) => {
|
|
|
|
|
console.log('转换前的数据:', data)
|
|
|
|
|
return data.map((item) => {
|
|
|
|
|
console.log('处理单个项目:', item)
|
2025-08-01 15:14:24 +08:00
|
|
|
|
|
|
|
|
|
// 格式化时间字段
|
|
|
|
|
const formatDateTime = (dateTime: any) => {
|
|
|
|
|
if (!dateTime) return ''
|
|
|
|
|
try {
|
|
|
|
|
return new Date(dateTime).toLocaleString('zh-CN', {
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
month: '2-digit',
|
|
|
|
|
day: '2-digit',
|
|
|
|
|
hour: '2-digit',
|
|
|
|
|
minute: '2-digit',
|
|
|
|
|
})
|
|
|
|
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return dateTime
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 直接返回后端数据,只格式化时间字段
|
2025-07-31 17:32:21 +08:00
|
|
|
|
return {
|
2025-08-01 15:14:24 +08:00
|
|
|
|
...item,
|
|
|
|
|
createTime: formatDateTime(item.createTime),
|
|
|
|
|
updateTime: formatDateTime(item.updateTime),
|
|
|
|
|
purchaseTime: formatDateTime(item.purchaseTime),
|
|
|
|
|
inStockTime: formatDateTime(item.inStockTime),
|
|
|
|
|
activationTime: formatDateTime(item.activationTime),
|
|
|
|
|
expectedScrapTime: formatDateTime(item.expectedScrapTime),
|
|
|
|
|
actualScrapTime: formatDateTime(item.actualScrapTime),
|
|
|
|
|
statusChangeTime: formatDateTime(item.statusChangeTime),
|
|
|
|
|
warrantyExpireDate: formatDateTime(item.warrantyExpireDate),
|
|
|
|
|
lastMaintenanceDate: formatDateTime(item.lastMaintenanceDate),
|
|
|
|
|
nextMaintenanceDate: formatDateTime(item.nextMaintenanceDate),
|
2025-07-31 17:32:21 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载数据
|
2025-08-01 15:14:24 +08:00
|
|
|
|
const loadData = async (searchParams?: EquipmentPageQuery) => {
|
2025-08-01 16:24:33 +08:00
|
|
|
|
console.log('📊 loadData - 开始加载数据')
|
|
|
|
|
console.log('📊 loadData - 接收到的搜索参数:', searchParams)
|
|
|
|
|
console.log('📊 loadData - 搜索参数类型:', typeof searchParams)
|
|
|
|
|
console.log('📊 loadData - 当前分页配置:', pagination)
|
|
|
|
|
|
2025-07-30 09:13:52 +08:00
|
|
|
|
loading.value = true
|
2025-07-31 17:32:21 +08:00
|
|
|
|
try {
|
|
|
|
|
const params = {
|
|
|
|
|
pageSize: pagination.pageSize,
|
|
|
|
|
page: pagination.current,
|
2025-08-01 15:14:24 +08:00
|
|
|
|
...(searchParams || {}), // 添加搜索条件
|
2025-07-31 17:32:21 +08:00
|
|
|
|
}
|
2025-08-01 15:14:24 +08:00
|
|
|
|
|
2025-08-01 16:24:33 +08:00
|
|
|
|
console.log('📊 loadData - 构建的完整请求参数:', params)
|
|
|
|
|
console.log('📊 loadData - 请求参数类型:', typeof params)
|
|
|
|
|
console.log('📊 loadData - 请求参数是否为对象:', params && typeof params === 'object')
|
|
|
|
|
|
|
|
|
|
// 详细打印每个搜索字段
|
|
|
|
|
if (searchParams) {
|
|
|
|
|
console.log('📊 loadData - 搜索字段详情:')
|
|
|
|
|
Object.entries(searchParams).forEach(([key, value]) => {
|
|
|
|
|
console.log(` ${key}: ${value} (类型: ${typeof value})`)
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-08-01 15:14:24 +08:00
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
const res = await pageEquipment(params)
|
|
|
|
|
|
|
|
|
|
console.log('API响应:', res)
|
|
|
|
|
|
|
|
|
|
// 兼容不同的响应格式
|
|
|
|
|
if (res.success || res.status === 200 || res.code === 200) {
|
|
|
|
|
// 处理数据,确保数据格式正确
|
|
|
|
|
let dataList: any[] = []
|
|
|
|
|
|
|
|
|
|
// 检查不同的数据字段
|
|
|
|
|
if (Array.isArray(res.data)) {
|
|
|
|
|
dataList = res.data
|
|
|
|
|
} else if (res.data && Array.isArray((res.data as any).records)) {
|
|
|
|
|
dataList = (res.data as any).records
|
|
|
|
|
} else if (res.data && Array.isArray((res.data as any).list)) {
|
|
|
|
|
dataList = (res.data as any).list
|
|
|
|
|
} else if (res.data && Array.isArray((res.data as any).rows)) {
|
|
|
|
|
dataList = (res.data as any).rows
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('处理后的数据列表:', dataList)
|
|
|
|
|
|
|
|
|
|
if (dataList.length > 0) {
|
|
|
|
|
const transformedData = transformBackendData(dataList)
|
|
|
|
|
console.log('转换后的数据:', transformedData)
|
|
|
|
|
tableData.value = transformedData
|
|
|
|
|
} else {
|
|
|
|
|
tableData.value = []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置总数
|
|
|
|
|
pagination.total = (res.data as any)?.total || (res as any).total || dataList.length || 0
|
|
|
|
|
console.log('总数:', pagination.total)
|
|
|
|
|
} else {
|
|
|
|
|
message.error(res.msg || '加载数据失败')
|
|
|
|
|
}
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error('加载数据失败:', error)
|
|
|
|
|
message.error(error?.message || '加载数据失败')
|
|
|
|
|
} finally {
|
2025-07-30 09:13:52 +08:00
|
|
|
|
loading.value = false
|
2025-07-31 17:32:21 +08:00
|
|
|
|
}
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 搜索
|
2025-08-01 15:14:24 +08:00
|
|
|
|
const handleSearch = (searchParams: EquipmentPageQuery) => {
|
2025-08-01 16:24:33 +08:00
|
|
|
|
console.log('🔍 主组件 - 接收到的搜索参数:', searchParams)
|
|
|
|
|
console.log('🔍 主组件 - 搜索参数类型:', typeof searchParams)
|
|
|
|
|
console.log('🔍 主组件 - 搜索参数是否为对象:', searchParams && typeof searchParams === 'object')
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
pagination.current = 1
|
2025-08-01 16:24:33 +08:00
|
|
|
|
currentSearchParams.value = { ...searchParams }
|
|
|
|
|
|
|
|
|
|
console.log('🔍 主组件 - 保存的当前搜索参数:', currentSearchParams.value)
|
|
|
|
|
console.log('🔍 主组件 - 准备调用 loadData,传递参数:', searchParams)
|
|
|
|
|
|
2025-08-01 15:14:24 +08:00
|
|
|
|
loadData(searchParams)
|
2025-07-31 17:32:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 重置
|
|
|
|
|
const handleReset = () => {
|
2025-08-01 16:24:33 +08:00
|
|
|
|
console.log('🔄 主组件 - 重置操作')
|
2025-07-30 09:13:52 +08:00
|
|
|
|
pagination.current = 1
|
2025-08-01 16:24:33 +08:00
|
|
|
|
currentSearchParams.value = {}
|
|
|
|
|
console.log('🔄 主组件 - 清空后的当前搜索参数:', currentSearchParams.value)
|
2025-07-31 17:32:21 +08:00
|
|
|
|
loadData()
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 表格变化
|
|
|
|
|
const handleTableChange = (pag: any) => {
|
|
|
|
|
pagination.current = pag.current || 1
|
|
|
|
|
pagination.pageSize = pag.pageSize || 10
|
2025-08-01 16:24:33 +08:00
|
|
|
|
loadData(currentSearchParams.value)
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 新增
|
|
|
|
|
const handleAdd = () => {
|
|
|
|
|
modalMode.value = 'add'
|
|
|
|
|
currentEquipment.value = null
|
|
|
|
|
modalVisible.value = true
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 查看
|
|
|
|
|
const handleView = (record: EquipmentResp) => {
|
|
|
|
|
modalMode.value = 'view'
|
|
|
|
|
currentEquipment.value = { ...record }
|
|
|
|
|
modalVisible.value = true
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 编辑
|
|
|
|
|
const handleEdit = (record: EquipmentResp) => {
|
|
|
|
|
modalMode.value = 'edit'
|
|
|
|
|
currentEquipment.value = { ...record }
|
|
|
|
|
modalVisible.value = true
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 详情
|
|
|
|
|
const handleDetail = (record: EquipmentResp) => {
|
|
|
|
|
// 跳转到设备详情页面,并传递 equipmentId
|
|
|
|
|
router.push({ name: 'DeviceDetail', params: { id: record.equipmentId } })
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 分配
|
|
|
|
|
const handleAssign = async (record: EquipmentResp) => {
|
|
|
|
|
Modal.confirm({
|
|
|
|
|
title: '确认分配',
|
|
|
|
|
content: `确定要分配设备"${record.equipmentName}"吗?`,
|
|
|
|
|
onOk: async () => {
|
|
|
|
|
try {
|
|
|
|
|
await assignEquipment(record.equipmentId, 'current-user-id')
|
|
|
|
|
message.success('分配成功')
|
|
|
|
|
loadData()
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error('分配失败:', error)
|
|
|
|
|
message.error(error?.message || '分配失败')
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 归还
|
|
|
|
|
const handleReturn = async (record: EquipmentResp) => {
|
|
|
|
|
Modal.confirm({
|
|
|
|
|
title: '确认归还',
|
|
|
|
|
content: `确定要归还设备"${record.equipmentName}"吗?`,
|
|
|
|
|
onOk: async () => {
|
|
|
|
|
try {
|
|
|
|
|
await returnEquipment(record.equipmentId)
|
|
|
|
|
message.success('归还成功')
|
|
|
|
|
loadData()
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error('归还失败:', error)
|
|
|
|
|
message.error(error?.message || '归还失败')
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 删除
|
|
|
|
|
const handleDelete = async (record: EquipmentResp) => {
|
2025-08-01 15:14:24 +08:00
|
|
|
|
// 检查设备状态,提供更详细的确认信息
|
|
|
|
|
let confirmContent = `确定要删除设备"${record.equipmentName}"吗?`
|
|
|
|
|
let canDelete = true
|
|
|
|
|
let statusWarning = ''
|
|
|
|
|
|
|
|
|
|
// 检查设备使用状态
|
|
|
|
|
if (record.useStatus === '1') {
|
|
|
|
|
canDelete = false
|
|
|
|
|
statusWarning = '该设备正在使用中,无法删除。请先归还设备后再进行删除操作。'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查设备位置状态
|
|
|
|
|
if (record.locationStatus === 'allocated' || record.locationStatus === 'borrowed') {
|
|
|
|
|
canDelete = false
|
|
|
|
|
statusWarning = '该设备已分配或外借中,无法删除。请先归还设备后再进行删除操作。'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查设备是否在维修中
|
|
|
|
|
if (record.locationStatus === 'repair' || record.equipmentStatus === 'repair') {
|
|
|
|
|
canDelete = false
|
|
|
|
|
statusWarning = '该设备正在维修中,无法删除。请等待维修完成后再进行删除操作。'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果设备状态不允许删除,显示警告信息
|
|
|
|
|
if (!canDelete) {
|
|
|
|
|
Modal.warning({
|
|
|
|
|
title: '无法删除设备',
|
|
|
|
|
content: statusWarning,
|
|
|
|
|
okText: '确定',
|
|
|
|
|
hideCancel: true,
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构建详细的确认信息
|
|
|
|
|
const deviceInfo = [
|
|
|
|
|
`设备名称:${record.equipmentName || '无'}`,
|
|
|
|
|
`资产编号:${record.assetCode || '无'}`,
|
|
|
|
|
`设备型号:${record.equipmentModel || '无'}`,
|
|
|
|
|
`序列号:${record.equipmentSn || '无'}`,
|
|
|
|
|
`当前状态:${getEquipmentStatusText(record.equipmentStatus || '')}`,
|
|
|
|
|
`位置状态:${getLocationStatusText(record.locationStatus || '')}`,
|
|
|
|
|
].join('\n')
|
|
|
|
|
|
|
|
|
|
confirmContent = `确定要删除以下设备吗?\n\n${deviceInfo}\n\n⚠️ 删除后设备将被标记为已报废,此操作不可恢复!\n\n删除原因:\n• 设备信息本身不可更改,但可以通过删除操作标记为报废\n• 删除后设备将不再出现在正常列表中\n• 历史记录将被保留,不影响其他模块功能`
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
Modal.confirm({
|
2025-08-01 15:14:24 +08:00
|
|
|
|
title: '确认删除设备',
|
|
|
|
|
content: confirmContent,
|
|
|
|
|
okText: '确认删除',
|
|
|
|
|
cancelText: '取消',
|
|
|
|
|
okButtonProps: { status: 'danger' },
|
2025-07-31 17:32:21 +08:00
|
|
|
|
onOk: async () => {
|
|
|
|
|
try {
|
|
|
|
|
await deleteEquipment(record.equipmentId)
|
2025-08-01 15:14:24 +08:00
|
|
|
|
message.success('设备删除成功')
|
2025-07-31 17:32:21 +08:00
|
|
|
|
loadData()
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error('删除失败:', error)
|
2025-08-01 15:14:24 +08:00
|
|
|
|
// 根据后端返回的错误信息显示具体的错误提示
|
|
|
|
|
const errorMessage = error?.response?.data?.msg || error?.message || '删除失败'
|
|
|
|
|
message.error(errorMessage)
|
2025-07-31 17:32:21 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
// 弹窗成功回调
|
|
|
|
|
const handleModalSuccess = () => {
|
|
|
|
|
modalVisible.value = false
|
|
|
|
|
loadData()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 监听表格数据变化
|
|
|
|
|
watch(tableData, (_newData) => {
|
|
|
|
|
// 数据变化监听
|
|
|
|
|
}, { deep: true })
|
|
|
|
|
|
|
|
|
|
// 初始化
|
2025-07-30 09:13:52 +08:00
|
|
|
|
onMounted(() => {
|
2025-07-31 17:32:21 +08:00
|
|
|
|
loadData()
|
2025-07-30 09:13:52 +08:00
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.equipment-center-container {
|
|
|
|
|
padding: 16px;
|
|
|
|
|
background: #f5f5f5;
|
|
|
|
|
min-height: 100vh;
|
2025-07-30 09:13:52 +08:00
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
.search-card {
|
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
}
|
2025-07-30 09:13:52 +08:00
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
.table-card {
|
|
|
|
|
.card-title {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-30 09:13:52 +08:00
|
|
|
|
|
2025-07-31 17:32:21 +08:00
|
|
|
|
.status-dot {
|
|
|
|
|
width: 8px;
|
|
|
|
|
height: 8px;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
display: inline-block;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.normal-dot {
|
|
|
|
|
background-color: #52c41a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.maintenance-dot {
|
|
|
|
|
background-color: #faad14;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.scrapped-dot {
|
|
|
|
|
background-color: #ff4d4f;
|
|
|
|
|
}
|
2025-07-30 09:13:52 +08:00
|
|
|
|
}
|
2025-07-31 17:32:21 +08:00
|
|
|
|
</style>
|