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

校验修改:未完善

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