|
|
@ -1,6 +1,12 @@ |
|
|
|
// package/inspectionInput/inspectionInput.js
|
|
|
|
import { addPatrolRecord, getPatrolTemplate, getPatrolPlan } from "../../utils/getApiUrl"; |
|
|
|
import { Request } from "../../common"; |
|
|
|
import { |
|
|
|
addPatrolRecord, |
|
|
|
getPatrolTemplate, |
|
|
|
getPatrolPlan |
|
|
|
} from "../../utils/getApiUrl"; |
|
|
|
import { |
|
|
|
Request |
|
|
|
} from "../../common"; |
|
|
|
const moment = require("../../utils/moment"); |
|
|
|
|
|
|
|
Page({ |
|
|
@ -14,11 +20,14 @@ Page({ |
|
|
|
imgUrl: getApp().globalData.imgUrl, |
|
|
|
checkItems: [], // 检查项
|
|
|
|
inspectContentArr: [], // 巡检内容
|
|
|
|
inspectContentArrCopy:[],//保持源数据结构的巡检内容数组
|
|
|
|
isCommitting: false, |
|
|
|
/*** 扫码巡检 ***/ |
|
|
|
planList: null, // 巡检计划列表
|
|
|
|
planListVisible: true, |
|
|
|
scenePointId: null, // 当前点位id
|
|
|
|
devicesChecked: [], //设备复选框
|
|
|
|
pointDevices:[], |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取巡检计划
|
|
|
@ -28,7 +37,9 @@ Page({ |
|
|
|
title: '加载中', |
|
|
|
}) |
|
|
|
const userInfo = wx.getStorageSync('userInfo'); |
|
|
|
Request.get(getPatrolPlan(), { userId: userInfo.id }).then(res => { |
|
|
|
Request.get(getPatrolPlan(), { |
|
|
|
userId: userInfo.id |
|
|
|
}).then(res => { |
|
|
|
wx.hideLoading(); |
|
|
|
let pointPlan = res.rows.filter(plan => { |
|
|
|
for (const point of plan.points) { |
|
|
@ -65,10 +76,27 @@ Page({ |
|
|
|
Request.get(getPatrolTemplate(templateId)).then(res => { |
|
|
|
const checkItems = res.rows[0].checkItems; |
|
|
|
let inspectContentArr = []; |
|
|
|
let inspectContentArrCopy = []; |
|
|
|
// 有绑定设备的点位,每个设备都要检查各个检查项
|
|
|
|
if (pointDevices.length) { |
|
|
|
pointDevices.forEach(device => { |
|
|
|
//渲染数组
|
|
|
|
checkItems.forEach(c => { |
|
|
|
inspectContentArr.push({ |
|
|
|
id: `${c.id}`, |
|
|
|
name: c.name, |
|
|
|
isNormal: true, |
|
|
|
imgs: [], |
|
|
|
msgInp: null, |
|
|
|
level: null, |
|
|
|
devices: pointDevices.map(device => ({ |
|
|
|
deviceName: device?.device?.name, |
|
|
|
deviceId: device.deviceId, |
|
|
|
id: `${device.deviceId}-${c.id}` |
|
|
|
})) |
|
|
|
}) |
|
|
|
}) |
|
|
|
pointDevices.forEach(device => { |
|
|
|
inspectContentArrCopy.push({ |
|
|
|
deviceName: device?.device?.name, |
|
|
|
deviceId: device.deviceId, |
|
|
|
checkItems: checkItems.map(c => ({ |
|
|
@ -81,28 +109,48 @@ Page({ |
|
|
|
})) |
|
|
|
}) |
|
|
|
}); |
|
|
|
// pointDevices.forEach(device => {
|
|
|
|
// inspectContentArr.push({
|
|
|
|
// deviceName: device?.device?.name,
|
|
|
|
// deviceId: device.deviceId,
|
|
|
|
// checkItems: checkItems.map(c => ({
|
|
|
|
// id: `${device.deviceId}-${c.id}`,
|
|
|
|
// name: c.name,
|
|
|
|
// isNormal: true,
|
|
|
|
// msgInp: null,
|
|
|
|
// level: null,
|
|
|
|
// imgs: [],
|
|
|
|
// }))
|
|
|
|
// })
|
|
|
|
// });
|
|
|
|
} else { |
|
|
|
checkItems.forEach(c => { |
|
|
|
inspectContentArr.push({ |
|
|
|
checkItems: checkItems.map(c => ({ |
|
|
|
id: c.id, |
|
|
|
name: c.name, |
|
|
|
isNormal: true, |
|
|
|
msgInp: null, |
|
|
|
level: null, |
|
|
|
imgs: [], |
|
|
|
})) |
|
|
|
}) |
|
|
|
})}) |
|
|
|
|
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
checkItems, |
|
|
|
inspectContentArr: inspectContentArr, |
|
|
|
inspectContentArrCopy:inspectContentArrCopy, |
|
|
|
pointDevices:pointDevices |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
onPickerChange(e) { |
|
|
|
const { key } = e.currentTarget.dataset; |
|
|
|
const { value } = e.detail; |
|
|
|
const { |
|
|
|
key |
|
|
|
} = e.currentTarget.dataset; |
|
|
|
const { |
|
|
|
value |
|
|
|
} = e.detail; |
|
|
|
this.setData({ |
|
|
|
[`${key}Visible`]: false, |
|
|
|
[`${key}Value`]: value, |
|
|
@ -119,14 +167,18 @@ Page({ |
|
|
|
}, |
|
|
|
|
|
|
|
onPickerCancel(e) { |
|
|
|
const { key } = e.currentTarget.dataset; |
|
|
|
const { |
|
|
|
key |
|
|
|
} = e.currentTarget.dataset; |
|
|
|
this.setData({ |
|
|
|
[`${key}Visible`]: false, |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
onPlanListPicker() { |
|
|
|
this.setData({ planListVisible: true }); |
|
|
|
this.setData({ |
|
|
|
planListVisible: true |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取当前位置
|
|
|
@ -170,7 +222,9 @@ Page({ |
|
|
|
confirmText: '去设置', |
|
|
|
content: '请允许位置权限', |
|
|
|
success: function (res) { |
|
|
|
const { confirm } = res || {} |
|
|
|
const { |
|
|
|
confirm |
|
|
|
} = res || {} |
|
|
|
if (confirm) { |
|
|
|
wx.openSetting() |
|
|
|
} |
|
|
@ -179,41 +233,61 @@ Page({ |
|
|
|
}, |
|
|
|
|
|
|
|
handleChangeTwo(e) { |
|
|
|
const { deviceidx, itemidx } = e.currentTarget.dataset; |
|
|
|
const {itemidx} = e.currentTarget.dataset |
|
|
|
let nextInspectContentArr = this.data.inspectContentArr; |
|
|
|
|
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].isNormal = e.detail; |
|
|
|
// nextInspectContentArr.forEach(e=>{
|
|
|
|
// const r=devicesChecked.find(i=>i?.join('-')==e.)
|
|
|
|
// e.isNormal=
|
|
|
|
// })
|
|
|
|
nextInspectContentArr[itemidx].isNormal = e.detail; |
|
|
|
if (e.detail) { // 清除异常数据
|
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].msgInp = null; |
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].level = null; |
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].imgs = []; |
|
|
|
nextInspectContentArr[itemidx].msgInp = null; |
|
|
|
nextInspectContentArr[itemidx].level = null; |
|
|
|
nextInspectContentArr[itemidx].imgs = []; |
|
|
|
this.setData({ |
|
|
|
devicesChecked: [] |
|
|
|
}) |
|
|
|
} |
|
|
|
this.setData({ inspectContentArr: nextInspectContentArr }) |
|
|
|
this.setData({ |
|
|
|
inspectContentArr: nextInspectContentArr |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
handleChangeThree(e) { |
|
|
|
const { deviceidx, itemidx } = e.currentTarget.dataset; |
|
|
|
let nextInspectContentArr = this.data.inspectContentArr; |
|
|
|
handleChangeDevice(e) { |
|
|
|
this.setData({ |
|
|
|
devicesChecked: e.detail |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].level = e.detail; |
|
|
|
this.setData({ inspectContentArr: nextInspectContentArr }) |
|
|
|
handleChangeThree(e) { |
|
|
|
const { itemidx } = e.currentTarget.dataset; |
|
|
|
let nextInspectContentArr = this.data.inspectContentArr |
|
|
|
nextInspectContentArr[itemidx].level= e.detail |
|
|
|
this.setData({ |
|
|
|
inspectContentArr: nextInspectContentArr |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 巡查详情
|
|
|
|
bindInput: function (e) { |
|
|
|
const {deviceidx,itemidx} = e.currentTarget.dataset; |
|
|
|
let nextInspectContentArr = this.data.inspectContentArr; |
|
|
|
|
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].msgInp = e.detail.value; |
|
|
|
this.setData({ inspectContentArr: nextInspectContentArr }) |
|
|
|
let nextInspectContentArr = this.data.inspectContentArr |
|
|
|
nextInspectContentArr[itemidx].msgInp= e.detail.value |
|
|
|
this.setData({ |
|
|
|
inspectContentArr: nextInspectContentArr |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 上传图片
|
|
|
|
chooseImg: function (e) { // 这里是选取图片的方法
|
|
|
|
const { deviceidx, itemidx } = e.currentTarget.dataset; |
|
|
|
const { |
|
|
|
deviceidx, |
|
|
|
itemidx |
|
|
|
} = e.currentTarget.dataset; |
|
|
|
const that = this; |
|
|
|
let pics = []; |
|
|
|
const detailPics = that.data.inspectContentArr[deviceidx].checkItems[itemidx].imgs; |
|
|
|
const detailPics = that.data.inspectContentArr[itemidx].imgs; |
|
|
|
if (detailPics.length >= 20) { |
|
|
|
wx.showToast({ |
|
|
|
title: '最多选择20张图片上传', |
|
|
@ -230,13 +304,19 @@ Page({ |
|
|
|
const imgs = res.tempFiles; |
|
|
|
for (let i = 0; i < imgs.length; i++) { |
|
|
|
if (res.tempFiles[i].size > 15728640) { |
|
|
|
wx.showToast({ title: '图片大于15M,不可上传', icon: 'none' }); |
|
|
|
wx.showToast({ |
|
|
|
title: '图片大于15M,不可上传', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
const fileNameArr = res.tempFiles[i].tempFilePath.split('.'); |
|
|
|
const extension = res.tempFiles[i].tempFilePath.split('.')[fileNameArr.length - 1]; |
|
|
|
if (extension !== 'jpg' && extension !== 'png' && extension !== 'jpeg') { |
|
|
|
wx.showToast({ title: '只能上传jpg、jpeg、png格式的图片', icon: 'none' }); |
|
|
|
wx.showToast({ |
|
|
|
title: '只能上传jpg、jpeg、png格式的图片', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
pics.push(imgs[i].tempFilePath) |
|
|
@ -259,7 +339,7 @@ Page({ |
|
|
|
i = data.i ? data.i : 0, |
|
|
|
success = data.success ? data.success : 0, |
|
|
|
fail = data.fail ? data.fail : 0; |
|
|
|
let imgs = that.data.inspectContentArr[deviceidx].checkItems[itemidx].imgs; |
|
|
|
let imgs = that.data.inspectContentArr[itemidx].imgs; |
|
|
|
wx.uploadFile({ |
|
|
|
url: data.url, |
|
|
|
filePath: data.path[i], |
|
|
@ -270,15 +350,15 @@ Page({ |
|
|
|
let str = JSON.parse(resp.data) // 返回的结果,可能不同项目结果不一样
|
|
|
|
str = str.uploaded |
|
|
|
if (imgs.length >= 20) { |
|
|
|
let nextInspectContentArr = that.data.inspectContentArr; |
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].imgs = imgs; |
|
|
|
let nextInspectContentArr = that.data.inspectContentArr |
|
|
|
nextInspectContentArr[itemidx].imgs = imgs; |
|
|
|
that.setData({ inspectContentArr: nextInspectContentArr }); |
|
|
|
return false; |
|
|
|
} else { |
|
|
|
imgs.push(str); |
|
|
|
let nextInspectContentArr = that.data.inspectContentArr; |
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].imgs = imgs; |
|
|
|
that.setData({ inspectContentArr: nextInspectContentArr }); |
|
|
|
let nextInspectContentArr = that.data.inspectContentArr |
|
|
|
nextInspectContentArr[itemidx].imgs = imgs |
|
|
|
that.setData({ inspectContentArr: nextInspectContentArr }) |
|
|
|
} |
|
|
|
}, |
|
|
|
fail: (res) => { |
|
|
@ -302,19 +382,28 @@ Page({ |
|
|
|
|
|
|
|
// 删除图片
|
|
|
|
deleteImg: function (e) { |
|
|
|
const { deviceidx, itemidx, index } = e.currentTarget.dataset; |
|
|
|
let imgs = this.data.inspectContentArr[deviceidx].checkItems[itemidx].imgs; |
|
|
|
const { |
|
|
|
itemidx, |
|
|
|
index |
|
|
|
} = e.currentTarget.dataset; |
|
|
|
let imgs = this.data.inspectContentArr[itemidx].imgs; |
|
|
|
imgs.splice(index, 1); |
|
|
|
let nextInspectContentArr = this.data.inspectContentArr; |
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].imgs = imgs; |
|
|
|
this.setData({ inspectContentArr: nextInspectContentArr }) |
|
|
|
nextInspectContentArr[itemidx].imgs = imgs; |
|
|
|
this.setData({ |
|
|
|
inspectContentArr: nextInspectContentArr |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 预览图片
|
|
|
|
previewImg: function (e) { |
|
|
|
const { deviceidx, itemidx, index } = e.currentTarget.dataset; |
|
|
|
const { |
|
|
|
deviceidx, |
|
|
|
itemidx, |
|
|
|
index |
|
|
|
} = e.currentTarget.dataset; |
|
|
|
// 所有图片
|
|
|
|
const imgs = this.data.inspectContentArr[deviceidx].checkItems[itemidx].imgs; |
|
|
|
const imgs = this.data.inspectContentArr[itemidx].imgs; |
|
|
|
const newImgs = imgs.map(i => this.data.imgUrl + i); |
|
|
|
wx.previewImage({ |
|
|
|
// 当前显示图片
|
|
|
@ -326,7 +415,9 @@ Page({ |
|
|
|
|
|
|
|
bindCancel() { |
|
|
|
if (this.data.scenePointId) { |
|
|
|
wx.switchTab({ url: '/pages/index/index' }) |
|
|
|
wx.switchTab({ |
|
|
|
url: '/pages/index/index' |
|
|
|
}) |
|
|
|
} else { |
|
|
|
wx.navigateBack(); |
|
|
|
} |
|
|
@ -335,13 +426,11 @@ Page({ |
|
|
|
// 开始巡检录入
|
|
|
|
addPatrolRecord: function () { |
|
|
|
const that = this; |
|
|
|
if (that.data.isCommitting) { return } |
|
|
|
let { |
|
|
|
itemData, |
|
|
|
inspectContentArr, |
|
|
|
dataList, |
|
|
|
address |
|
|
|
} = that.data; |
|
|
|
if (that.data.isCommitting) { |
|
|
|
return |
|
|
|
} |
|
|
|
let {itemData, inspectContentArrCopy, inspectContentArr, dataList,address,devicesChecked,pointDevices } = that.data; |
|
|
|
|
|
|
|
let alarm = false; |
|
|
|
// if (!address) {
|
|
|
|
// wx.showToast({
|
|
|
@ -351,10 +440,40 @@ Page({ |
|
|
|
// })
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
let reportArr = inspectContentArr.map(d => ({ ...d, alarm: false })); |
|
|
|
for (const [index, device] of inspectContentArr.entries()) { |
|
|
|
for (const item of device.checkItems) { |
|
|
|
if (item.isNormal === null) { |
|
|
|
let reportArr =[] |
|
|
|
if(pointDevices.length){ |
|
|
|
reportArr=inspectContentArrCopy.map(d => { |
|
|
|
const r=devicesChecked.find(j=>j?.split('-')[0]==d.deviceId) |
|
|
|
return { |
|
|
|
...d, |
|
|
|
checkItems:d.checkItems.map(i=>{ |
|
|
|
const cp=d.deviceId+'-'+i.id.split('-')[1] |
|
|
|
const isExist=devicesChecked.some(l=>l==cp) |
|
|
|
const rlst=inspectContentArr.find(q=>q.id==i.id.split('-')[1]) |
|
|
|
return { |
|
|
|
isNormal:isExist?rlst?.isNormal:true, |
|
|
|
level:isExist?rlst?.level:null, |
|
|
|
msgInp:isExist?rlst?.msgInp:null, |
|
|
|
imgs:isExist?rlst?.imgs:[], |
|
|
|
name:i.name, |
|
|
|
id:i.id |
|
|
|
} |
|
|
|
|
|
|
|
}), |
|
|
|
alarm: r?true:false |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
}else{ |
|
|
|
reportArr = [{ |
|
|
|
checkItems:inspectContentArr, |
|
|
|
alarm:false |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
|
|
|
|
for (const [index, checkItems] of inspectContentArr.entries()) { |
|
|
|
if (checkItems.isNormal === null) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请填写完整', |
|
|
|
icon: 'none', |
|
|
@ -362,7 +481,17 @@ Page({ |
|
|
|
}) |
|
|
|
return; |
|
|
|
} |
|
|
|
if ((!item.isNormal) && (!item.level || !item.msgInp)) { |
|
|
|
if(checkItems.devices){ |
|
|
|
if(!checkItems.isNormal&&devicesChecked&&devicesChecked.length==0){ |
|
|
|
wx.showToast({ |
|
|
|
title: '选择了检查项异常,但未选择具体设备', |
|
|
|
icon: 'none', |
|
|
|
duration: 1500 |
|
|
|
}) |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if ((!checkItems.isNormal) && (!checkItems.level || !checkItems.msgInp)) { |
|
|
|
wx.showToast({ |
|
|
|
title: '异常项必须输入巡查详情和选择严重等级', |
|
|
|
icon: 'none', |
|
|
@ -370,19 +499,18 @@ Page({ |
|
|
|
}) |
|
|
|
return; |
|
|
|
} |
|
|
|
if (item.isNormal === false) { |
|
|
|
if (checkItems.isNormal === false) { |
|
|
|
alarm = true; // 巡检记录异常
|
|
|
|
reportArr[index].alarm = true; // 设备异常
|
|
|
|
} |
|
|
|
// reportArr[index].alarm = true; // 设备异常
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const { id, name,departmentId, deptName } = wx.getStorageSync('userInfo'); |
|
|
|
let data = { |
|
|
|
patrolPlanId: dataList.id, |
|
|
|
pointId: itemData.id, |
|
|
|
inspectionTime: moment().format('YYYY-MM-DD HH:mm:ss'), |
|
|
|
points: { |
|
|
|
user: { id, name, department: { id: departmentId, name: deptName } }, |
|
|
|
points: { user: { id, name, department: { id: departmentId, name: deptName }}, |
|
|
|
project: dataList.project, |
|
|
|
frequency: dataList.frequency, |
|
|
|
itemData: itemData, |
|
|
@ -392,11 +520,17 @@ Page({ |
|
|
|
alarm, |
|
|
|
projectId: dataList.project.id |
|
|
|
} |
|
|
|
wx.showLoading({ title: '提交中...' }); |
|
|
|
that.setData({ isCommitting: true }); |
|
|
|
wx.showLoading({ |
|
|
|
title: '提交中...' |
|
|
|
}); |
|
|
|
that.setData({ |
|
|
|
isCommitting: true |
|
|
|
}); |
|
|
|
Request.post(addPatrolRecord(), data).then(res => { |
|
|
|
wx.hideLoading(); |
|
|
|
that.setData({ isCommitting: false }); |
|
|
|
that.setData({ |
|
|
|
isCommitting: false |
|
|
|
}); |
|
|
|
wx.showToast({ |
|
|
|
title: '提交成功', |
|
|
|
icon: 'success' |
|
|
@ -412,18 +546,21 @@ Page({ |
|
|
|
*/ |
|
|
|
onLoad(options) { |
|
|
|
const that = this; |
|
|
|
// console.log('inspectContentArr',inspectContentArr)
|
|
|
|
const scenePointId = options.scene; |
|
|
|
if (scenePointId) { // 扫小程序码进入
|
|
|
|
const userInfo = wx.getStorageSync('userInfo'); |
|
|
|
if (!userInfo || !userInfo.id) { // 如果没登录,先登录
|
|
|
|
wx.showToast({ title: '请先登录' }) |
|
|
|
wx.showToast({ |
|
|
|
title: '请先登录' |
|
|
|
}) |
|
|
|
wx.reLaunch({ |
|
|
|
url: `/pages/login/login?scene=${scenePointId}` |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
that.setData({ scenePointId }); |
|
|
|
that.setData({ |
|
|
|
scenePointId |
|
|
|
}); |
|
|
|
that.getPatrolPlan(scenePointId); |
|
|
|
} else { // 正常点击进入
|
|
|
|
const dataList = JSON.parse(decodeURIComponent(options.dataList)); |
|
|
@ -485,3 +622,5 @@ Page({ |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|