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

fix:组件处理<template>

<!-- 机房巡检操作 --> <view> <view v-for="(item, index) in itemData.detail" :key="index"> <view class="form-item"> <text class="form-label" ><text class="required">*</text>{{ item.settingLabel }}</text ><text>{{ item.setting }}</text> </view> <view class="form-item"> <text class="form-label" ><text class="required">*</text>{{ item.label }}</text > <view class="switch-container"> <view :class="['status-btn', { active: item.inspectionResult === 0 }]" @click="setInspectionResult(index, 0, item.lableArr[0])" > {{ item.lableArr[0] }} </view> <view :class="['status-btn', { active: item.inspectionResult === 1 }]" @click="setInspectionResult(index, 1, item.lableArr[1])" > {{ item.lableArr[1] }} </view> </view ><input v-if="'value' in item" class="input" v-model="item.value" type="text" placeholder="请输入" maxlength="3" />{{ item.unit }} </view> <view v-if="'conclusion' in item" class="form-item"> <text class="form-label"><text class="required">*</text>情况摘要</text> <text class="conclusion" @click="showPopup(index)">{{ item.conclusion || "请输入情况摘要" }}</text> </view> <view class="form-item" v-if="'photos' in item"> <text class="form-label"><text class="required">*</text>现场照片</text> <view class="photo-box"> <view class="photo-container"> <view @click="takePhoto(index)" class="photo-btn"> + </view> <view v-for="(photo, itemIndex) in item && item.photos" :key="itemIndex" class="photo-item" > <image :src="photo" class="photo"></image> <text class="delete-photo" @click="deletePhoto(index, itemIndex)" >×</text > </view> </view> <view class="photo-limit" >请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view > </view> </view> </view ><custom-popup ref="customPopup" :inspectionItem="inspectionItem" @confirm="handlePopupConfirm" ></custom-popup> </view> </template> <script> import customPopup from "./customPopup.vue"; import _ from "lodash"; export default { components: { customPopup, }, props: { // 父组件传递的巡检状态 status: { type: Number, default: 0, }, // 父组件传递的巡检类型 jfType: { type: Number, default: 0, }, // 父组件传递的巡检事项名 inspectionItem: { type: String, default: "", }, // 父组件传递的数据 defaultData: { type: Object, default: {}, }, }, data() { return { currentIndex: 0, // 当前操作的索引 photos: [], itemData: { isValid: false, // false是校验未通过 true是校验通过 // status: 0, 0是未巡检 1是已巡检 2巡检异常 statusLabel: "未巡检", inspectionItem: "", //巡检事项 detail: [ { label: "实际电池电压", inspectionResult: 0, inspectionResultLable: "正常", lableArr: ["正常", "正常"], conclusion: "", settingLabel: "设定电池电压", setting: "10V-15V", //设定温度值 value: "", //输入温度 unit: "V", //单位 photos: [], }, { label: "实际电池温度", inspectionResult: 0, inspectionResultLable: "正常", lableArr: ["正常", "正常"], conclusion: "", settingLabel: "设定电池温度", setting: "15℃-30℃", //设定湿度值 value: "", //输入湿度 unit: "℃", //单位 photos: [], }, { label: "实际电池内阻", inspectionResult: 0, inspectionResultLable: "正常", lableArr: ["正常", "正常"], conclusion: "", settingLabel: "设定电池内阻", setting: "<10mΩ", //设定湿度值 value: "", //输入湿度 unit: "mΩ", //单位 photos: [], }, ], }, itemDataOther: { isValid: false, // false是校验未通过 true是校验通过 // status: 0, 0是未巡检 1是已巡检 2巡检异常 statusLabel: "未巡检", inspectionItem: "", //巡检事项 detail: [ { label: "实际电池电压", inspectionResult: 0, inspectionResultLable: "正常", lableArr: ["正常", "正常"], conclusion: "", settingLabel: "设定电池电压", setting: "2V-3V", //设定温度值 value: "", //输入温度 unit: "V", //单位 photos: [], }, { label: "实际电池温度", inspectionResult: 0, inspectionResultLable: "正常", lableArr: ["正常", "正常"], conclusion: "", settingLabel: "设定电池温度", setting: "15℃-30℃", //设定湿度值 value: "", //输入湿度 unit: "℃", //单位 photos: [], }, { label: "实际电池内阻", inspectionResult: 0, inspectionResultLable: "正常", lableArr: ["正常", "正常"], conclusion: "", settingLabel: "设定电池内阻", setting: "<0.5mΩ", //设定湿度值 value: "", //输入湿度 unit: "mΩ", //单位 photos: [], }, ], }, }; }, computed: { userInfo() { return this.$store.state.now_user || {}; }, }, mounted() { console.log(console.log(45454854,this.jfType)) if (this.jfType === "2") { this.itemData = this.itemDataOther; } console.log("itemData",this.itemData) if (Object.keys(this.defaultData).length !== 0) { this.itemData = this.defaultData; } }, methods: { // 拍照 takePhoto(index) { uni.chooseImage({ count: 1, sourceType: ["camera"], // 可以从相机拍摄 success: async (res) => { if (this.photos.length < 5) { const base64 = await this.convertFileToBase64(res.tempFilePaths[0]); this.itemData.detail[index].photos.push(base64); } else { uni.showToast({ title: "最多只能上传5张照片", icon: "none", }); } }, }); }, // 转化为base64 convertFileToBase64(filePath) { return new Promise((resolve, reject) => { plus.io.resolveLocalFileSystemURL( filePath, function (entry) { entry.file( function (file) { const reader = new plus.io.FileReader(); reader.onloadend = function (evt) { const base64 = evt.target.result; // 获取 Base64 数据 resolve(base64); // 返回 Base64 数据 }; reader.readAsDataURL(file); // 读取文件并转换为 Base64 }, function (error) { reject("获取文件对象失败:" + error.message); } ); }, function (error) { reject("解析文件路径失败:" + error.message); } ); }); }, // 删除照片 deletePhoto(index, itemIndex) { this.itemData.detail[index].photos.splice(itemIndex, 1); }, // 设置巡检结论 setInspectionResult(index, value, label) { this.itemData.detail[index].inspectionResult = value; // 0正常 1异常 this.itemData.detail[index].inspectionResultLable = label; }, // 显示弹窗 showPopup(index) { this.currentIndex = index; this.$refs.customPopup.open(); }, // 处理弹窗确认 handlePopupConfirm(summary) { this.itemData.detail[this.currentIndex].conclusion = summary; // 回显到文字显示区域 }, // 处理】数据 getFromData() { console.log(111, this.itemData); const isValid = this.areAllObjectsValid(this.itemData.detail, 2); //false不通过 true通过 // const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail); this.itemData.isValid = isValid; this.itemData.inspectionItem = this.inspectionItem; console.log(222, this.itemData); // if (isAllOne) { // // 全都是正常 // this.itemData.status = 1; //1表示已经巡检过没有异常 // this.itemData.statusLabel = "已巡检"; // } else { // this.itemData.status = 2; //1表示已经巡检过有异常 // this.itemData.statusLabel = "巡检异常"; // } // console.log(this.itemData); return this.itemData; }, // 数据校验方法 true说明有未填项 areAllObjectsValid(arr, skipIndex) { // 遍历数组中的每个对象 for (let i = 0; i < arr.length; i++) { const obj = arr[i]; // 如果当前索引大于等于 skipIndex,并且 inspectionResult 为 1,则跳过后续校验 if (i >= skipIndex && obj.inspectionResult === 1) { break; } // 检查对象中的每个属性是否有值 for (const key in obj) { if (obj.hasOwnProperty(key)) { // 如果属性值为空(null, undefined, 空字符串等),则校验不通过 if ( obj[key] === null || obj[key] === undefined || obj[key] === "" ) { return false; } } } } // 如果所有对象都通过校验,返回 true return true; }, // 校验是否有异常 areAllInspectionResultsOne(arr) { return arr.every((obj) => obj.inspectionResult === 0); }, }, }; </script> <style scoped lang="less"> .form-item { display: flex; align-items: center; padding: 9.6px 0; line-height: 28.8px; border-bottom: 0.8px solid #f2f3f5; .form-label { font-size: 11.2px; margin-right: 25.6px; width: 88px; text-align: right; color: #7c7c7c; .required { color: red; margin-right: 3.2px; } } .input { width: 50px; margin-left: 12px; } .fg { margin: 0 12px; } .conclusion { color: #c7c7c7; font-size: 11.2px; .have { color: #000; } } .label { font-size: 11.2px; } .switch-container { display: flex; gap: 9.6px; .status-btn { flex: 1; padding: 5.6px 19.2px; font-size: 12.8px; color: #000000; background: #f2f2f2; text-align: center; font-weight: 400; line-height: 17.6px; border-radius: 14.4px; &.active { color: #ffffff; background: #3774f6; border: 0.32px solid rgba(224, 224, 224, 1); } } } .input-box { flex: 1; border-radius: 3.2px; font-size: 12.8px; line-height: 19.2px; } .photo-limit { font-size: 12.8px; color: #959595; line-height: 19.2px; font-weight: 400; } .photo-container { display: flex; flex-wrap: wrap; margin-bottom: 6.4px; .photo-item { position: relative; margin-right: 6.4px; margin-bottom: 6.4px; .photo { width: 57.6px; height: 57.6px; border-radius: 3.2px; margin-left: 9.6px; } .delete-photo { position: absolute; top: -6.4px; right: -6.4px; background-color: #ff4d4f; color: #fff; width: 12.8px; height: 12.8px; border-radius: 50%; text-align: center; line-height: 12.8px; font-size: 9.6px; } } } .photo-btn { background: #ffffff; border: 0.272px solid rgba(221, 221, 221, 1); border-radius: 1.64px; width: 57.6px; height: 57.6px; font-size: 57.6px; color: #cccccc; text-align: center; line-height: 51.2px; } } </style>
上级 6a72f2ce
...@@ -2,63 +2,64 @@ ...@@ -2,63 +2,64 @@
<!-- 机房巡检操作 --> <!-- 机房巡检操作 -->
<view> <view>
<view v-for="(item, index) in itemData.detail" :key="index"> <view v-for="(item, index) in itemData.detail" :key="index">
<template <view class="form-item">
v-if="!(index > 2 && itemData.detail[2].inspectionResult === 1)" <text class="form-label"
> ><text class="required">*</text>{{ item.settingLabel }}</text
<view class="form-item"> ><text>{{ item.setting }}</text>
<text class="form-label" </view>
><text class="required">*</text>{{ item.label }}</text <view class="form-item">
<text class="form-label"
><text class="required">*</text>{{ item.label }}</text
>
<view class="switch-container">
<view
:class="['status-btn', { active: item.inspectionResult === 0 }]"
@click="setInspectionResult(index, 0, item.lableArr[0])"
> >
<view class="switch-container"> {{ item.lableArr[0] }}
<view </view>
:class="['status-btn', { active: item.inspectionResult === 0 }]" <view
@click="setInspectionResult(index, 0, item.lableArr[0])" :class="['status-btn', { active: item.inspectionResult === 1 }]"
> @click="setInspectionResult(index, 1, item.lableArr[1])"
{{ item.lableArr[0] }} >
</view> {{ item.lableArr[1] }}
</view> </view
><input
v-if="'value' in item"
class="input"
v-model="item.value"
type="text"
placeholder="请输入"
maxlength="3"
/>{{ item.unit }}
</view>
<view v-if="'conclusion' in item" class="form-item">
<text class="form-label"><text class="required">*</text>情况摘要</text>
<text class="conclusion" @click="showPopup(index)">{{
item.conclusion || "请输入情况摘要"
}}</text>
</view>
<view class="form-item" v-if="'photos' in item">
<text class="form-label"><text class="required">*</text>现场照片</text>
<view class="photo-box">
<view class="photo-container">
<view @click="takePhoto(index)" class="photo-btn"> + </view>
<view <view
:class="['status-btn', { active: item.inspectionResult === 1 }]" v-for="(photo, itemIndex) in item && item.photos"
@click="setInspectionResult(index, 1, item.lableArr[1])" :key="itemIndex"
class="photo-item"
> >
{{ item.lableArr[1] }} <image :src="photo" class="photo"></image>
<text class="delete-photo" @click="deletePhoto(index, itemIndex)"
>×</text
>
</view> </view>
</view> </view>
</view> <view class="photo-limit"
>请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view
<view v-if="'conclusion' in item" class="form-item">
<text class="form-label"
><text class="required">*</text>情况摘要</text
> >
<text class="conclusion" @click="showPopup(index)">{{
item.conclusion || "请输入情况摘要"
}}</text>
</view> </view>
<view class="form-item" v-if="'photos' in item"> </view> </view
<text class="form-label"
><text class="required">*</text>现场照片</text
>
<view class="photo-box">
<view class="photo-container">
<view @click="takePhoto(index)" class="photo-btn"> + </view>
<view
v-for="(photo, itemIndex) in item && item.photos"
:key="itemIndex"
class="photo-item"
>
<image :src="photo" class="photo"></image>
<text
class="delete-photo"
@click="deletePhoto(index, itemIndex)"
>×</text
>
</view>
</view>
<view class="photo-limit"
>请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view
>
</view>
</view></template
> </view
><custom-popup ><custom-popup
ref="customPopup" ref="customPopup"
:inspectionItem="inspectionItem" :inspectionItem="inspectionItem"
...@@ -81,6 +82,11 @@ export default { ...@@ -81,6 +82,11 @@ export default {
type: Number, type: Number,
default: 0, default: 0,
}, },
// 父组件传递的巡检类型
jfType: {
type: Number,
default: 0,
},
// 父组件传递的巡检事项名 // 父组件传递的巡检事项名
inspectionItem: { inspectionItem: {
type: String, type: String,
...@@ -102,53 +108,44 @@ export default { ...@@ -102,53 +108,44 @@ export default {
inspectionItem: "", //巡检事项 inspectionItem: "", //巡检事项
detail: [ detail: [
{ {
label: "门禁功能", label: "实际电池电压",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "正常", inspectionResultLable: "正常",
lableArr: ["正常", "常"], lableArr: ["正常", "常"],
conclusion: "", conclusion: "",
settingLabel: "设定电池电压",
setting: this.jfType === "3" ? "10V-15V" : "2V-3V", //设定温度值
value: "", //输入温度
unit: "V", //单位
photos: [], photos: [],
}, },
{ {
label: "门禁外观破损", label: "实际电池温度",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "无", inspectionResultLable: "正常",
lableArr: ["无", "有"], lableArr: ["正常", "正常"],
conclusion: "",
photos: [],
},
{
label: "是否有监控",
inspectionResult: 0,
inspectionResultLable: "有监控",
lableArr: ["有监控", "无监控"],
},
{
label: "监控外观破损",
inspectionResult: 0,
inspectionResultLable: "无",
lableArr: ["无", "有"],
conclusion: "",
photos: [],
},
{
label: "监控画面清晰",
inspectionResult: 0,
inspectionResultLable: "清晰",
lableArr: ["清晰", "模糊"],
conclusion: "", conclusion: "",
settingLabel: "设定电池温度",
setting: "15℃-30℃", //设定湿度值
value: "", //输入湿度
unit: "℃", //单位
photos: [], photos: [],
}, },
{ {
label: "监控存储连续", label: "实际电池内阻",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "正常", inspectionResultLable: "正常",
lableArr: ["正常", "常"], lableArr: ["正常", "常"],
conclusion: "", conclusion: "",
settingLabel: "设定电池内阻",
setting: this.jfType === "3" ? "<10mΩ" : "<0.5mΩ", //设定湿度值
value: "", //输入湿度
unit: "mΩ", //单位
photos: [], photos: [],
}, },
], ],
}, },
}; };
}, },
computed: { computed: {
...@@ -228,7 +225,7 @@ export default { ...@@ -228,7 +225,7 @@ export default {
// 处理】数据 // 处理】数据
getFromData() { getFromData() {
console.log(111, this.itemData); console.log(111, this.itemData);
const isValid = this.areAllObjectsValid(this.itemData.detail,2); //false不通过 true通过 const isValid = this.areAllObjectsValid(this.itemData.detail, 2); //false不通过 true通过
// const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail); // const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail);
this.itemData.isValid = isValid; this.itemData.isValid = isValid;
this.itemData.inspectionItem = this.inspectionItem; this.itemData.inspectionItem = this.inspectionItem;
...@@ -297,6 +294,13 @@ export default { ...@@ -297,6 +294,13 @@ export default {
margin-right: 3.2px; margin-right: 3.2px;
} }
} }
.input {
width: 50px;
margin-left: 12px;
}
.fg {
margin: 0 12px;
}
.conclusion { .conclusion {
color: #c7c7c7; color: #c7c7c7;
font-size: 11.2px; font-size: 11.2px;
......
...@@ -2,63 +2,53 @@ ...@@ -2,63 +2,53 @@
<!-- 机房巡检操作 --> <!-- 机房巡检操作 -->
<view> <view>
<view v-for="(item, index) in itemData.detail" :key="index"> <view v-for="(item, index) in itemData.detail" :key="index">
<template <view class="form-item">
v-if="!(index > 2 && itemData.detail[2].inspectionResult === 1)" <text class="form-label"
> ><text class="required">*</text>{{ item.label }}</text
<view class="form-item"> >
<text class="form-label" <view class="switch-container">
><text class="required">*</text>{{ item.label }}</text <view
:class="['status-btn', { active: item.inspectionResult === 0 }]"
@click="setInspectionResult(index, 0)"
> >
<view class="switch-container"> 正常
<view
:class="['status-btn', { active: item.inspectionResult === 0 }]"
@click="setInspectionResult(index, 0, item.lableArr[0])"
>
{{ item.lableArr[0] }}
</view>
<view
:class="['status-btn', { active: item.inspectionResult === 1 }]"
@click="setInspectionResult(index, 1, item.lableArr[1])"
>
{{ item.lableArr[1] }}
</view>
</view> </view>
</view> <view
:class="['status-btn', { active: item.inspectionResult === 1 }]"
<view v-if="'conclusion' in item" class="form-item"> @click="setInspectionResult(index, 1)"
<text class="form-label"
><text class="required">*</text>情况摘要</text
> >
<text class="conclusion" @click="showPopup(index)">{{ 异常
item.conclusion || "请输入情况摘要" </view>
}}</text>
</view> </view>
<view class="form-item" v-if="'photos' in item"> </view>
<text class="form-label"
><text class="required">*</text>现场照片</text <view class="form-item">
> <text class="form-label"><text class="required">*</text>情况摘要</text>
<view class="photo-box"> <text class="conclusion" @click="showPopup(index)">{{
<view class="photo-container"> item.conclusion || "请输入情况摘要"
<view @click="takePhoto(index)" class="photo-btn"> + </view> }}</text>
<view </view>
v-for="(photo, itemIndex) in item && item.photos" <view class="form-item">
:key="itemIndex" <text class="form-label"><text class="required">*</text>现场照片</text>
class="photo-item" <view class="photo-box">
<view class="photo-container">
<view @click="takePhoto(index)" class="photo-btn"> + </view>
<view
v-for="(photo, itemIndex) in item && item.photos"
:key="itemIndex"
class="photo-item"
>
<image :src="photo" class="photo"></image>
<text class="delete-photo" @click="deletePhoto(index, itemIndex)"
>×</text
> >
<image :src="photo" class="photo"></image>
<text
class="delete-photo"
@click="deletePhoto(index, itemIndex)"
>×</text
>
</view>
</view> </view>
<view class="photo-limit"
>请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view
>
</view> </view>
</view></template <view class="photo-limit"
> </view >请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view
>
</view>
</view> </view
><custom-popup ><custom-popup
ref="customPopup" ref="customPopup"
:inspectionItem="inspectionItem" :inspectionItem="inspectionItem"
...@@ -87,22 +77,15 @@ export default { ...@@ -87,22 +77,15 @@ export default {
default: "", default: "",
}, },
// 父组件传递的数据 // 父组件传递的数据
defaultData: { itemData: {
type: Object, type: Object,
default: {}, default: () => ({
},
},
data() {
return {
currentIndex: 0, // 当前操作的索引
photos: [],
itemData: {
isValid: false, // false是校验未通过 true是校验通过 isValid: false, // false是校验未通过 true是校验通过
// status: 0, 0是未巡检 1是已巡检 2巡检异常 statusLabel: "未巡检", // status: 0, 0是未巡检 1是已巡检 2巡检异常 statusLabel: "未巡检",
inspectionItem: "", //巡检事项 inspectionItem: "", //巡检事项
detail: [ detail: [
{ {
label: "门禁功能", label: "市电输入状态",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "正常", inspectionResultLable: "正常",
lableArr: ["正常", "异常"], lableArr: ["正常", "异常"],
...@@ -110,37 +93,15 @@ export default { ...@@ -110,37 +93,15 @@ export default {
photos: [], photos: [],
}, },
{ {
label: "门禁外观破损", label: "UPS状态",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "无", inspectionResultLable: "正常",
lableArr: ["无", "有"], lableArr: ["正常", "异常"],
conclusion: "",
photos: [],
},
{
label: "是否有监控",
inspectionResult: 0,
inspectionResultLable: "有监控",
lableArr: ["有监控", "无监控"],
},
{
label: "监控外观破损",
inspectionResult: 0,
inspectionResultLable: "无",
lableArr: ["无", "有"],
conclusion: "",
photos: [],
},
{
label: "监控画面清晰",
inspectionResult: 0,
inspectionResultLable: "清晰",
lableArr: ["清晰", "模糊"],
conclusion: "", conclusion: "",
photos: [], photos: [],
}, },
{ {
label: "监控存储连续", label: "电池状态",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "正常", inspectionResultLable: "正常",
lableArr: ["正常", "异常"], lableArr: ["正常", "异常"],
...@@ -148,7 +109,13 @@ export default { ...@@ -148,7 +109,13 @@ export default {
photos: [], photos: [],
}, },
], ],
}, }),
},
},
data() {
return {
currentIndex: 0, // 当前操作的索引
photos: [],
}; };
}, },
computed: { computed: {
...@@ -156,11 +123,7 @@ export default { ...@@ -156,11 +123,7 @@ export default {
return this.$store.state.now_user || {}; return this.$store.state.now_user || {};
}, },
}, },
mounted() { mounted() {},
if (Object.keys(this.defaultData).length !== 0) {
this.itemData = this.defaultData;
}
},
methods: { methods: {
// 拍照 // 拍照
takePhoto(index) { takePhoto(index) {
...@@ -212,9 +175,8 @@ export default { ...@@ -212,9 +175,8 @@ export default {
}, },
// 设置巡检结论 // 设置巡检结论
setInspectionResult(index, value, label) { setInspectionResult(index, value) {
this.itemData.detail[index].inspectionResult = value; // 0正常 1异常 this.itemData.detail[index].inspectionResult = value; // 0正常 1异常
this.itemData.detail[index].inspectionResultLable = label;
}, },
// 显示弹窗 // 显示弹窗
showPopup(index) { showPopup(index) {
...@@ -227,12 +189,10 @@ export default { ...@@ -227,12 +189,10 @@ export default {
}, },
// 处理】数据 // 处理】数据
getFromData() { getFromData() {
console.log(111, this.itemData); const isValid = this.areAllObjectsValid(this.itemData.detail); //false不通过 true通过
const isValid = this.areAllObjectsValid(this.itemData.detail,2); //false不通过 true通过 const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail);
// const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail);
this.itemData.isValid = isValid; this.itemData.isValid = isValid;
this.itemData.inspectionItem = this.inspectionItem; this.itemData.inspectionItem = this.inspectionItem;
console.log(222, this.itemData);
// if (isAllOne) { // if (isAllOne) {
// // 全都是正常 // // 全都是正常
// this.itemData.status = 1; //1表示已经巡检过没有异常 // this.itemData.status = 1; //1表示已经巡检过没有异常
...@@ -245,29 +205,34 @@ export default { ...@@ -245,29 +205,34 @@ export default {
return this.itemData; return this.itemData;
}, },
// 数据校验方法 true说明有未填项 // 数据校验方法 true说明有未填项
areAllObjectsValid(arr, skipIndex) { areAllObjectsValid(arr) {
// 遍历数组中的每个对象
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
const obj = arr[i]; const obj = arr[i];
// 如果当前索引大于等于 skipIndex,并且 inspectionResult 为 1,则跳过后续校验 const keys = Object.keys(obj);
if (i >= skipIndex && obj.inspectionResult === 1) { for (let j = 0; j < keys.length; j++) {
break; const key = keys[j];
} const value = obj[key];
// 检查对象中的每个属性是否有值 if (value === null || value === undefined || value === "") {
for (const key in obj) { return false;
if (obj.hasOwnProperty(key)) { }
// 如果属性值为空(null, undefined, 空字符串等),则校验不通过 if (Array.isArray(value)) {
if ( if (value.length === 0) {
obj[key] === null || return false;
obj[key] === undefined || }
obj[key] === "" for (let k = 0; k < value.length; k++) {
) { if (typeof value[k] === "object" && value[k] !== null) {
if (!validateArrayObjects([value[k]])) {
return false;
}
}
}
} else if (typeof value === "object" && value !== null) {
if (!validateArrayObjects([value])) {
return false; return false;
} }
} }
} }
} }
// 如果所有对象都通过校验,返回 true
return true; return true;
}, },
// 校验是否有异常 // 校验是否有异常
......
...@@ -2,63 +2,63 @@ ...@@ -2,63 +2,63 @@
<!-- 机房巡检操作 --> <!-- 机房巡检操作 -->
<view> <view>
<view v-for="(item, index) in itemData.detail" :key="index"> <view v-for="(item, index) in itemData.detail" :key="index">
<template <view class="form-item">
v-if="!(index > 2 && itemData.detail[2].inspectionResult === 1)" <text class="form-label"
> ><text class="required">*</text>{{ item.settingLabel }}</text
<view class="form-item"> ><text>{{ item.setting }}{{ item.unit }}</text>
<text class="form-label" </view>
><text class="required">*</text>{{ item.label }}</text <view class="form-item">
<text class="form-label"
><text class="required">*</text>{{ item.label }}</text
>
<view class="switch-container">
<view
:class="['status-btn', { active: item.inspectionResult === 0 }]"
@click="setInspectionResult(index, 0, item.lableArr[0])"
> >
<view class="switch-container"> {{ item.lableArr[0] }}
<view </view>
:class="['status-btn', { active: item.inspectionResult === 0 }]" <view
@click="setInspectionResult(index, 0, item.lableArr[0])" :class="['status-btn', { active: item.inspectionResult === 1 }]"
> @click="setInspectionResult(index, 1, item.lableArr[1])"
{{ item.lableArr[0] }} >
</view> {{ item.lableArr[1] }}
</view> </view
><input
class="input"
v-model="item.value"
type="text"
placeholder="请输入"
maxlength="3"
/>{{ item.unit }}
</view>
<view v-if="'conclusion' in item" class="form-item">
<text class="form-label"><text class="required">*</text>情况摘要</text>
<text class="conclusion" @click="showPopup(index)">{{
item.conclusion || "请输入情况摘要"
}}</text>
</view>
<view class="form-item" v-if="'photos' in item">
<text class="form-label"><text class="required">*</text>现场照片</text>
<view class="photo-box">
<view class="photo-container">
<view @click="takePhoto(index)" class="photo-btn"> + </view>
<view <view
:class="['status-btn', { active: item.inspectionResult === 1 }]" v-for="(photo, itemIndex) in item && item.photos"
@click="setInspectionResult(index, 1, item.lableArr[1])" :key="itemIndex"
class="photo-item"
> >
{{ item.lableArr[1] }} <image :src="photo" class="photo"></image>
<text class="delete-photo" @click="deletePhoto(index, itemIndex)"
>×</text
>
</view> </view>
</view> </view>
</view> <view class="photo-limit"
>请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view
<view v-if="'conclusion' in item" class="form-item">
<text class="form-label"
><text class="required">*</text>情况摘要</text
> >
<text class="conclusion" @click="showPopup(index)">{{
item.conclusion || "请输入情况摘要"
}}</text>
</view> </view>
<view class="form-item" v-if="'photos' in item"> </view></view
<text class="form-label"
><text class="required">*</text>现场照片</text
>
<view class="photo-box">
<view class="photo-container">
<view @click="takePhoto(index)" class="photo-btn"> + </view>
<view
v-for="(photo, itemIndex) in item && item.photos"
:key="itemIndex"
class="photo-item"
>
<image :src="photo" class="photo"></image>
<text
class="delete-photo"
@click="deletePhoto(index, itemIndex)"
>×</text
>
</view>
</view>
<view class="photo-limit"
>请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view
>
</view>
</view></template
> </view
><custom-popup ><custom-popup
ref="customPopup" ref="customPopup"
:inspectionItem="inspectionItem" :inspectionItem="inspectionItem"
...@@ -102,49 +102,27 @@ export default { ...@@ -102,49 +102,27 @@ export default {
inspectionItem: "", //巡检事项 inspectionItem: "", //巡检事项
detail: [ detail: [
{ {
label: "门禁功能", label: "实际温度",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "正常", inspectionResultLable: "正常",
lableArr: ["正常", "异常"], lableArr: ["正常", "正常"],
conclusion: "",
photos: [],
},
{
label: "门禁外观破损",
inspectionResult: 0,
inspectionResultLable: "无",
lableArr: ["无", "有"],
conclusion: "", conclusion: "",
settingLabel: "设定温度",
setting: "25", //设定温度值
value: "", //输入温度
unit: "℃", //单位
photos: [], photos: [],
}, },
{ {
label: "是否有监控", label: "实际湿度",
inspectionResult: 0,
inspectionResultLable: "有监控",
lableArr: ["有监控", "无监控"],
},
{
label: "监控外观破损",
inspectionResult: 0,
inspectionResultLable: "无",
lableArr: ["无", "有"],
conclusion: "",
photos: [],
},
{
label: "监控画面清晰",
inspectionResult: 0,
inspectionResultLable: "清晰",
lableArr: ["清晰", "模糊"],
conclusion: "",
photos: [],
},
{
label: "监控存储连续",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "正常", inspectionResultLable: "正常",
lableArr: ["正常", "常"], lableArr: ["正常", "常"],
conclusion: "", conclusion: "",
settingLabel: "设定湿度",
setting: "25", //设定湿度值
value: "", //输入湿度
unit: "%", //单位
photos: [], photos: [],
}, },
], ],
...@@ -228,7 +206,7 @@ export default { ...@@ -228,7 +206,7 @@ export default {
// 处理】数据 // 处理】数据
getFromData() { getFromData() {
console.log(111, this.itemData); console.log(111, this.itemData);
const isValid = this.areAllObjectsValid(this.itemData.detail,2); //false不通过 true通过 const isValid = this.areAllObjectsValid(this.itemData.detail, 2); //false不通过 true通过
// const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail); // const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail);
this.itemData.isValid = isValid; this.itemData.isValid = isValid;
this.itemData.inspectionItem = this.inspectionItem; this.itemData.inspectionItem = this.inspectionItem;
...@@ -244,30 +222,35 @@ export default { ...@@ -244,30 +222,35 @@ export default {
// console.log(this.itemData); // console.log(this.itemData);
return this.itemData; return this.itemData;
}, },
// 数据校验方法 true说明有未填项 // / 数据校验方法 true说明有未填项
areAllObjectsValid(arr, skipIndex) { areAllObjectsValid(arr) {
// 遍历数组中的每个对象
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
const obj = arr[i]; const obj = arr[i];
// 如果当前索引大于等于 skipIndex,并且 inspectionResult 为 1,则跳过后续校验 const keys = Object.keys(obj);
if (i >= skipIndex && obj.inspectionResult === 1) { for (let j = 0; j < keys.length; j++) {
break; const key = keys[j];
} const value = obj[key];
// 检查对象中的每个属性是否有值 if (value === null || value === undefined || value === "") {
for (const key in obj) { return false;
if (obj.hasOwnProperty(key)) { }
// 如果属性值为空(null, undefined, 空字符串等),则校验不通过 if (Array.isArray(value)) {
if ( if (value.length === 0) {
obj[key] === null || return false;
obj[key] === undefined || }
obj[key] === "" for (let k = 0; k < value.length; k++) {
) { if (typeof value[k] === "object" && value[k] !== null) {
if (!validateArrayObjects([value[k]])) {
return false;
}
}
}
} else if (typeof value === "object" && value !== null) {
if (!validateArrayObjects([value])) {
return false; return false;
} }
} }
} }
} }
// 如果所有对象都通过校验,返回 true
return true; return true;
}, },
// 校验是否有异常 // 校验是否有异常
...@@ -297,6 +280,13 @@ export default { ...@@ -297,6 +280,13 @@ export default {
margin-right: 3.2px; margin-right: 3.2px;
} }
} }
.input {
width: 50px;
margin-left: 12px;
}
.fg {
margin: 0 12px;
}
.conclusion { .conclusion {
color: #c7c7c7; color: #c7c7c7;
font-size: 11.2px; font-size: 11.2px;
......
...@@ -2,63 +2,34 @@ ...@@ -2,63 +2,34 @@
<!-- 机房巡检操作 --> <!-- 机房巡检操作 -->
<view> <view>
<view v-for="(item, index) in itemData.detail" :key="index"> <view v-for="(item, index) in itemData.detail" :key="index">
<template
v-if="!(index > 2 && itemData.detail[2].inspectionResult === 1)" <view class="form-item">
> <text class="form-label"><text class="required"></text>其他问题</text>
<view class="form-item"> <text class="conclusion" @click="showPopup(index)">{{
<text class="form-label" item.conclusion || "请输入情况摘要"
><text class="required">*</text>{{ item.label }}</text }}</text>
> </view>
<view class="switch-container"> <view class="form-item">
<view <text class="form-label"><text class="required"></text>现场照片</text>
:class="['status-btn', { active: item.inspectionResult === 0 }]" <view class="photo-box">
@click="setInspectionResult(index, 0, item.lableArr[0])" <view class="photo-container">
> <view @click="takePhoto(index)" class="photo-btn"> + </view>
{{ item.lableArr[0] }}
</view>
<view <view
:class="['status-btn', { active: item.inspectionResult === 1 }]" v-for="(photo, itemIndex) in item && item.photos"
@click="setInspectionResult(index, 1, item.lableArr[1])" :key="itemIndex"
class="photo-item"
> >
{{ item.lableArr[1] }} <image :src="photo" class="photo"></image>
<text class="delete-photo" @click="deletePhoto(index, itemIndex)"
>×</text
>
</view> </view>
</view> </view>
</view> <view class="photo-limit"
>请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view
<view v-if="'conclusion' in item" class="form-item">
<text class="form-label"
><text class="required">*</text>情况摘要</text
> >
<text class="conclusion" @click="showPopup(index)">{{
item.conclusion || "请输入情况摘要"
}}</text>
</view> </view>
<view class="form-item" v-if="'photos' in item"> </view> </view
<text class="form-label"
><text class="required">*</text>现场照片</text
>
<view class="photo-box">
<view class="photo-container">
<view @click="takePhoto(index)" class="photo-btn"> + </view>
<view
v-for="(photo, itemIndex) in item && item.photos"
:key="itemIndex"
class="photo-item"
>
<image :src="photo" class="photo"></image>
<text
class="delete-photo"
@click="deletePhoto(index, itemIndex)"
>×</text
>
</view>
</view>
<view class="photo-limit"
>请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view
>
</view>
</view></template
> </view
><custom-popup ><custom-popup
ref="customPopup" ref="customPopup"
:inspectionItem="inspectionItem" :inspectionItem="inspectionItem"
...@@ -87,60 +58,15 @@ export default { ...@@ -87,60 +58,15 @@ export default {
default: "", default: "",
}, },
// 父组件传递的数据 // 父组件传递的数据
defaultData: { itemData: {
type: Object, type: Object,
default: {}, default: () => ({
}, isValid: true, // true是不校验
},
data() {
return {
currentIndex: 0, // 当前操作的索引
photos: [],
itemData: {
isValid: false, // false是校验未通过 true是校验通过
// status: 0, 0是未巡检 1是已巡检 2巡检异常 statusLabel: "未巡检", // status: 0, 0是未巡检 1是已巡检 2巡检异常 statusLabel: "未巡检",
inspectionItem: "", //巡检事项 inspectionItem: "", //巡检事项
detail: [ detail: [
{ {
label: "门禁功能", label: "机柜",
inspectionResult: 0,
inspectionResultLable: "正常",
lableArr: ["正常", "异常"],
conclusion: "",
photos: [],
},
{
label: "门禁外观破损",
inspectionResult: 0,
inspectionResultLable: "无",
lableArr: ["无", "有"],
conclusion: "",
photos: [],
},
{
label: "是否有监控",
inspectionResult: 0,
inspectionResultLable: "有监控",
lableArr: ["有监控", "无监控"],
},
{
label: "监控外观破损",
inspectionResult: 0,
inspectionResultLable: "无",
lableArr: ["无", "有"],
conclusion: "",
photos: [],
},
{
label: "监控画面清晰",
inspectionResult: 0,
inspectionResultLable: "清晰",
lableArr: ["清晰", "模糊"],
conclusion: "",
photos: [],
},
{
label: "监控存储连续",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "正常", inspectionResultLable: "正常",
lableArr: ["正常", "异常"], lableArr: ["正常", "异常"],
...@@ -148,7 +74,13 @@ export default { ...@@ -148,7 +74,13 @@ export default {
photos: [], photos: [],
}, },
], ],
}, }),
},
},
data() {
return {
currentIndex: 0, // 当前操作的索引
photos: [],
}; };
}, },
computed: { computed: {
...@@ -156,11 +88,7 @@ export default { ...@@ -156,11 +88,7 @@ export default {
return this.$store.state.now_user || {}; return this.$store.state.now_user || {};
}, },
}, },
mounted() { mounted() {},
if (Object.keys(this.defaultData).length !== 0) {
this.itemData = this.defaultData;
}
},
methods: { methods: {
// 拍照 // 拍照
takePhoto(index) { takePhoto(index) {
...@@ -212,9 +140,8 @@ export default { ...@@ -212,9 +140,8 @@ export default {
}, },
// 设置巡检结论 // 设置巡检结论
setInspectionResult(index, value, label) { setInspectionResult(index, value) {
this.itemData.detail[index].inspectionResult = value; // 0正常 1异常 this.itemData.detail[index].inspectionResult = value; // 0正常 1异常
this.itemData.detail[index].inspectionResultLable = label;
}, },
// 显示弹窗 // 显示弹窗
showPopup(index) { showPopup(index) {
...@@ -227,47 +154,38 @@ export default { ...@@ -227,47 +154,38 @@ export default {
}, },
// 处理】数据 // 处理】数据
getFromData() { getFromData() {
console.log(111, this.itemData);
const isValid = this.areAllObjectsValid(this.itemData.detail,2); //false不通过 true通过
// const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail);
this.itemData.isValid = isValid;
this.itemData.inspectionItem = this.inspectionItem; this.itemData.inspectionItem = this.inspectionItem;
console.log(222, this.itemData);
// if (isAllOne) {
// // 全都是正常
// this.itemData.status = 1; //1表示已经巡检过没有异常
// this.itemData.statusLabel = "已巡检";
// } else {
// this.itemData.status = 2; //1表示已经巡检过有异常
// this.itemData.statusLabel = "巡检异常";
// }
// console.log(this.itemData);
return this.itemData; return this.itemData;
}, },
// 数据校验方法 true说明有未填项 // 数据校验方法 true说明有未填项
areAllObjectsValid(arr, skipIndex) { areAllObjectsValid(arr) {
// 遍历数组中的每个对象
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
const obj = arr[i]; const obj = arr[i];
// 如果当前索引大于等于 skipIndex,并且 inspectionResult 为 1,则跳过后续校验 const keys = Object.keys(obj);
if (i >= skipIndex && obj.inspectionResult === 1) { for (let j = 0; j < keys.length; j++) {
break; const key = keys[j];
} const value = obj[key];
// 检查对象中的每个属性是否有值 if (value === null || value === undefined || value === "") {
for (const key in obj) { return false;
if (obj.hasOwnProperty(key)) { }
// 如果属性值为空(null, undefined, 空字符串等),则校验不通过 if (Array.isArray(value)) {
if ( if (value.length === 0) {
obj[key] === null || return false;
obj[key] === undefined || }
obj[key] === "" for (let k = 0; k < value.length; k++) {
) { if (typeof value[k] === "object" && value[k] !== null) {
if (!validateArrayObjects([value[k]])) {
return false;
}
}
}
} else if (typeof value === "object" && value !== null) {
if (!validateArrayObjects([value])) {
return false; return false;
} }
} }
} }
} }
// 如果所有对象都通过校验,返回 true
return true; return true;
}, },
// 校验是否有异常 // 校验是否有异常
......
...@@ -24,7 +24,33 @@ ...@@ -24,7 +24,33 @@
</view> </view>
</view> </view>
</view> </view>
<view class="form-item">
<text class="form-label"
><text class="required">*</text>{{ item.deviceLabel }}</text
><input
class="conclusion"
v-model="item.deviceId"
type="text"
placeholder="请输入编号"
/>
</view>
<view class="form-item">
<text class="form-label"
><text class="required">*</text>{{ item.UpositonLabel }}</text
><input
class="input"
v-model="item.UpositonS"
type="number"
placeholder="请输入"
maxlength="2"
/> <text class="fg"></text><input
class="input"
v-model="item.UpositonE"
type="number"
placeholder="请输入"
maxlength="2"
/>
</view>
<view v-if="'conclusion' in item" class="form-item"> <view v-if="'conclusion' in item" class="form-item">
<text class="form-label" <text class="form-label"
><text class="required">*</text>情况摘要</text ><text class="required">*</text>情况摘要</text
...@@ -102,49 +128,16 @@ export default { ...@@ -102,49 +128,16 @@ export default {
inspectionItem: "", //巡检事项 inspectionItem: "", //巡检事项
detail: [ detail: [
{ {
label: "门禁功能", label: "是否有告警",
inspectionResult: 0,
inspectionResultLable: "正常",
lableArr: ["正常", "异常"],
conclusion: "",
photos: [],
},
{
label: "门禁外观破损",
inspectionResult: 0,
inspectionResultLable: "无",
lableArr: ["无", "有"],
conclusion: "",
photos: [],
},
{
label: "是否有监控",
inspectionResult: 0,
inspectionResultLable: "有监控",
lableArr: ["有监控", "无监控"],
},
{
label: "监控外观破损",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "无", inspectionResultLable: "无",
lableArr: ["无", "有"], lableArr: ["无", "有"],
conclusion: "", conclusion: "",
photos: [], deviceLabel: "故障设备机柜",
}, deviceId: "",
{ UpositonLabel: "U位",
label: "监控画面清晰", UpositonS: "",
inspectionResult: 0, UpositonE: "",
inspectionResultLable: "清晰",
lableArr: ["清晰", "模糊"],
conclusion: "",
photos: [],
},
{
label: "监控存储连续",
inspectionResult: 0,
inspectionResultLable: "正常",
lableArr: ["正常", "异常"],
conclusion: "",
photos: [], photos: [],
}, },
], ],
...@@ -228,7 +221,7 @@ export default { ...@@ -228,7 +221,7 @@ export default {
// 处理】数据 // 处理】数据
getFromData() { getFromData() {
console.log(111, this.itemData); console.log(111, this.itemData);
const isValid = this.areAllObjectsValid(this.itemData.detail,2); //false不通过 true通过 const isValid = this.areAllObjectsValid(this.itemData.detail, 2); //false不通过 true通过
// const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail); // const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail);
this.itemData.isValid = isValid; this.itemData.isValid = isValid;
this.itemData.inspectionItem = this.inspectionItem; this.itemData.inspectionItem = this.inspectionItem;
...@@ -297,6 +290,12 @@ export default { ...@@ -297,6 +290,12 @@ export default {
margin-right: 3.2px; margin-right: 3.2px;
} }
} }
.input {
width: 50px;
}
.fg {
margin: 0 12px;
}
.conclusion { .conclusion {
color: #c7c7c7; color: #c7c7c7;
font-size: 11.2px; font-size: 11.2px;
......
...@@ -212,28 +212,28 @@ export default { ...@@ -212,28 +212,28 @@ export default {
}, },
// 数据校验方法 true说明有未填项 // 数据校验方法 true说明有未填项
areAllObjectsValid(arr) { areAllObjectsValid(arr) {
function isEmpty(value) {
return (
value === null ||
value === undefined ||
(typeof value === "string" && value.trim() === "") ||
(Array.isArray(value) && value.length === 0) ||
(typeof value === "object" &&
!Array.isArray(value) &&
Object.keys(value).length === 0)
);
}
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
const obj = arr[i]; const obj = arr[i];
for (const key in obj) { const keys = Object.keys(obj);
if (obj.hasOwnProperty(key)) { for (let j = 0; j < keys.length; j++) {
const value = obj[key]; const key = keys[j];
if (typeof value === "object") { const value = obj[key];
if (isEmpty(value) || !allPropertiesNonEmpty([value])) { if (value === null || value === undefined || value === "") {
return false; return false;
}
if (Array.isArray(value)) {
if (value.length === 0) {
return false;
}
for (let k = 0; k < value.length; k++) {
if (typeof value[k] === "object" && value[k] !== null) {
if (!validateArrayObjects([value[k]])) {
return false;
}
} }
} else if (isEmpty(value)) { }
} else if (typeof value === "object" && value !== null) {
if (!validateArrayObjects([value])) {
return false; return false;
} }
} }
......
...@@ -2,63 +2,63 @@ ...@@ -2,63 +2,63 @@
<!-- 机房巡检操作 --> <!-- 机房巡检操作 -->
<view> <view>
<view v-for="(item, index) in itemData.detail" :key="index"> <view v-for="(item, index) in itemData.detail" :key="index">
<template <view v-if="'settingLabel' in item" class="form-item">
v-if="!(index > 2 && itemData.detail[2].inspectionResult === 1)" <text class="form-label"
> ><text class="required">*</text>{{ item.settingLabel }}</text
<view class="form-item"> ><text>{{ item.setting }}</text>
<text class="form-label" </view>
><text class="required">*</text>{{ item.label }}</text <view class="form-item">
<text class="form-label"
><text class="required">*</text>{{ item.label }}</text
>
<view class="switch-container">
<view
:class="['status-btn', { active: item.inspectionResult === 0 }]"
@click="setInspectionResult(index, 0, item.lableArr[0])"
> >
<view class="switch-container"> {{ item.lableArr[0] }}
<view </view>
:class="['status-btn', { active: item.inspectionResult === 0 }]" <view
@click="setInspectionResult(index, 0, item.lableArr[0])" :class="['status-btn', { active: item.inspectionResult === 1 }]"
> @click="setInspectionResult(index, 1, item.lableArr[1])"
{{ item.lableArr[0] }} >
</view> {{ item.lableArr[1] }}
</view> </view
><input v-if="'value' in item"
class="input"
v-model="item.value"
type="text"
placeholder="请输入"
maxlength="3"
/>{{ item.unit }}
</view>
<view v-if="'conclusion' in item" class="form-item">
<text class="form-label"><text class="required">*</text>情况摘要</text>
<text class="conclusion" @click="showPopup(index)">{{
item.conclusion || "请输入情况摘要"
}}</text>
</view>
<view class="form-item" v-if="'photos' in item">
<text class="form-label"><text class="required">*</text>现场照片</text>
<view class="photo-box">
<view class="photo-container">
<view @click="takePhoto(index)" class="photo-btn"> + </view>
<view <view
:class="['status-btn', { active: item.inspectionResult === 1 }]" v-for="(photo, itemIndex) in item && item.photos"
@click="setInspectionResult(index, 1, item.lableArr[1])" :key="itemIndex"
class="photo-item"
> >
{{ item.lableArr[1] }} <image :src="photo" class="photo"></image>
<text class="delete-photo" @click="deletePhoto(index, itemIndex)"
>×</text
>
</view> </view>
</view> </view>
</view> <view class="photo-limit"
>请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view
<view v-if="'conclusion' in item" class="form-item">
<text class="form-label"
><text class="required">*</text>情况摘要</text
> >
<text class="conclusion" @click="showPopup(index)">{{
item.conclusion || "请输入情况摘要"
}}</text>
</view> </view>
<view class="form-item" v-if="'photos' in item"> </view></view
<text class="form-label"
><text class="required">*</text>现场照片</text
>
<view class="photo-box">
<view class="photo-container">
<view @click="takePhoto(index)" class="photo-btn"> + </view>
<view
v-for="(photo, itemIndex) in item && item.photos"
:key="itemIndex"
class="photo-item"
>
<image :src="photo" class="photo"></image>
<text
class="delete-photo"
@click="deletePhoto(index, itemIndex)"
>×</text
>
</view>
</view>
<view class="photo-limit"
>请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view
>
</view>
</view></template
> </view
><custom-popup ><custom-popup
ref="customPopup" ref="customPopup"
:inspectionItem="inspectionItem" :inspectionItem="inspectionItem"
...@@ -102,48 +102,30 @@ export default { ...@@ -102,48 +102,30 @@ export default {
inspectionItem: "", //巡检事项 inspectionItem: "", //巡检事项
detail: [ detail: [
{ {
label: "门禁功能", label: "七氟丙烷灭火气压",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "正常", inspectionResultLable: "正常",
lableArr: ["正常", "异常"], lableArr: ["正常", "正常"],
conclusion: "",
photos: [],
},
{
label: "门禁外观破损",
inspectionResult: 0,
inspectionResultLable: "无",
lableArr: ["无", "有"],
conclusion: "", conclusion: "",
settingLabel: "气压设定值",
setting: "2MPA-4.2MPA", //设定气压
value: "", //请输入
unit: "MPA", //单位
photos: [], photos: [],
}, },
{ {
label: "是否有监控", label: "消防报警器",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "有监控", inspectionResultLable: "正常",
lableArr: ["有监控", "无监控"], lableArr: ["正常", "正常"],
},
{
label: "监控外观破损",
inspectionResult: 0,
inspectionResultLable: "无",
lableArr: ["无", "有"],
conclusion: "",
photos: [],
},
{
label: "监控画面清晰",
inspectionResult: 0,
inspectionResultLable: "清晰",
lableArr: ["清晰", "模糊"],
conclusion: "", conclusion: "",
photos: [], photos: [],
}, },
{ {
label: "监控存储连续", label: "防毒面具",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "正常", inspectionResultLable: "正常",
lableArr: ["正常", "常"], lableArr: ["正常", "常"],
conclusion: "", conclusion: "",
photos: [], photos: [],
}, },
...@@ -228,7 +210,7 @@ export default { ...@@ -228,7 +210,7 @@ export default {
// 处理】数据 // 处理】数据
getFromData() { getFromData() {
console.log(111, this.itemData); console.log(111, this.itemData);
const isValid = this.areAllObjectsValid(this.itemData.detail,2); //false不通过 true通过 const isValid = this.areAllObjectsValid(this.itemData.detail, 2); //false不通过 true通过
// const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail); // const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail);
this.itemData.isValid = isValid; this.itemData.isValid = isValid;
this.itemData.inspectionItem = this.inspectionItem; this.itemData.inspectionItem = this.inspectionItem;
...@@ -244,30 +226,35 @@ export default { ...@@ -244,30 +226,35 @@ export default {
// console.log(this.itemData); // console.log(this.itemData);
return this.itemData; return this.itemData;
}, },
// 数据校验方法 true说明有未填项 // / 数据校验方法 true说明有未填项
areAllObjectsValid(arr, skipIndex) { areAllObjectsValid(arr) {
// 遍历数组中的每个对象
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
const obj = arr[i]; const obj = arr[i];
// 如果当前索引大于等于 skipIndex,并且 inspectionResult 为 1,则跳过后续校验 const keys = Object.keys(obj);
if (i >= skipIndex && obj.inspectionResult === 1) { for (let j = 0; j < keys.length; j++) {
break; const key = keys[j];
} const value = obj[key];
// 检查对象中的每个属性是否有值 if (value === null || value === undefined || value === "") {
for (const key in obj) { return false;
if (obj.hasOwnProperty(key)) { }
// 如果属性值为空(null, undefined, 空字符串等),则校验不通过 if (Array.isArray(value)) {
if ( if (value.length === 0) {
obj[key] === null || return false;
obj[key] === undefined || }
obj[key] === "" for (let k = 0; k < value.length; k++) {
) { if (typeof value[k] === "object" && value[k] !== null) {
if (!validateArrayObjects([value[k]])) {
return false;
}
}
}
} else if (typeof value === "object" && value !== null) {
if (!validateArrayObjects([value])) {
return false; return false;
} }
} }
} }
} }
// 如果所有对象都通过校验,返回 true
return true; return true;
}, },
// 校验是否有异常 // 校验是否有异常
...@@ -297,6 +284,13 @@ export default { ...@@ -297,6 +284,13 @@ export default {
margin-right: 3.2px; margin-right: 3.2px;
} }
} }
.input {
width: 50px;
margin-left: 12px;
}
.fg {
margin: 0 12px;
}
.conclusion { .conclusion {
color: #c7c7c7; color: #c7c7c7;
font-size: 11.2px; font-size: 11.2px;
......
...@@ -2,63 +2,53 @@ ...@@ -2,63 +2,53 @@
<!-- 机房巡检操作 --> <!-- 机房巡检操作 -->
<view> <view>
<view v-for="(item, index) in itemData.detail" :key="index"> <view v-for="(item, index) in itemData.detail" :key="index">
<template <view class="form-item">
v-if="!(index > 2 && itemData.detail[2].inspectionResult === 1)" <text class="form-label"
> ><text class="required">*</text>{{ item.label }}</text
<view class="form-item"> >
<text class="form-label" <view class="switch-container">
><text class="required">*</text>{{ item.label }}</text <view
:class="['status-btn', { active: item.inspectionResult === 0 }]"
@click="setInspectionResult(index, 0)"
> >
<view class="switch-container"> 正常
<view
:class="['status-btn', { active: item.inspectionResult === 0 }]"
@click="setInspectionResult(index, 0, item.lableArr[0])"
>
{{ item.lableArr[0] }}
</view>
<view
:class="['status-btn', { active: item.inspectionResult === 1 }]"
@click="setInspectionResult(index, 1, item.lableArr[1])"
>
{{ item.lableArr[1] }}
</view>
</view> </view>
</view> <view
:class="['status-btn', { active: item.inspectionResult === 1 }]"
<view v-if="'conclusion' in item" class="form-item"> @click="setInspectionResult(index, 1)"
<text class="form-label"
><text class="required">*</text>情况摘要</text
> >
<text class="conclusion" @click="showPopup(index)">{{ 异常
item.conclusion || "请输入情况摘要" </view>
}}</text>
</view> </view>
<view class="form-item" v-if="'photos' in item"> </view>
<text class="form-label"
><text class="required">*</text>现场照片</text <view class="form-item">
> <text class="form-label"><text class="required">*</text>情况摘要</text>
<view class="photo-box"> <text class="conclusion" @click="showPopup(index)">{{
<view class="photo-container"> item.conclusion || "请输入情况摘要"
<view @click="takePhoto(index)" class="photo-btn"> + </view> }}</text>
<view </view>
v-for="(photo, itemIndex) in item && item.photos" <view class="form-item">
:key="itemIndex" <text class="form-label"><text class="required">*</text>现场照片</text>
class="photo-item" <view class="photo-box">
<view class="photo-container">
<view @click="takePhoto(index)" class="photo-btn"> + </view>
<view
v-for="(photo, itemIndex) in item && item.photos"
:key="itemIndex"
class="photo-item"
>
<image :src="photo" class="photo"></image>
<text class="delete-photo" @click="deletePhoto(index, itemIndex)"
>×</text
> >
<image :src="photo" class="photo"></image>
<text
class="delete-photo"
@click="deletePhoto(index, itemIndex)"
>×</text
>
</view>
</view> </view>
<view class="photo-limit"
>请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view
>
</view> </view>
</view></template <view class="photo-limit"
> </view >请对检查项进行拍照留存(限5张)。发现“异常、告警”时,需拍照留存。</view
>
</view>
</view> </view
><custom-popup ><custom-popup
ref="customPopup" ref="customPopup"
:inspectionItem="inspectionItem" :inspectionItem="inspectionItem"
...@@ -87,22 +77,15 @@ export default { ...@@ -87,22 +77,15 @@ export default {
default: "", default: "",
}, },
// 父组件传递的数据 // 父组件传递的数据
defaultData: { itemData: {
type: Object, type: Object,
default: {}, default: () => ({
},
},
data() {
return {
currentIndex: 0, // 当前操作的索引
photos: [],
itemData: {
isValid: false, // false是校验未通过 true是校验通过 isValid: false, // false是校验未通过 true是校验通过
// status: 0, 0是未巡检 1是已巡检 2巡检异常 statusLabel: "未巡检", // status: 0, 0是未巡检 1是已巡检 2巡检异常 statusLabel: "未巡检",
inspectionItem: "", //巡检事项 inspectionItem: "", //巡检事项
detail: [ detail: [
{ {
label: "门禁功能", label: "机柜",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "正常", inspectionResultLable: "正常",
lableArr: ["正常", "异常"], lableArr: ["正常", "异常"],
...@@ -110,37 +93,15 @@ export default { ...@@ -110,37 +93,15 @@ export default {
photos: [], photos: [],
}, },
{ {
label: "门禁外观破损", label: "配线架",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "无", inspectionResultLable: "正常",
lableArr: ["无", "有"], lableArr: ["正常", "异常"],
conclusion: "",
photos: [],
},
{
label: "是否有监控",
inspectionResult: 0,
inspectionResultLable: "有监控",
lableArr: ["有监控", "无监控"],
},
{
label: "监控外观破损",
inspectionResult: 0,
inspectionResultLable: "无",
lableArr: ["无", "有"],
conclusion: "",
photos: [],
},
{
label: "监控画面清晰",
inspectionResult: 0,
inspectionResultLable: "清晰",
lableArr: ["清晰", "模糊"],
conclusion: "", conclusion: "",
photos: [], photos: [],
}, },
{ {
label: "监控存储连续", label: "电力线路",
inspectionResult: 0, inspectionResult: 0,
inspectionResultLable: "正常", inspectionResultLable: "正常",
lableArr: ["正常", "异常"], lableArr: ["正常", "异常"],
...@@ -148,7 +109,13 @@ export default { ...@@ -148,7 +109,13 @@ export default {
photos: [], photos: [],
}, },
], ],
}, }),
},
},
data() {
return {
currentIndex: 0, // 当前操作的索引
photos: [],
}; };
}, },
computed: { computed: {
...@@ -156,11 +123,7 @@ export default { ...@@ -156,11 +123,7 @@ export default {
return this.$store.state.now_user || {}; return this.$store.state.now_user || {};
}, },
}, },
mounted() { mounted() {},
if (Object.keys(this.defaultData).length !== 0) {
this.itemData = this.defaultData;
}
},
methods: { methods: {
// 拍照 // 拍照
takePhoto(index) { takePhoto(index) {
...@@ -212,9 +175,8 @@ export default { ...@@ -212,9 +175,8 @@ export default {
}, },
// 设置巡检结论 // 设置巡检结论
setInspectionResult(index, value, label) { setInspectionResult(index, value) {
this.itemData.detail[index].inspectionResult = value; // 0正常 1异常 this.itemData.detail[index].inspectionResult = value; // 0正常 1异常
this.itemData.detail[index].inspectionResultLable = label;
}, },
// 显示弹窗 // 显示弹窗
showPopup(index) { showPopup(index) {
...@@ -227,12 +189,10 @@ export default { ...@@ -227,12 +189,10 @@ export default {
}, },
// 处理】数据 // 处理】数据
getFromData() { getFromData() {
console.log(111, this.itemData); const isValid = this.areAllObjectsValid(this.itemData.detail); //false不通过 true通过
const isValid = this.areAllObjectsValid(this.itemData.detail,2); //false不通过 true通过 const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail);
// const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail);
this.itemData.isValid = isValid; this.itemData.isValid = isValid;
this.itemData.inspectionItem = this.inspectionItem; this.itemData.inspectionItem = this.inspectionItem;
console.log(222, this.itemData);
// if (isAllOne) { // if (isAllOne) {
// // 全都是正常 // // 全都是正常
// this.itemData.status = 1; //1表示已经巡检过没有异常 // this.itemData.status = 1; //1表示已经巡检过没有异常
...@@ -245,29 +205,34 @@ export default { ...@@ -245,29 +205,34 @@ export default {
return this.itemData; return this.itemData;
}, },
// 数据校验方法 true说明有未填项 // 数据校验方法 true说明有未填项
areAllObjectsValid(arr, skipIndex) { areAllObjectsValid(arr) {
// 遍历数组中的每个对象
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
const obj = arr[i]; const obj = arr[i];
// 如果当前索引大于等于 skipIndex,并且 inspectionResult 为 1,则跳过后续校验 const keys = Object.keys(obj);
if (i >= skipIndex && obj.inspectionResult === 1) { for (let j = 0; j < keys.length; j++) {
break; const key = keys[j];
} const value = obj[key];
// 检查对象中的每个属性是否有值 if (value === null || value === undefined || value === "") {
for (const key in obj) { return false;
if (obj.hasOwnProperty(key)) { }
// 如果属性值为空(null, undefined, 空字符串等),则校验不通过 if (Array.isArray(value)) {
if ( if (value.length === 0) {
obj[key] === null || return false;
obj[key] === undefined || }
obj[key] === "" for (let k = 0; k < value.length; k++) {
) { if (typeof value[k] === "object" && value[k] !== null) {
if (!validateArrayObjects([value[k]])) {
return false;
}
}
}
} else if (typeof value === "object" && value !== null) {
if (!validateArrayObjects([value])) {
return false; return false;
} }
} }
} }
} }
// 如果所有对象都通过校验,返回 true
return true; return true;
}, },
// 校验是否有异常 // 校验是否有异常
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
v-show="checkValueInArray(tabs, 'wlhj', activeTab)" v-show="checkValueInArray(tabs, 'wlhj', activeTab)"
ref="wlhj" ref="wlhj"
:inspectionItem="tabs[activeTab].label" :inspectionItem="tabs[activeTab].label"
:defaultData="{}" :defaultData="list.wlhj || {}"
></wlhj> ></wlhj>
<!-- 安防系统 --> <!-- 安防系统 -->
<afxt <afxt
...@@ -66,6 +66,56 @@ ...@@ -66,6 +66,56 @@
:inspectionItem="tabs[activeTab].label" :inspectionItem="tabs[activeTab].label"
:defaultData="{}" :defaultData="{}"
></afxt> ></afxt>
<!-- 设备告警 -->
<sbgj
v-show="checkValueInArray(tabs, 'sbgj', activeTab)"
ref="sbgj"
:inspectionItem="tabs[activeTab].label"
:defaultData="{}"
></sbgj>
<!-- 电池状态 -->
<dczt
v-show="checkValueInArray(tabs, 'dczt', activeTab)"
ref="dczt"
:inspectionItem="tabs[activeTab].label"
:defaultData="{}"
:jfType ="jfType"
></dczt>
<!-- 机房温湿度 -->
<jfwsd
v-show="checkValueInArray(tabs, 'jfwsd', activeTab)"
ref="jfwsd"
:inspectionItem="tabs[activeTab].label"
:defaultData="{}"
></jfwsd>
<!-- 电力系统 -->
<dlxt
v-show="checkValueInArray(tabs, 'dlxt', activeTab)"
ref="dlxt"
:inspectionItem="tabs[activeTab].label"
:defaultData="{}"
></dlxt>
<!-- 消防系统 -->
<xfxt
v-show="checkValueInArray(tabs, 'xfxt', activeTab)"
ref="xfxt"
:inspectionItem="tabs[activeTab].label"
:defaultData="{}"
></xfxt>
<!-- 线路情况 -->
<xlqk
v-show="checkValueInArray(tabs, 'xlqk', activeTab)"
ref="xlqk"
:inspectionItem="tabs[activeTab].label"
:defaultData="{}"
></xlqk>
<!-- 其它 -->
<qt
v-show="checkValueInArray(tabs, 'qt', activeTab)"
ref="qt"
:inspectionItem="tabs[activeTab].label"
:defaultData="{}"
></qt>
</view> </view>
</view> </view>
<view class="submit-module"> <view class="submit-module">
...@@ -106,8 +156,8 @@ import wlhj from "./components/wlhj.vue"; //物理环境 ...@@ -106,8 +156,8 @@ import wlhj from "./components/wlhj.vue"; //物理环境
import afxt from "./components/afxt.vue"; //安防系统 import afxt from "./components/afxt.vue"; //安防系统
import sbgj from "./components/sbgj.vue"; //设备告警 import sbgj from "./components/sbgj.vue"; //设备告警
import dczt from "./components/dczt.vue"; //电池状态 import dczt from "./components/dczt.vue"; //电池状态
import jfwsd from "./components/sbgj.vue"; //机房温湿度 import jfwsd from "./components/jfwsd.vue"; //机房温湿度
import dlxt from "./components/afxt.vue"; //电力系统 import dlxt from "./components/dlxt.vue"; //电力系统
import xfxt from "./components/xfxt.vue"; //消防系统 import xfxt from "./components/xfxt.vue"; //消防系统
import xlqk from "./components/xlqk.vue"; //线路情况 import xlqk from "./components/xlqk.vue"; //线路情况
import qt from "./components/qt.vue"; //其它 import qt from "./components/qt.vue"; //其它
...@@ -266,64 +316,6 @@ export default { ...@@ -266,64 +316,6 @@ export default {
this.list = data; this.list = data;
}, },
// 更新当前 Tab 数据
updateCurrentTabData() {
const currentTabData = this.list[this.activeTab];
this.inspectionResult = currentTabData.inspectionResult;
this.conclusion = currentTabData.conclusion;
this.photos = currentTabData.photos;
},
// 拍照
takePhoto() {
uni.chooseImage({
count: 1,
sourceType: ["camera"], // 可以从相机拍摄
success: async (res) => {
if (this.photos.length < 5) {
const base64 = await this.convertFileToBase64(res.tempFilePaths[0]);
this.photos.push(base64);
this.list[this.activeTab].photos = this.photos;
} else {
uni.showToast({
title: "最多只能上传5张照片",
icon: "none",
});
}
},
});
},
// 转化为base64
convertFileToBase64(filePath) {
return new Promise((resolve, reject) => {
plus.io.resolveLocalFileSystemURL(
filePath,
function (entry) {
entry.file(
function (file) {
const reader = new plus.io.FileReader();
reader.onloadend = function (evt) {
const base64 = evt.target.result; // 获取 Base64 数据
resolve(base64); // 返回 Base64 数据
};
reader.readAsDataURL(file); // 读取文件并转换为 Base64
},
function (error) {
reject("获取文件对象失败:" + error.message);
}
);
},
function (error) {
reject("解析文件路径失败:" + error.message);
}
);
});
},
// 删除照片
deletePhoto(index) {
this.photos.splice(index, 1);
this.list[this.activeTab].photos = this.photos;
},
// 处理提交数据 // 处理提交数据
getParams(isSubmit) { getParams(isSubmit) {
if (this.uid) { if (this.uid) {
...@@ -437,7 +429,7 @@ export default { ...@@ -437,7 +429,7 @@ export default {
submit(isSubmit = 1) { submit(isSubmit = 1) {
console.log("all", this.getAllChildFormData()); console.log("all", this.getAllChildFormData());
let paramsObj = this.getAllChildFormData(); let paramsObj = this.getAllChildFormData();
return false return false;
let allValid = this.allValid(paramsObj); let allValid = this.allValid(paramsObj);
// 校验是否通过 // 校验是否通过
if (isSubmit && !allValid) { if (isSubmit && !allValid) {
...@@ -560,7 +552,6 @@ export default { ...@@ -560,7 +552,6 @@ export default {
if (this.activeTab !== this.tabs.length - 1) { if (this.activeTab !== this.tabs.length - 1) {
this.isSubmitEnabled = false; this.isSubmitEnabled = false;
} }
this.updateCurrentTabData();
}, // 设置巡检结论 }, // 设置巡检结论
setInspectionResult(value) { setInspectionResult(value) {
console.log("value", value); console.log("value", value);
...@@ -605,6 +596,7 @@ export default { ...@@ -605,6 +596,7 @@ export default {
background: #ffffff; background: #ffffff;
border-radius: 9.6px; border-radius: 9.6px;
padding: 12.8px 20px; padding: 12.8px 20px;
min-height: calc(100vh - 80px);
overflow: hidden; overflow: hidden;
.location { .location {
font-size: 14.4px; font-size: 14.4px;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论