提交 f1457a26 authored 作者: caodi\cd's avatar caodi\cd

校验修改:未完善

上级 60af222c
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
> >
</view> </view>
</view> </view>
<view class="action-btn complete-btn" @click="submit(1)">
完成巡检
</view>
</view> </view>
</view> </view>
<!-- 模块3:Tab 操作区域 --> <!-- 模块3:Tab 操作区域 -->
...@@ -77,18 +80,25 @@ ...@@ -77,18 +80,25 @@
</view> </view>
</view> </view>
</view> </view>
<template v-if="inspectionResult === 1">
<view class="form-item"> <view class="form-item">
<text class="form-label" <text class="form-label"
><text class="required">*</text>情况摘要</text ><text class="required">*</text>情况摘要</text
> >
<text v-if="list[activeTab].conclusion" class="conclusion have" @click="showPopup(index)">{{ <text
list[activeTab].conclusion v-if="list[activeTab].conclusion"
}}</text> class="conclusion have"
<text v-else class="conclusion" @click="showPopup(index)">请输入情况摘要</text> @click="showPopup(index)"
>{{ list[activeTab].conclusion }}</text
>
<text v-else class="conclusion" @click="showPopup(index)"
>请输入情况摘要</text
>
</view> </view>
<view class="form-item"> <view class="form-item">
<text class="form-label">现场照片</text> <text class="form-label"
><text class="required">*</text>现场照片</text
>
<view class="photo-box"> <view class="photo-box">
<view class="photo-container"> <view class="photo-container">
<view <view
...@@ -98,7 +108,9 @@ ...@@ -98,7 +108,9 @@
class="photo-item" class="photo-item"
> >
<image :src="photo" class="photo"></image> <image :src="photo" class="photo"></image>
<text class="delete-photo" @click="deletePhoto(index)">×</text> <text class="delete-photo" @click="deletePhoto(index)"
>×</text
>
</view> </view>
<view @click="takePhoto" class="photo-btn"> + </view> <view @click="takePhoto" class="photo-btn"> + </view>
</view> </view>
...@@ -106,7 +118,8 @@ ...@@ -106,7 +118,8 @@
>请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view >请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view
> >
</view> </view>
</view> </view></template
>
</view> </view>
</view> </view>
...@@ -120,13 +133,10 @@ ...@@ -120,13 +133,10 @@
<view class="submit-module"> <view class="submit-module">
<view class="action-btn" @click="submit(0)">暂存</view> <view class="action-btn" @click="submit(0)">暂存</view>
<view <view
v-if="isSubmitEnabled" v-if="activeTab !== 2"
class="action-btn complete-btn" class="action-btn complete-btn"
@click="submit(1)" @click="nextTab"
> >
完成巡检
</view>
<view v-else class="action-btn complete-btn" @click="nextTab">
下一项 下一项
</view> </view </view> </view
><custom-popup ><custom-popup
...@@ -187,7 +197,7 @@ export default { ...@@ -187,7 +197,7 @@ export default {
}, },
], ],
activeTab: 0, // 当前选中的 Tab activeTab: 0, // 当前选中的 Tab
inspectionResult: 0, // Switch 值(0: 正常, 1: 异常) inspectionResult: "", // Switch 值(0: 正常, 1: 异常)
conclusion: "", // 情况摘要 conclusion: "", // 情况摘要
photos: [], // 现场照片 photos: [], // 现场照片
historyData: null, // 历史数据 historyData: null, // 历史数据
...@@ -304,7 +314,7 @@ export default { ...@@ -304,7 +314,7 @@ export default {
dictValue: item.dictValue, dictValue: item.dictValue,
conclusion: "", // 情况摘要 conclusion: "", // 情况摘要
// roomType, // roomType,
inspectionResult: 0, // 异常结论 inspectionResult: "", // 异常结论
itemCode: item.dictValue, // 检查项 如:门禁 itemCode: item.dictValue, // 检查项 如:门禁
measuredData: this.floor, // 逗号分隔字符串 measuredData: this.floor, // 逗号分隔字符串
photos: [], // 照片 photos: [], // 照片
...@@ -497,7 +507,7 @@ export default { ...@@ -497,7 +507,7 @@ export default {
// 提交 // 提交
submit(isSubmit = 1) { submit(isSubmit = 1) {
// 校验是否通过 // 校验是否通过
if (isSubmit && !this.isAllTabValid()) { if (isSubmit && !this.isAllTabValid().valid) {
uni.showToast({ uni.showToast({
title: "请填写完整必填项", title: "请填写完整必填项",
icon: "none", icon: "none",
...@@ -510,7 +520,9 @@ export default { ...@@ -510,7 +520,9 @@ export default {
console.log("this.uid", this.uid); console.log("this.uid", this.uid);
console.log("all_data", this.all_data); console.log("all_data", this.all_data);
if (this.uid) { if (this.uid) {
const index = this.all_data.findIndex((element) => element.uid == this.uid); const index = this.all_data.findIndex(
(element) => element.uid == this.uid
);
params.uid = this.uid; params.uid = this.uid;
this.all_data[index] = params; this.all_data[index] = params;
...@@ -560,39 +572,60 @@ export default { ...@@ -560,39 +572,60 @@ export default {
}, },
// 检查所有Tab 的必填项是否填写完整 // 检查所有Tab 的必填项是否填写完整
isAllTabValid() { isAllTabValid() {
const data = this.list; // 遍历所有巡检项
// 校验函数 for (let i = 0; i < this.list.length; i++) {
const validateData = (data) => { const item = this.list[i];
return data.every(
(item) => // 1. 检查是否填写了巡检结论
item.inspectionResult !== null && item.conclusion.trim() !== "" if (
); item.inspectionResult === null ||
item.inspectionResult === undefined
) {
return {
valid: false,
message: `请填写【${this.tabs[i].label}】的巡检结论`,
tabIndex: i,
};
}
// 2. 检查是否填写了情况摘要
if (!item.conclusion || item.conclusion.trim() === "") {
return {
valid: false,
message: `请填写【${this.tabs[i].label}】的情况摘要`,
tabIndex: i,
};
}
// 3. 如果是异常情况,检查是否上传了照片
if (
item.inspectionResult === 1 &&
(!item.photos || item.photos.length === 0)
) {
return {
valid: false,
message: `【${this.tabs[i].label}】为异常情况,必须上传现场照片`,
tabIndex: i,
};
}
}
// 所有检查都通过
return {
valid: true,
message: "",
}; };
// 调用校验函数
const isValid = validateData(data);
console.log(141, isValid);
return isValid;
}, },
// 检查当前 Tab 的必填项是否填写完整 // 检查当前 Tab 的必填项是否填写完整
isCurrentTabValid() {
const currentTabData = this.list[this.activeTab];
console.log("currentTabData", currentTabData);
return (
currentTabData.inspectionResult !== null && // 巡检结论必填
currentTabData.conclusion.trim() !== "" // 情况摘要必填
// 现场照片为非必填项,不做校验
);
},
// 下一项 // 下一项
nextTab() { nextTab() {
console.log(5215415, this.isCurrentTabValid()); // if (!this.isCurrentTabValid()) {
if (!this.isCurrentTabValid()) { // uni.showToast({
uni.showToast({ // title: "请填写完整必填项",
title: "请填写完整必填项", // icon: "none",
icon: "none", // });
}); // return false;
return false; // }
}
this.tabs[this.activeTab].status = this.tabs[this.activeTab].status =
this.list[this.activeTab].inspectionResult === 0 ? "1" : "2"; // 更新当前 Tab 的数据 this.list[this.activeTab].inspectionResult === 0 ? "1" : "2"; // 更新当前 Tab 的数据
if (this.activeTab === 2) { if (this.activeTab === 2) {
...@@ -665,6 +698,7 @@ export default { ...@@ -665,6 +698,7 @@ export default {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
position: relative;
.profile-left { .profile-left {
display: flex; display: flex;
...@@ -720,6 +754,26 @@ export default { ...@@ -720,6 +754,26 @@ export default {
} }
} }
} }
.action-btn {
width: 145.6px;
height: 38.4px;
line-height: 38.4px;
background: #ffffff;
border: 0.8px solid rgba(224, 224, 224, 1);
box-shadow: 0px 8px 19.2px 0px rgba(185, 185, 185, 0.24);
border-radius: 21.6px 19.2px 19.2px 21.6px;
font-size: 16px;
color: #000000;
text-align: center;
font-weight: 400;
position: absolute;
right: 20px;
top: 15px;
&.complete-btn {
background-image: linear-gradient(180deg, #3773f6 0%, #2c57f6 99%);
color: #ffffff;
}
}
} }
} }
...@@ -972,7 +1026,6 @@ export default { ...@@ -972,7 +1026,6 @@ export default {
left: 50%; left: 50%;
transform: translateX(-50%); transform: translateX(-50%);
bottom: 25.6px; bottom: 25.6px;
.action-btn { .action-btn {
width: 145.6px; width: 145.6px;
height: 38.4px; height: 38.4px;
...@@ -985,7 +1038,6 @@ export default { ...@@ -985,7 +1038,6 @@ export default {
color: #000000; color: #000000;
text-align: center; text-align: center;
font-weight: 400; font-weight: 400;
&.complete-btn { &.complete-btn {
background-image: linear-gradient(180deg, #3773f6 0%, #2c57f6 99%); background-image: linear-gradient(180deg, #3773f6 0%, #2c57f6 99%);
color: #ffffff; color: #ffffff;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论