提交 4e244b86 authored 作者: 何宗全's avatar 何宗全

山南添加月度巡检和年度巡检

上级 a64f3cd4
......@@ -4,7 +4,7 @@ import { fixNullVal } from "@/utils/common";
// 巡检
export default {
async selectLastData(data) {
async selectLastData(data, inspectionType = 1) {
let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
try {
let rs = await sqllitedb.selectSQL(
......@@ -12,7 +12,7 @@ export default {
FROM ${table.inspectionRecordName}
WHERE userId = '${data}'
AND createTime >= strftime('%s', 'now') - 7*24*60*60
AND inspectionType = 1
AND inspectionType = '${inspectionType}'
AND (synFlag = 0 OR synFlag = 1)
ORDER BY createTime DESC
LIMIT 1;`
......
......@@ -73,8 +73,8 @@
},
toPage() {
const url =
this.details.inspectionType == 1 ?
`/pages/inspectionContent/inspectionContentList?isDisable=${
this.details.inspectionType != 2 ?
`/pages/inspectionContent/inspectionContentList?inspectionType=${this.details.inspectionType}&isDisable=${
this.isDisable ? 1 : 0
}` :
`/pages/shaftInspection/shaftInspectionList?isDisable=${
......
......@@ -2,9 +2,9 @@
<!-- 巡检管理搜索页 -->
<view class="search-com">
<view class="search-com-left">
<!-- <uni-data-select v-if="!hiddenSearch.includes('inspectionType')" class="uni-search-item"
<uni-data-select v-if="!hiddenSearch.includes('inspectionType')" class="uni-search-item bigLong"
v-model="searchFrom.inspectionType" :localdata="inspectArr" @change="(e) => change(e, 'inspectionType')"
placeholder="类型"></uni-data-select> -->
placeholder="类型"></uni-data-select>
<uni-data-select v-if="!hiddenSearch.includes('synFlag')" class="uni-search-item" v-model="searchFrom.synFlag" :localdata="synchronization" placeholder="是否同步"
@change="(e) => change(e, 'synFlag')"></uni-data-select>
......@@ -46,12 +46,20 @@
},
{
value: "1",
text: "机房巡检"
text: "机房日常巡检"
},
{
value: "2",
text: "井道巡检"
},
{
value: "3",
text: "机房月度巡检"
},
{
value: "4",
text: "机房年度巡检"
},
],
synchronization: [{
value: "-1",
......@@ -114,6 +122,9 @@
background: #fff;
border-radius: 10px;
border: none !important;
&.bigLong{
width: 240px;
}
}
}
......
......@@ -77,7 +77,21 @@
"style": {
"navigationBarTitleText": ""
}
},
},
// 机房月度巡检新页面
{
"path": "pages/inspectionContent/inspectionContentMonthlyNew",
"style": {
"navigationBarTitleText": ""
}
},
// 机房年度巡检新页面
{
"path": "pages/inspectionContent/inspectionContentYearNew",
"style": {
"navigationBarTitleText": ""
}
},
// 井道巡检列表
{
"path": "pages/shaftInspection/shaftInspectionList",
......
......@@ -65,22 +65,22 @@
@confirm="dialogInputConfirm2"
>
</uni-popup-dialog>
</uni-popup>
</uni-popup>
</view>
</template>
<script>
import { copyDirectory } from "@/utils/IoReadingAndWriting.js";
import inspectApi from "@/api/inspect.js";
import { cleanTimeoutDataApi } from '@/api/base.js'
import inspectApi from "@/api/inspect.js";
import { cleanTimeoutDataApi } from "@/api/base.js";
export default {
data() {
return {
cards: [
{
image: "../../static/img/jf.png",
text: "机房巡检",
url: "/pages/inspectionContent/inspectionContentList?backValue=home",
text: "机房日常巡检",
url: "/pages/inspectionContent/inspectionContentList?backValue=home&inspectionType=1",
},
// {
// image: "../../static/img/jd.png",
......@@ -92,6 +92,16 @@ export default {
text: "设备上架",
url: "/pages/listingManagement/index?backValue=home",
},
{
image: "../../static/img/jf.png",
text: "机房月度巡检",
url: "/pages/inspectionContent/inspectionContentList?backValue=home&inspectionType=3",
},
{
image: "../../static/img/jf.png",
text: "机房年度巡检",
url: "/pages/inspectionContent/inspectionContentList?backValue=home&inspectionType=4",
},
],
userName: this.$store.state.now_user.user,
};
......@@ -102,8 +112,8 @@ export default {
},
},
created() {
console.log(this.$store.state);
cleanTimeoutDataApi();
console.log(this.$store.state);
cleanTimeoutDataApi();
},
methods: {
// 修改密码
......@@ -154,7 +164,7 @@ export default {
uni.setStorageSync("now_user", this.$store.state.now_user);
uni.setStorageSync(
"last_time",
this.$store.state.now_user.LastSynchronizationTime || ""
this.$store.state.now_user.LastSynchronizationTime || "",
);
},
});
......@@ -181,7 +191,7 @@ export default {
align-items: center;
padding: 10px;
position: relative;
margin-bottom: 147px;
margin-bottom: 60px;
.title {
position: absolute;
......@@ -193,8 +203,8 @@ export default {
text-align: center;
line-height: 40px;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.16);
font-weight: 500;
white-space: nowrap;
font-weight: 500;
white-space: nowrap;
}
.header-buttons {
......@@ -235,7 +245,7 @@ export default {
}
.profile-section {
width: 720px;
width: 680px;
.profile-box {
background-color: #fff;
......@@ -320,21 +330,23 @@ export default {
}
.card-section {
width: 720px;
margin-top: 20px;
width: 432px;
margin-top: 16px;
.card-container {
display: flex;
justify-content: space-evenly;
flex-wrap: wrap;
justify-content: space-between;
gap: 20px;
.card {
width: 224px;
height: 194px;
border-radius: 10px;
width: 206px;
height: 140px;
border-radius: 9px;
display: flex;
flex-direction: column;
align-items: center;
padding-top: 130px;
padding-top: 95px;
background-size: cover; // 背景图覆盖整个卡片
background-position: center; // 背景图居中
......@@ -348,6 +360,5 @@ export default {
}
}
}
}
}
</style>
......@@ -77,13 +77,21 @@ export default {
return {
rooms: [
{
text: "机房巡检",
text: "机房日常巡检",
value: "1",
},
{
text: "井道巡检",
value: "2",
},
{
text: "机房月度巡检",
value: "3",
},
{
text: "机房年度巡检",
value: "4",
},
],
formData: {
inspectionType: "",
......
<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.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>
</view>
<template v-if="item.inspectionResult === 1">
<view class="form-item">
<text class="form-label"
><text class="required">*</text>情况摘要</text
>
<text
:class="['conclusion', { 'no-text': !item.conclusion }]"
@click="showPopup(item, index)"
>
{{ item.conclusion || "请输入情况摘要" }}</text
>
</view>
<view class="form-item">
<text class="form-label"
><text class="required">*</text>现场照片</text
>
<CommonUpload v-model="item.photos" :max-count="5">
</CommonUpload> </view
></template> </view
><custom-popup
ref="customPopup"
:inspectionItem="inspectionItem"
@confirm="handlePopupConfirm"
></custom-popup>
</view>
</template>
<script>
import CommonUpload from "@/components/CommonUpload/index.vue";
import customPopup from "./customPopup.vue";
import _ from "lodash";
import mixin from "./mixin";
export default {
components: {
CommonUpload,
customPopup,
},
mixins: [mixin],
props: {
// 父组件传递的巡检状态
status: {
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: "",
inspectionResultLable: "正常",
lableArr: ["正常", "异常"],
conclusion: "",
photos: [],
},
],
},
};
},
computed: {
userInfo() {
return this.$store.state.now_user || {};
},
},
watch: {
defaultData(newVal) {
// 在这里处理数据变化
if (Object.keys(this.defaultData).length !== 0) {
this.itemData = this.defaultData;
}
},
},
async mounted() {
console.log("sdsadasd", 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);
},
// 处理弹窗确认
handlePopupConfirm(summary) {
this.itemData.detail[this.currentIndex].conclusion = summary; // 回显到文字显示区域
},
// 处理】数据
getFromData() {
const isValid = this.areAllObjectsValid(this.itemData.detail); //false不通过 true通过
console.log("wlhj", isValid);
const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail);
console.log("isAllOne", isAllOne);
this.itemData.isValid = isValid;
this.itemData.inspectionItem = this.inspectionItem;
this.itemData.status = isAllOne.status; //1表示已经巡检过没有异常
this.itemData.statusLabel = isAllOne.statusLabel;
console.log("查看数据", this.itemData);
return this.itemData;
},
// 数据校验方法 true说明有未填项
areAllObjectsValid(details) {
// 检查是否有任何项的 inspectionResult 为空字符串
const hasEmptyResult = details.some(
(item) => item.inspectionResult === "",
);
if (hasEmptyResult) {
return false;
}
// 遍历每一项进行检查
for (const item of details) {
if (item.inspectionResult === 0) {
// 如果 inspectionResult 为 0,跳过此项的其他检查
continue;
} else if (item.inspectionResult === 1) {
// 如果 inspectionResult 为 1,检查 conclusion 和 photos
if (!item.conclusion || item.photos.length === 0) {
return false;
}
} else {
// 其他情况(理论上不应该存在,根据当前规则)
return false;
}
}
// 所有检查都通过
return true;
},
areAllInspectionResultsOne(details) {
let hasEmpty = false;
let allZero = true;
let hasOne = false;
for (const item of details) {
if (item.inspectionResult === "") {
hasEmpty = true;
break;
} else if (item.inspectionResult === 1) {
hasOne = true;
allZero = false;
} else if (item.inspectionResult === 0) {
// 继续检查
} else {
// 如果有其他值,可以在这里处理
allZero = false;
}
}
if (hasEmpty) {
return { statusLabel: "未巡检", status: 0 };
} else if (allZero) {
return { statusLabel: "已巡检", status: 1 };
} else if (hasOne) {
return { statusLabel: "巡检异常", status: 2 };
} else {
// 默认情况,可以根据需求调整
return { statusLabel: "未巡检", status: 0 };
}
},
setNormal() {
this.itemData.detail.forEach((item) => {
item.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;
}
}
.conclusion {
&.no-text {
color: #c7c7c7;
}
.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>
<template>
<view class="container-item">
<view class="title">{{ title }}</view>
<view class="cards">
<view
v-for="(item, index) in detailObj.detail"
:key="index"
class="cards-item"
v-if="showItem(item)"
>
<view v-if="hasLabel" class="name"
>{{ item.label
}}<text
class="status"
:class="{ warning: item.inspectionResult === 1 }"
>{{ item.inspectionResultLable }}</text
></view
>
<view class="list" v-if="type == 1">
<view class="label">{{ item.settingLabelShow }}</view>
<view class="content">
{{ item.setting }}
</view>
</view>
<view v-if="type == 2 && item.inspectionResult === 1" class="list">
<view class="label">故障设备:</view>
<view class="content">
<text v-for="(current, idx) in item.cabinets" :key="idx">
{{ current.deviceId }}机柜,{{ current.UpositonS }}~{{
current.UpositonE
}}U】
</text>
</view>
</view>
<template v-if="type == 3">
<view class="list" v-if="item.settingLabel">
<view class="label">{{ item.settingLabel }}</view>
<view class="content"> {{ item.setting }}{{ item.unit }} </view>
</view>
<view class="list" v-if="item.sjLabel">
<view class="label">{{ item.sjLabel }}</view>
<view class="content"> {{ item.value }}{{ item.unit }} </view>
</view>
</template>
<view class="name" v-if="type == 4">
<template v-if="index == 0">
<view>
{{ item.label }} (气压范围:{{ item.setting }}
<text
class="status"
:class="{ warning: item.inspectionResult === 1 }"
>{{ item.inspectionResultLable }}
</text>
</view>
</template>
<template v-else>
{{ item.label }}
<text
class="status"
:class="{ warning: item.inspectionResult === 1 }"
>{{ item.inspectionResultLable }}
</text>
</template>
</view>
<template v-if="type == 5">
<template v-if="item.required">
<view class="name"
>{{ item.label }}
<text
class="status"
:class="{ warning: item.inspectionResult === 1 }"
>{{ item.inspectionResultLable }}
</text>
</view>
<view class="list">
<view class="label">情况描述:</view>
<view class="content">
{{ item.conclusion }}
</view>
</view>
</template>
<view v-if="!item.required" class="list">
<view class="label">其它问题:</view>
<view class="content">
{{ item.conclusion }}
</view>
</view>
</template>
<view class="list" v-if="type != 5">
<view class="label">{{ "情况描述" }}:</view>
<view class="content">
{{ item.conclusion }}
</view>
</view>
<view class="list">
<view class="label">现场照片:</view>
<view v-if="item.photos.length === 0" class="content">
未拍摄照片
</view>
<view v-else class="content">
<image
v-for="(url, urlIndex) in item.photos"
:key="urlIndex"
class="image-item"
:src="url"
mode="aspectFit"
@click="previewImage(item.photos, urlIndex)"
></image>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
props: {
detailObj: {
type: Object,
default: () => ({}),
},
title: {
type: String,
default: "",
},
type: {
type: [String, Number],
default: "",
},
hasLabel: {
type: Boolean,
default: true,
},
isShowItem: {
type: Boolean,
default: false,
},
},
data() {
return {};
},
methods: {
showItem(item) {
if (!this.isShowItem) return true;
const hasMonitor = this.detailObj.detail.find(
(i) => i.label === "是否有监控",
);
if (hasMonitor && hasMonitor.inspectionResultLable === "无监控") {
return !["监控外观破损", "监控画面清晰", "监控存储连续"].includes(
item.label,
);
}
return true;
},
previewImage(images, index) {
uni.previewImage({
current: index,
urls: images,
});
},
},
};
</script>
<style scoped lang="less">
.container-item {
margin-bottom: 19.2px;
.title {
font-size: 12.8px;
color: #000000;
line-height: 19.2px;
font-weight: 500;
margin-bottom: 9.6px;
}
.cards {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
.cards-item {
width: calc(50% - 6.4px);
margin-bottom: 12.8px;
background: #f9f9f9;
border-radius: 6.4px;
padding: 6.4px;
&.sbgj {
width: 100%;
}
.name {
font-size: 12.8px;
color: #000000;
line-height: 19.2px;
font-weight: 500;
margin-bottom: 9.6px;
.status {
margin-left: 6.4px;
padding: 0 6.4px;
font-size: 9.6px;
background: #e6f9f3;
border-radius: 8.8px;
color: #0cc991;
line-height: 16px;
font-weight: 400;
&.warning {
background: #fdebe9;
color: #f55a42;
}
}
}
.list {
display: flex;
align-items: flex-start;
margin-bottom: 9.6px;
&:last-child {
margin-bottom: 0;
}
.label {
width: 56px;
font-size: 11.2px;
color: #7c7c7c;
line-height: 17.6px;
font-weight: 400;
}
.content {
flex: 1;
word-wrap: break-word;
font-size: 11.2px;
color: #000000;
line-height: 17.6px;
font-weight: 400;
display: flex;
flex-wrap: nowrap;
// justify-content: space-between;
.image-item {
width: 57.6px;
height: 57.6px;
margin-right: 6.4px;
border-radius: 3.2px;
}
}
}
}
}
}
</style>
......@@ -15,7 +15,7 @@
</view>
<!-- 关闭按钮 -->
<div class="close-button">
<div class="close-button" v-if="!startDialogData.isLast">
<text class="iconfont icon-shibai1" @click="close"></text>
</div>
</view>
......
差异被折叠。
差异被折叠。
差异被折叠。
<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.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>
</view>
<template v-if="item.inspectionResult === 1">
<view class="form-item">
<text class="form-label"
><text class="required">*</text>情况摘要</text
>
<text
:class="['conclusion', { 'no-text': !item.conclusion }]"
@click="showPopup(item, index)"
>
{{ item.conclusion || "请输入情况摘要" }}</text
>
</view>
<view class="form-item">
<text class="form-label"
><text class="required">*</text>现场照片</text
>
<CommonUpload v-model="item.photos" :max-count="5">
</CommonUpload> </view
></template> </view
><custom-popup
ref="customPopup"
:inspectionItem="inspectionItem"
@confirm="handlePopupConfirm"
></custom-popup>
</view>
</template>
<script>
import CommonUpload from "@/components/CommonUpload/index.vue";
import customPopup from "./customPopup.vue";
import _ from "lodash";
import mixin from "./mixin";
export default {
components: {
CommonUpload,
customPopup,
},
mixins: [mixin],
props: {
// 父组件传递的巡检状态
status: {
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: "",
inspectionResultLable: "正常",
lableArr: ["正常", "异常"],
conclusion: "",
photos: [],
},
],
},
};
},
computed: {
userInfo() {
return this.$store.state.now_user || {};
},
},
watch: {
defaultData(newVal) {
// 在这里处理数据变化
if (Object.keys(this.defaultData).length !== 0) {
this.itemData = this.defaultData;
}
},
},
async mounted() {
console.log("sdsadasd", 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);
},
// 处理弹窗确认
handlePopupConfirm(summary) {
this.itemData.detail[this.currentIndex].conclusion = summary; // 回显到文字显示区域
},
// 处理】数据
getFromData() {
const isValid = this.areAllObjectsValid(this.itemData.detail); //false不通过 true通过
console.log("wlhj", isValid);
const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail);
console.log("isAllOne", isAllOne);
this.itemData.isValid = isValid;
this.itemData.inspectionItem = this.inspectionItem;
this.itemData.status = isAllOne.status; //1表示已经巡检过没有异常
this.itemData.statusLabel = isAllOne.statusLabel;
console.log("查看数据", this.itemData);
return this.itemData;
},
// 数据校验方法 true说明有未填项
areAllObjectsValid(details) {
// 检查是否有任何项的 inspectionResult 为空字符串
const hasEmptyResult = details.some(
(item) => item.inspectionResult === "",
);
if (hasEmptyResult) {
return false;
}
// 遍历每一项进行检查
for (const item of details) {
if (item.inspectionResult === 0) {
// 如果 inspectionResult 为 0,跳过此项的其他检查
continue;
} else if (item.inspectionResult === 1) {
// 如果 inspectionResult 为 1,检查 conclusion 和 photos
if (!item.conclusion || item.photos.length === 0) {
return false;
}
} else {
// 其他情况(理论上不应该存在,根据当前规则)
return false;
}
}
// 所有检查都通过
return true;
},
areAllInspectionResultsOne(details) {
let hasEmpty = false;
let allZero = true;
let hasOne = false;
for (const item of details) {
if (item.inspectionResult === "") {
hasEmpty = true;
break;
} else if (item.inspectionResult === 1) {
hasOne = true;
allZero = false;
} else if (item.inspectionResult === 0) {
// 继续检查
} else {
// 如果有其他值,可以在这里处理
allZero = false;
}
}
if (hasEmpty) {
return { statusLabel: "未巡检", status: 0 };
} else if (allZero) {
return { statusLabel: "已巡检", status: 1 };
} else if (hasOne) {
return { statusLabel: "巡检异常", status: 2 };
} else {
// 默认情况,可以根据需求调整
return { statusLabel: "未巡检", status: 0 };
}
},
setNormal() {
this.itemData.detail.forEach((item) => {
item.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;
}
}
.conclusion {
&.no-text {
color: #c7c7c7;
}
.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>
<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.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>
</view>
<template v-if="item.inspectionResult === 1">
<view class="form-item">
<text class="form-label"
><text class="required">*</text>情况摘要</text
>
<text
:class="['conclusion', { 'no-text': !item.conclusion }]"
@click="showPopup(item, index)"
>
{{ item.conclusion || "请输入情况摘要" }}</text
>
</view>
<view class="form-item">
<text class="form-label"
><text class="required">*</text>现场照片</text
>
<CommonUpload v-model="item.photos" :max-count="5">
</CommonUpload> </view
></template> </view
><custom-popup
ref="customPopup"
:inspectionItem="inspectionItem"
@confirm="handlePopupConfirm"
></custom-popup>
</view>
</template>
<script>
import CommonUpload from "@/components/CommonUpload/index.vue";
import customPopup from "./customPopup.vue";
import _ from "lodash";
import mixin from "./mixin";
export default {
components: {
CommonUpload,
customPopup,
},
mixins: [mixin],
props: {
// 父组件传递的巡检状态
status: {
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: "",
inspectionResultLable: "正常",
lableArr: ["正常", "异常"],
conclusion: "",
photos: [],
},
],
},
};
},
computed: {
userInfo() {
return this.$store.state.now_user || {};
},
},
watch: {
defaultData(newVal) {
// 在这里处理数据变化
if (Object.keys(this.defaultData).length !== 0) {
this.itemData = this.defaultData;
}
},
},
async mounted() {
console.log("sdsadasd", 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);
},
// 处理弹窗确认
handlePopupConfirm(summary) {
this.itemData.detail[this.currentIndex].conclusion = summary; // 回显到文字显示区域
},
// 处理】数据
getFromData() {
const isValid = this.areAllObjectsValid(this.itemData.detail); //false不通过 true通过
console.log("wlhj", isValid);
const isAllOne = this.areAllInspectionResultsOne(this.itemData.detail);
console.log("isAllOne", isAllOne);
this.itemData.isValid = isValid;
this.itemData.inspectionItem = this.inspectionItem;
this.itemData.status = isAllOne.status; //1表示已经巡检过没有异常
this.itemData.statusLabel = isAllOne.statusLabel;
console.log("查看数据", this.itemData);
return this.itemData;
},
// 数据校验方法 true说明有未填项
areAllObjectsValid(details) {
// 检查是否有任何项的 inspectionResult 为空字符串
const hasEmptyResult = details.some(
(item) => item.inspectionResult === "",
);
if (hasEmptyResult) {
return false;
}
// 遍历每一项进行检查
for (const item of details) {
if (item.inspectionResult === 0) {
// 如果 inspectionResult 为 0,跳过此项的其他检查
continue;
} else if (item.inspectionResult === 1) {
// 如果 inspectionResult 为 1,检查 conclusion 和 photos
if (!item.conclusion || item.photos.length === 0) {
return false;
}
} else {
// 其他情况(理论上不应该存在,根据当前规则)
return false;
}
}
// 所有检查都通过
return true;
},
areAllInspectionResultsOne(details) {
let hasEmpty = false;
let allZero = true;
let hasOne = false;
for (const item of details) {
if (item.inspectionResult === "") {
hasEmpty = true;
break;
} else if (item.inspectionResult === 1) {
hasOne = true;
allZero = false;
} else if (item.inspectionResult === 0) {
// 继续检查
} else {
// 如果有其他值,可以在这里处理
allZero = false;
}
}
if (hasEmpty) {
return { statusLabel: "未巡检", status: 0 };
} else if (allZero) {
return { statusLabel: "已巡检", status: 1 };
} else if (hasOne) {
return { statusLabel: "巡检异常", status: 2 };
} else {
// 默认情况,可以根据需求调整
return { statusLabel: "未巡检", status: 0 };
}
},
setNormal() {
this.itemData.detail.forEach((item) => {
item.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;
}
}
.conclusion {
&.no-text {
color: #c7c7c7;
}
.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>
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论