修复新增维保记录接口报错

This commit is contained in:
hr121 2025-08-08 16:10:18 +08:00
parent ebdd3c68f7
commit 637bf8024c

View File

@ -1,8 +1,13 @@
<template>
<view class="equipment-detail">
<!-- 顶部导航区 -->
<Topnav :topLevel="topLevel" title="设备详情" defaultBackColor="#333333"
defaultNavTextColor="#333333" showBack />
<Topnav
:topLevel="topLevel"
title="设备详情"
defaultBackColor="#333333"
defaultNavTextColor="#333333"
showBack
/>
<!-- 主要内容区域 -->
<view class="detail-container">
@ -34,22 +39,26 @@
<!-- 设备基本信息区 -->
<view class="equipment-info">
<view class="info-card">
<text class="device-id">{{equipmentDetail.name || '未知设备'}}</text>
<text class="device-model">{{equipmentDetail.model || '未知型号'}}</text>
<text class="device-id">{{
equipmentDetail.name || "未知设备"
}}</text>
<text class="device-model">{{
equipmentDetail.model || "未知型号"
}}</text>
</view>
</view>
<!-- 维保记录区 -->
<view class="maintenance-records">
<view class="section-title">
<text style="z-index:1;">维保记录</text>
<text style="z-index: 1">维保记录</text>
<view class="title-underline"></view>
</view>
<view class="record-list">
<view
class="record-item"
v-for="(record, index) in maintenanceRecords"
v-for="(record, index) in maintenanceRecords || []"
:key="index"
>
<view class="record-image">
@ -102,7 +111,7 @@
custom-style="font-size:32rpx;"
placeholder="请选择维保类型"
type="select"
v-model="maintenanceType"
v-model="recordForm.type"
@click="handleClickType()"
:clearable="false"
/>
@ -118,9 +127,9 @@
:maxlength="100"
/>
<view class="word-count">
{{ recordForm.description ? recordForm.description.length : 0 }}
<view class="word-count-max">/100</view>
</view>
{{ recordForm.description ? recordForm.description.length : 0 }}
<view class="word-count-max">/100</view>
</view>
</view>
</view>
</view>
@ -157,16 +166,18 @@ export default {
//
CustomBar: this.CustomBar || 0,
// #endif
deviceId: '',
equipmentImages: [{
image: "/static/drone.png",
title: "默认图片"
}],
deviceId: "",
equipmentImages: [
{
image: "/static/drone.png",
title: "默认图片",
},
],
currentImageIndex: 0,
//
topLevel: 0,
//
scrollTop: 0,
//
topLevel: 0,
//
scrollTop: 0,
//
equipmentDetail: {},
maintenanceRecords: [],
@ -181,9 +192,8 @@ export default {
showTypePicker: false,
maintenanceType: "",
maintenanceTypes: [
{ label: "三方险", value: 1 },
{ label: "设备险", value: 2 },
{ label: "运营险", value: 3 },
{ label: "例行检查", value: 0 },
{ label: "电池损坏", value: 1 },
],
recordForm: {
type: "",
@ -192,8 +202,8 @@ export default {
};
},
onLoad(e) {
this.deviceId = e.id;
},
this.deviceId = e.id;
},
mounted() {
// ID
this.loadDeviceDetail();
@ -204,27 +214,29 @@ export default {
async loadDeviceDetail() {
try {
const detail = await this.$api.getDevicesDetail(this.deviceId);
console.log('设备详情:', detail);
console.log("设备详情:", detail);
if (detail) {
this.equipmentDetail = detail;
//
if (detail.deviceImages && detail.deviceImages.length > 0) {
this.equipmentImages = detail.deviceImages.map(img => ({
this.equipmentImages = detail.deviceImages.map((img) => ({
image: img.fileFullPath,
title: img.sourceFileName
title: img.sourceFileName,
}));
} else {
this.equipmentImages = [{
image: "/static/drone.png",
title: "默认图片"
}];
this.equipmentImages = [
{
image: "/static/drone.png",
title: "默认图片",
},
];
}
}
} catch (err) {
console.error('获取设备详情失败:', err);
console.error("获取设备详情失败:", err);
uni.showToast({
title: '获取设备详情失败',
icon: 'none'
title: "获取设备详情失败",
icon: "none",
});
}
},
@ -233,21 +245,23 @@ export default {
async loadMaintenanceRecords() {
try {
const res = await this.$api.getMaintenanceRecords({
aircraftId: this.deviceId
aircraftId: this.deviceId,
});
if (res && res.records) {
this.maintenanceRecords = res.records.map(record => ({
if (res && res.records && res.records.length > 0) {
this.maintenanceRecords = res.records.map((record) => ({
type: this.getMaintenanceTypeName(record.maintenanceType),
operator: record.createBy || '未知',
time: record.createTime || '未知时间',
description: record.remark || '无'
operator: record.createBy || "未知",
time: record.createTime || "未知时间",
description: record.remark || "无",
}));
} else {
this.maintenanceRecords = [];
}
} catch (err) {
console.error('获取维保记录失败:', err);
console.error("获取维保记录失败:", err);
uni.showToast({
title: '获取维保记录失败',
icon: 'none'
title: "获取维保记录失败",
icon: "none",
});
}
},
@ -255,18 +269,18 @@ export default {
//
getMaintenanceTypeName(type) {
const typeMap = {
0: '例行检查',
1: '电池损坏',
0: "例行检查",
1: "电池损坏",
};
return typeMap[type] || '未知类型';
return typeMap[type] || "未知类型";
},
onPageScroll(e) {
const level = e.scrollTop/60;
if(level<=1) this.topLevel = level;
else this.topLevel = 1;
this.scrollTop = e.scrollTop;
},
onPageScroll(e) {
const level = e.scrollTop / 60;
if (level <= 1) this.topLevel = level;
else this.topLevel = 1;
this.scrollTop = e.scrollTop;
},
//
showAddRecordModal() {
this.showRecordPopup = true;
@ -301,7 +315,9 @@ export default {
}
//
const selectedType = this.maintenanceTypes.find(t => t.label === this.recordForm.type);
const selectedType = this.maintenanceTypes.find(
(t) => t.label === this.recordForm.type
);
if (!selectedType) {
uni.showToast({
title: "请选择正确的维保类型",
@ -325,12 +341,13 @@ export default {
aircraftId: this.deviceId,
employeesId: employeesId,
maintenanceType: selectedType.value,
remark: this.recordForm.description
remark: this.recordForm.description,
createTime: new Date().toISOString(),
});
uni.showToast({
title: '添加成功',
icon: 'success'
title: "添加成功",
icon: "success",
});
//
@ -344,22 +361,23 @@ export default {
};
this.maintenanceType = "";
} catch (err) {
console.error('添加维保记录失败:', err);
console.error("添加维保记录失败:", err);
uni.showToast({
title: '添加失败',
icon: 'none'
title: "添加失败",
icon: "none",
});
}
},
//
handleTypeSelect(e) {
if (e && e.indexs && e.indexs.length > 0) {
const selected = this.maintenanceTypes[e.indexs[0]];
if (e && typeof e[0] === "number") {
const selected = this.maintenanceTypes[e[0]];
if (selected) {
this.recordForm.type = selected.label;
this.maintenanceType = selected.label;
}
console.log("选中的维保类型:", this.recordForm.type);
}
},
},
@ -371,34 +389,34 @@ export default {
display: flex;
flex-direction: column;
// min-height: 100vh;
background-color: #F5F5F5;
background-color: #f5f5f5;
.detail-container {
flex: 1;
min-height: 100vh;
min-height: 100vh;
}
//
.equipment-images {
width: 100%;
overflow: hidden;
padding-top:144rpx;
background-color: #ebebf0;
padding-top: 180rpx;
background-color: #ebebf0;
// margin-bottom: 20rpx;
}
::v-deep .u-indicator-item-dot {
width: 20rpx;
height: 20rpx;
border-radius: 50%;
opacity: 0.5;
margin: 0 8rpx;
margin-bottom: 25rpx;
background-color: #999999 !important; /* 默认颜色 */
}
::v-deep .u-indicator-item-dot-active {
opacity: 1;
background-color: #fee547 !important; /* 选中颜色 */
}
width: 20rpx;
height: 20rpx;
border-radius: 50%;
opacity: 0.5;
margin: 0 8rpx;
margin-bottom: 25rpx;
background-color: #999999 !important; /* 默认颜色 */
}
::v-deep .u-indicator-item-dot-active {
opacity: 1;
background-color: #fee547 !important; /* 选中颜色 */
}
.indicator {
display: flex;
flex-direction: row;
@ -439,10 +457,10 @@ export default {
// box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
.device-id {
font-family: Source Han Sans SC;
font-weight: bold;
font-size: 36rpx;
color: #333333;
font-family: Source Han Sans SC;
font-weight: bold;
font-size: 36rpx;
color: #333333;
}
.device-model {
@ -459,8 +477,8 @@ export default {
background-color: #ffffff;
border-radius: 16rpx;
padding: 30rpx 20rpx;
margin: 24rpx;
margin-top: 0;
margin: 24rpx;
margin-top: 0;
.section-title {
font-size: 36rpx;
@ -487,21 +505,22 @@ export default {
flex-direction: column;
gap: 26rpx;
.record-item:first-child {
box-shadow: 0rpx -6rpx 10rpx 0rpx rgba(226,226,226,0.3), 0rpx 6rpx 8rpx 0rpx rgba(218,218,218,0.3);
}
.record-item:first-child {
box-shadow: 0rpx -6rpx 10rpx 0rpx rgba(226, 226, 226, 0.3),
0rpx 6rpx 8rpx 0rpx rgba(218, 218, 218, 0.3);
}
.record-item {
display: flex;
gap: 20rpx;
padding: 30rpx 20rpx 37rpx 20rpx;
border-radius: 8rpx;
box-shadow: 0rpx 6rpx 10rpx 0rpx rgba(200,199,193,0.3);
box-shadow: 0rpx 6rpx 10rpx 0rpx rgba(200, 199, 193, 0.3);
.record-image {
width: 123rpx;
height: 123rpx;
border-radius: 12rpx;
border: 3rpx solid #FEE547;
width: 123rpx;
height: 123rpx;
border-radius: 12rpx;
border: 3rpx solid #fee547;
.thumbnail {
width: 100%;
height: 100%;
@ -513,12 +532,12 @@ export default {
display: flex;
flex-direction: column;
justify-content: space-between;
gap: 8rpx;
gap: 8rpx;
.info-top {
display: flex;
flex-direction: column;
gap: 8rpx;
display: flex;
flex-direction: column;
gap: 8rpx;
.record-type {
font-family: Source Han Sans SC;
@ -539,10 +558,10 @@ export default {
display: flex;
flex-direction: column;
gap: 8rpx;
font-family: Source Han Sans SC;
font-weight: 400;
font-size: 28rpx;
color: #666666;
font-family: Source Han Sans SC;
font-weight: 400;
font-size: 28rpx;
color: #666666;
}
}
}
@ -637,20 +656,28 @@ export default {
}
.textarea-container {
position: relative;
height: 420rpx;
height: 420rpx;
.u-input {
height: 100%;
font-size: 32rpx;
color: #333333;
padding: 20rpx 30rpx;
border-radius: 12rpx;
background-color: #f5f5f5;
}
.word-count {
position: absolute;
right: 20rpx;
bottom: 103rpx;
font-family: Arial;
font-weight: 400;
font-size: 32rpx;
color: #B3B3B3;
font-family: Arial;
font-weight: 400;
font-size: 32rpx;
color: #b3b3b3;
.word-count-max {
color: #333333;
display: inline-block;
}
.word-count-max {
color: #333333;
display: inline-block;
}
}
}