|
|
@ -13,7 +13,7 @@ Page({ |
|
|
|
address: '', // 当前位置
|
|
|
|
imgUrl: getApp().globalData.imgUrl, |
|
|
|
checkItems: [], // 检查项
|
|
|
|
inspectContent: {}, // 巡检内容
|
|
|
|
inspectContentArr: [], // 巡检内容
|
|
|
|
isCommitting: false, |
|
|
|
/*** 扫码巡检 ***/ |
|
|
|
planList: null, // 巡检计划列表
|
|
|
@ -61,26 +61,46 @@ Page({ |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取巡检模板
|
|
|
|
getPatrolTemplate (templateId) { |
|
|
|
getPatrolTemplate(templateId, pointDevices = []) { |
|
|
|
Request.get(getPatrolTemplate(templateId)).then(res => { |
|
|
|
const checkItems = res.rows[0].checkItems; |
|
|
|
const inspectContent = {}; |
|
|
|
for (const c of checkItems) { |
|
|
|
inspectContent[c.name] = { |
|
|
|
isNormal: null, |
|
|
|
msgInp: null, |
|
|
|
level: null, |
|
|
|
imgs: [], |
|
|
|
}; |
|
|
|
let inspectContentArr = []; |
|
|
|
// 有绑定设备的点位,每个设备都要检查各个检查项
|
|
|
|
if (pointDevices.length) { |
|
|
|
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: null, |
|
|
|
msgInp: null, |
|
|
|
level: null, |
|
|
|
imgs: [], |
|
|
|
})) |
|
|
|
}) |
|
|
|
}); |
|
|
|
} else { |
|
|
|
inspectContentArr.push({ |
|
|
|
checkItems: checkItems.map(c => ({ |
|
|
|
id: c.id, |
|
|
|
name: c.name, |
|
|
|
isNormal: null, |
|
|
|
msgInp: null, |
|
|
|
level: null, |
|
|
|
imgs: [], |
|
|
|
})) |
|
|
|
}) |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
checkItems, |
|
|
|
inspectContent, |
|
|
|
inspectContentArr: inspectContentArr, |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
onPickerChange (e) { |
|
|
|
onPickerChange(e) { |
|
|
|
const { key } = e.currentTarget.dataset; |
|
|
|
const { value } = e.detail; |
|
|
|
this.setData({ |
|
|
@ -90,26 +110,27 @@ Page({ |
|
|
|
}); |
|
|
|
|
|
|
|
const curPlan = this.data.planList[e.detail.columns[0].index]; |
|
|
|
const nextItemData = curPlan.points.find(p => p.id == this.data.scenePointId) |
|
|
|
this.setData({ |
|
|
|
dataList: curPlan, |
|
|
|
itemData: curPlan.points.find(p => p.id == this.data.scenePointId) |
|
|
|
itemData: nextItemData |
|
|
|
}); |
|
|
|
this.getPatrolTemplate(curPlan.templateId); |
|
|
|
this.getPatrolTemplate(curPlan.templateId, nextItemData.pointDevices); |
|
|
|
}, |
|
|
|
|
|
|
|
onPickerCancel (e) { |
|
|
|
onPickerCancel(e) { |
|
|
|
const { key } = e.currentTarget.dataset; |
|
|
|
this.setData({ |
|
|
|
[`${key}Visible`]: false, |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
onPlanListPicker () { |
|
|
|
onPlanListPicker() { |
|
|
|
this.setData({ planListVisible: true }); |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取当前位置
|
|
|
|
selfLocation () { |
|
|
|
selfLocation() { |
|
|
|
const that = this |
|
|
|
wx.showLoading({ |
|
|
|
title: '定位中', |
|
|
@ -140,42 +161,43 @@ Page({ |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
handleChangeTwo (e) { |
|
|
|
handleChangeTwo(e) { |
|
|
|
const isNormal = e.detail === 'normal'; |
|
|
|
const inspectContent = this.data.inspectContent; |
|
|
|
inspectContent[e.currentTarget.dataset.item].isNormal = isNormal; |
|
|
|
const { deviceidx, itemidx } = e.currentTarget.dataset; |
|
|
|
let nextInspectContentArr = this.data.inspectContentArr; |
|
|
|
|
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].isNormal = isNormal; |
|
|
|
if (isNormal) { // 清除异常数据
|
|
|
|
inspectContent[e.currentTarget.dataset.item].msgInp = null; |
|
|
|
inspectContent[e.currentTarget.dataset.item].level = null; |
|
|
|
inspectContent[e.currentTarget.dataset.item].imgs = []; |
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].msgInp = null; |
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].level = null; |
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].imgs = []; |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
inspectContent, |
|
|
|
}) |
|
|
|
this.setData({ inspectContentArr: nextInspectContentArr }) |
|
|
|
}, |
|
|
|
|
|
|
|
handleChangeThree (e) { |
|
|
|
const inspectContent = this.data.inspectContent; |
|
|
|
inspectContent[e.currentTarget.dataset.item].level = e.detail; |
|
|
|
this.setData({ |
|
|
|
inspectContent |
|
|
|
}) |
|
|
|
handleChangeThree(e) { |
|
|
|
const { deviceidx, itemidx } = e.currentTarget.dataset; |
|
|
|
let nextInspectContentArr = this.data.inspectContentArr; |
|
|
|
|
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].level = e.detail; |
|
|
|
this.setData({ inspectContentArr: nextInspectContentArr }) |
|
|
|
}, |
|
|
|
|
|
|
|
// 巡查详情
|
|
|
|
bindInput: function (e) { |
|
|
|
const inspectContent = this.data.inspectContent; |
|
|
|
inspectContent[e.currentTarget.dataset.item].msgInp = e.detail.value; |
|
|
|
this.setData({ |
|
|
|
inspectContent |
|
|
|
}) |
|
|
|
const { deviceidx, itemidx } = e.currentTarget.dataset; |
|
|
|
let nextInspectContentArr = this.data.inspectContentArr; |
|
|
|
|
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].msgInp = e.detail.value; |
|
|
|
this.setData({ inspectContentArr: nextInspectContentArr }) |
|
|
|
}, |
|
|
|
|
|
|
|
// 上传图片
|
|
|
|
chooseImg: function (e) { // 这里是选取图片的方法
|
|
|
|
const { deviceidx, itemidx } = e.currentTarget.dataset; |
|
|
|
const that = this; |
|
|
|
let pics = []; |
|
|
|
const detailPics = that.data.inspectContent[e.currentTarget.dataset.item].imgs; |
|
|
|
const detailPics = that.data.inspectContentArr[deviceidx].checkItems[itemidx].imgs; |
|
|
|
if (detailPics.length >= 20) { |
|
|
|
wx.showToast({ |
|
|
|
title: '最多选择20张图片上传', |
|
|
@ -203,16 +225,16 @@ Page({ |
|
|
|
} |
|
|
|
pics.push(imgs[i].tempFilePath) |
|
|
|
} |
|
|
|
that.uploadimg({ |
|
|
|
that.uploadImg({ |
|
|
|
url: getApp().globalData.webUrl + '_upload/attachments/project', // 图片上传的接口
|
|
|
|
path: pics, // 选取的图片的地址数组
|
|
|
|
}, e.currentTarget.dataset.item); |
|
|
|
}, deviceidx, itemidx); |
|
|
|
}, |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
//多张图片上传
|
|
|
|
uploadimg: function (data, itemName) { |
|
|
|
uploadImg: function (data, deviceidx, itemidx) { |
|
|
|
wx.showLoading({ |
|
|
|
title: '上传中...', |
|
|
|
mask: true, |
|
|
@ -221,7 +243,7 @@ Page({ |
|
|
|
i = data.i ? data.i : 0, |
|
|
|
success = data.success ? data.success : 0, |
|
|
|
fail = data.fail ? data.fail : 0; |
|
|
|
let imgs = that.data.inspectContent[itemName].imgs; |
|
|
|
let imgs = that.data.inspectContentArr[deviceidx].checkItems[itemidx].imgs; |
|
|
|
wx.uploadFile({ |
|
|
|
url: data.url, |
|
|
|
filePath: data.path[i], |
|
|
@ -232,19 +254,15 @@ Page({ |
|
|
|
let str = JSON.parse(resp.data) // 返回的结果,可能不同项目结果不一样
|
|
|
|
str = str.uploaded |
|
|
|
if (imgs.length >= 20) { |
|
|
|
const inspectContent = that.data.inspectContent; |
|
|
|
inspectContent[itemName].imgs = imgs; |
|
|
|
that.setData({ |
|
|
|
inspectContent, |
|
|
|
}); |
|
|
|
let nextInspectContentArr = that.data.inspectContentArr; |
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].imgs = imgs; |
|
|
|
that.setData({ inspectContentArr: nextInspectContentArr }); |
|
|
|
return false; |
|
|
|
} else { |
|
|
|
imgs.push(str); |
|
|
|
const inspectContent = that.data.inspectContent; |
|
|
|
inspectContent[itemName].imgs = imgs; |
|
|
|
that.setData({ |
|
|
|
inspectContent, |
|
|
|
}) |
|
|
|
let nextInspectContentArr = that.data.inspectContentArr; |
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].imgs = imgs; |
|
|
|
that.setData({ inspectContentArr: nextInspectContentArr }); |
|
|
|
} |
|
|
|
}, |
|
|
|
fail: (res) => { |
|
|
@ -260,7 +278,7 @@ Page({ |
|
|
|
data.i = i; |
|
|
|
data.success = success; |
|
|
|
data.fail = fail; |
|
|
|
that.uploadimg(data, itemName); // 递归,回调自己
|
|
|
|
that.uploadImg(data, deviceidx, itemidx); // 递归,回调自己
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
@ -268,22 +286,19 @@ Page({ |
|
|
|
|
|
|
|
// 删除图片
|
|
|
|
deleteImg: function (e) { |
|
|
|
let imgs = this.data.inspectContent[e.currentTarget.dataset.item].imgs; |
|
|
|
const index = e.currentTarget.dataset.index; |
|
|
|
const { deviceidx, itemidx, index } = e.currentTarget.dataset; |
|
|
|
let imgs = this.data.inspectContentArr[deviceidx].checkItems[itemidx].imgs; |
|
|
|
imgs.splice(index, 1); |
|
|
|
const inspectContent = this.data.inspectContent; |
|
|
|
inspectContent[e.currentTarget.dataset.item].imgs = imgs; |
|
|
|
this.setData({ |
|
|
|
inspectContent |
|
|
|
}); |
|
|
|
let nextInspectContentArr = this.data.inspectContentArr; |
|
|
|
nextInspectContentArr[deviceidx].checkItems[itemidx].imgs = imgs; |
|
|
|
this.setData({ inspectContentArr: nextInspectContentArr }) |
|
|
|
}, |
|
|
|
|
|
|
|
// 预览图片
|
|
|
|
previewImg: function (e) { |
|
|
|
// 获取当前图片的下标
|
|
|
|
const index = e.currentTarget.dataset.index; |
|
|
|
const { deviceidx, itemidx, index } = e.currentTarget.dataset; |
|
|
|
// 所有图片
|
|
|
|
const imgs = this.data.inspectContent[e.currentTarget.dataset.item].imgs; |
|
|
|
const imgs = this.data.inspectContentArr[deviceidx].checkItems[itemidx].imgs; |
|
|
|
const newImgs = imgs.map(i => this.data.imgUrl + i); |
|
|
|
wx.previewImage({ |
|
|
|
// 当前显示图片
|
|
|
@ -293,7 +308,7 @@ Page({ |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
bindCancel () { |
|
|
|
bindCancel() { |
|
|
|
if (this.data.scenePointId) { |
|
|
|
wx.switchTab({ url: '/pages/index/index' }) |
|
|
|
} else { |
|
|
@ -307,12 +322,11 @@ Page({ |
|
|
|
if (that.data.isCommitting) { return } |
|
|
|
let { |
|
|
|
itemData, |
|
|
|
inspectContent, |
|
|
|
inspectContentArr, |
|
|
|
dataList, |
|
|
|
address |
|
|
|
} = that.data; |
|
|
|
let alarm = false; |
|
|
|
|
|
|
|
if (!address) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请获取当前位置', |
|
|
@ -321,26 +335,29 @@ Page({ |
|
|
|
}) |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
for (const item in inspectContent) { |
|
|
|
if (inspectContent[item].isNormal === null) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请填写完整', |
|
|
|
icon: 'none', |
|
|
|
duration: 1500 |
|
|
|
}) |
|
|
|
return; |
|
|
|
} |
|
|
|
if ((!inspectContent[item].isNormal) && (!inspectContent[item].level || !inspectContent[item].msgInp)) { |
|
|
|
wx.showToast({ |
|
|
|
title: '异常项必须输入巡查详情和选择严重等级', |
|
|
|
icon: 'none', |
|
|
|
duration: 2000 |
|
|
|
}) |
|
|
|
return; |
|
|
|
} |
|
|
|
if (inspectContent[item].isNormal === false) { |
|
|
|
alarm = true; |
|
|
|
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) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请填写完整', |
|
|
|
icon: 'none', |
|
|
|
duration: 1500 |
|
|
|
}) |
|
|
|
return; |
|
|
|
} |
|
|
|
if ((!item.isNormal) && (!item.level || !item.msgInp)) { |
|
|
|
wx.showToast({ |
|
|
|
title: '异常项必须输入巡查详情和选择严重等级', |
|
|
|
icon: 'none', |
|
|
|
duration: 2000 |
|
|
|
}) |
|
|
|
return; |
|
|
|
} |
|
|
|
if (item.isNormal === false) { |
|
|
|
alarm = true; // 巡检记录异常
|
|
|
|
reportArr[index].alarm = true; // 设备异常
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const { id, name, departmentId, deptName } = wx.getStorageSync('userInfo'); |
|
|
@ -353,7 +370,7 @@ Page({ |
|
|
|
project: dataList.project, |
|
|
|
frequency: dataList.frequency, |
|
|
|
itemData: itemData, |
|
|
|
inspectContent, |
|
|
|
inspectContent: reportArr, |
|
|
|
address: address |
|
|
|
}, |
|
|
|
alarm, |
|
|
@ -377,7 +394,7 @@ Page({ |
|
|
|
/** |
|
|
|
* 生命周期函数--监听页面加载 |
|
|
|
*/ |
|
|
|
onLoad (options) { |
|
|
|
onLoad(options) { |
|
|
|
const that = this; |
|
|
|
const scenePointId = options.scene; |
|
|
|
if (scenePointId) { // 扫小程序码进入
|
|
|
@ -398,56 +415,56 @@ Page({ |
|
|
|
dataList, |
|
|
|
itemData |
|
|
|
}) |
|
|
|
that.getPatrolTemplate(dataList.templateId); |
|
|
|
that.getPatrolTemplate(dataList.templateId, itemData.pointDevices); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 生命周期函数--监听页面初次渲染完成 |
|
|
|
*/ |
|
|
|
onReady () { |
|
|
|
onReady() { |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 生命周期函数--监听页面显示 |
|
|
|
*/ |
|
|
|
onShow () { |
|
|
|
onShow() { |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 生命周期函数--监听页面隐藏 |
|
|
|
*/ |
|
|
|
onHide () { |
|
|
|
onHide() { |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 生命周期函数--监听页面卸载 |
|
|
|
*/ |
|
|
|
onUnload () { |
|
|
|
onUnload() { |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 页面相关事件处理函数--监听用户下拉动作 |
|
|
|
*/ |
|
|
|
onPullDownRefresh () { |
|
|
|
onPullDownRefresh() { |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 页面上拉触底事件的处理函数 |
|
|
|
*/ |
|
|
|
onReachBottom () { |
|
|
|
onReachBottom() { |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 用户点击右上角分享 |
|
|
|
*/ |
|
|
|
onShareAppMessage () { |
|
|
|
onShareAppMessage() { |
|
|
|
|
|
|
|
} |
|
|
|
}) |