|
|
|
// package/startInspection/startInspection.js
|
|
|
|
import { addPatrolRecord, getPatrolRecord } from "../../utils/getApiUrl";
|
|
|
|
import { Request } from "../../common";
|
|
|
|
const moment = require("../../utils/moment");
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
dataList: '',
|
|
|
|
imgs: [], //上传图片
|
|
|
|
imgUrl: getApp().globalData.imgUrl,
|
|
|
|
msgInp: '', //巡查详情
|
|
|
|
itemData: '', //单条数据
|
|
|
|
changeTwo: '', //是否异常
|
|
|
|
changeThree: '', //严重等级
|
|
|
|
},
|
|
|
|
|
|
|
|
handleChangeTwo(e) {
|
|
|
|
this.setData({
|
|
|
|
changeTwo: e.detail.value
|
|
|
|
})
|
|
|
|
if (e.detail.value == 'normal') {
|
|
|
|
this.setData({
|
|
|
|
msgInp: '', //巡查详情
|
|
|
|
changeThree: '', //严重等级
|
|
|
|
imgs: []
|
|
|
|
})
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleChangeThree(e) {
|
|
|
|
this.setData({
|
|
|
|
changeThree: e.detail.value
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
showModal(e) {
|
|
|
|
this.setData({
|
|
|
|
showModal: true,
|
|
|
|
itemData: e.currentTarget.dataset.itemdata
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
bindCancel() {
|
|
|
|
this.setData({
|
|
|
|
showModal: false,
|
|
|
|
itemData: '',
|
|
|
|
msgInp: '', //巡查详情
|
|
|
|
changeTwo: '', //是否异常
|
|
|
|
changeThree: '', //严重等级
|
|
|
|
imgs: []
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
// 上传图片
|
|
|
|
chooseImg: function (e) { //这里是选取图片的方法
|
|
|
|
var that = this;
|
|
|
|
var pics = [];
|
|
|
|
var detailPics = that.data.imgs;
|
|
|
|
if (detailPics.length >= 20) {
|
|
|
|
wx.showToast({
|
|
|
|
title: '最多选择20张图片上传',
|
|
|
|
icon: 'none'
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wx.chooseMedia({
|
|
|
|
count: 20, // 基础库2.25.0前,最多可支持9个文件,2.25.0及以后最多可支持20个文件
|
|
|
|
mediaType: ['image'], // 文件类型
|
|
|
|
sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
|
|
|
|
sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
|
|
|
|
success: function (res) {
|
|
|
|
var imgs = res.tempFiles;
|
|
|
|
for (var i = 0; i < imgs.length; i++) {
|
|
|
|
if (res.tempFiles[i].size > 15728640) {
|
|
|
|
commonJs.showToast('图片大于15M,不可上传');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pics.push(imgs[i].tempFilePath)
|
|
|
|
}
|
|
|
|
that.uploadimg({
|
|
|
|
url: getApp().globalData.webUrl + '_upload/attachments/project', //这里是你图片上传的接口
|
|
|
|
path: pics, //这里是选取的图片的地址数组
|
|
|
|
});
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
//多张图片上传
|
|
|
|
uploadimg: function (data) {
|
|
|
|
wx.showLoading({
|
|
|
|
title: '上传中...',
|
|
|
|
mask: true,
|
|
|
|
})
|
|
|
|
var that = this,
|
|
|
|
i = data.i ? data.i : 0,
|
|
|
|
success = data.success ? data.success : 0,
|
|
|
|
fail = data.fail ? data.fail : 0;
|
|
|
|
let imgs = that.data.imgs;
|
|
|
|
wx.uploadFile({
|
|
|
|
url: data.url,
|
|
|
|
filePath: data.path[i],
|
|
|
|
name: 'file',
|
|
|
|
success: (resp) => {
|
|
|
|
wx.hideLoading();
|
|
|
|
success++;
|
|
|
|
var str = JSON.parse(resp.data) //返回的结果,可能不同项目结果不一样
|
|
|
|
str = str.uploaded
|
|
|
|
console.log(str);
|
|
|
|
if (imgs.length >= 20) {
|
|
|
|
that.setData({
|
|
|
|
imgs: imgs
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
imgs.push(that.data.imgUrl + str);
|
|
|
|
that.setData({
|
|
|
|
imgs: imgs
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fail: (res) => {
|
|
|
|
fail++;
|
|
|
|
console.log('fail:' + i + "fail:" + fail);
|
|
|
|
},
|
|
|
|
complete: () => {
|
|
|
|
i++;
|
|
|
|
if (i == data.path.length) { //当图片传完时,停止调用
|
|
|
|
console.log('执行完毕');
|
|
|
|
console.log('成功:' + success + " 失败:" + fail);
|
|
|
|
} else { //若图片还没有传完,则继续调用函数
|
|
|
|
data.i = i;
|
|
|
|
data.success = success;
|
|
|
|
data.fail = fail;
|
|
|
|
that.uploadimg(data);//递归,回调自己
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// 删除图片
|
|
|
|
deleteImg: function (e) {
|
|
|
|
var imgs = this.data.imgs;
|
|
|
|
var index = e.currentTarget.dataset.index;
|
|
|
|
imgs.splice(index, 1);
|
|
|
|
this.setData({
|
|
|
|
imgs: imgs
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// 预览图片
|
|
|
|
previewImg: function (e) {
|
|
|
|
//获取当前图片的下标
|
|
|
|
var index = e.currentTarget.dataset.index;
|
|
|
|
//所有图片
|
|
|
|
var imgs = this.data.imgs;
|
|
|
|
wx.previewImage({
|
|
|
|
//当前显示图片
|
|
|
|
current: imgs[index],
|
|
|
|
//所有图片
|
|
|
|
urls: imgs
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
// 巡查详情
|
|
|
|
bindInput: function (e) {
|
|
|
|
this.setData({
|
|
|
|
msgInp: e.detail.value
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
// 开始巡检录入
|
|
|
|
addPatrolRecord: function () {
|
|
|
|
let that = this;
|
|
|
|
let { itemData, imgs, msgInp, changeTwo, changeThree, dataList, imgUrl } = that.data;
|
|
|
|
let newImgs = imgs.map(i => {
|
|
|
|
i = i.replace(imgUrl, '');
|
|
|
|
return i;
|
|
|
|
})
|
|
|
|
if (changeTwo == 'abnormal') {
|
|
|
|
if (msgInp == '') {
|
|
|
|
wx.showToast({
|
|
|
|
title: '请填写巡查详情',
|
|
|
|
icon: 'none'
|
|
|
|
})
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (changeThree == '') {
|
|
|
|
wx.showToast({
|
|
|
|
title: '请选择严重等级',
|
|
|
|
icon: 'none'
|
|
|
|
})
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let data = {
|
|
|
|
patrolPlanId: dataList.id,
|
|
|
|
lastInspectionTime: moment().format('YYYY-MM-DD'),
|
|
|
|
inspectionTime: moment().format('YYYY-MM-DD'),
|
|
|
|
points: {
|
|
|
|
user: dataList.user,
|
|
|
|
project: dataList.project,
|
|
|
|
frequency: dataList.frequency,
|
|
|
|
itemData: itemData,
|
|
|
|
msgInp: msgInp,
|
|
|
|
changeThree: changeThree == 'slight' ? '轻微' : changeThree == 'moderate' ? '中度' : '严重',
|
|
|
|
imgs: newImgs,
|
|
|
|
},
|
|
|
|
alarm: true
|
|
|
|
}
|
|
|
|
Request.post(addPatrolRecord(), data).then(res => {
|
|
|
|
wx.showToast({
|
|
|
|
title: '提交成功',
|
|
|
|
})
|
|
|
|
that.bindCancel();
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
if (changeTwo == 'normal') {
|
|
|
|
let data = {
|
|
|
|
patrolPlanId: dataList.id,
|
|
|
|
lastInspectionTime: moment().format('YYYY-MM-DD'),
|
|
|
|
inspectionTime: moment().format('YYYY-MM-DD'),
|
|
|
|
points: {
|
|
|
|
user: dataList.user,
|
|
|
|
project: dataList.project,
|
|
|
|
frequency: dataList.frequency,
|
|
|
|
itemData: itemData,
|
|
|
|
},
|
|
|
|
alarm: false
|
|
|
|
}
|
|
|
|
Request.post(addPatrolRecord(), data).then(res => {
|
|
|
|
wx.showToast({
|
|
|
|
title: '提交成功',
|
|
|
|
})
|
|
|
|
that.bindCancel();
|
|
|
|
})
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wx.showToast({
|
|
|
|
title: '提交信息不全,请检查',
|
|
|
|
icon: 'none'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// 获取巡检记录
|
|
|
|
getPatrolRecord: function () {
|
|
|
|
Request.get(getPatrolRecord(this.data.dataList.id)).then(res => {
|
|
|
|
console.log(res);
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
// selfLocation() {
|
|
|
|
// const self = this
|
|
|
|
// wx.showLoading({
|
|
|
|
// title: '定位中',
|
|
|
|
// mask: true,
|
|
|
|
// });
|
|
|
|
// wx.getLocation({
|
|
|
|
// type: 'gcj02',
|
|
|
|
// success: (res) => {
|
|
|
|
// let latitude, longitude;
|
|
|
|
// latitude = res.latitude.toString();
|
|
|
|
// longitude = res.longitude.toString();
|
|
|
|
// this.latitude = res.latitude
|
|
|
|
// this.longitude = res.longitude
|
|
|
|
// getGeocoder({ lat: latitude, long: longitude }).then(res => { // 获取详细信息的接口
|
|
|
|
// const data = res.data;
|
|
|
|
// self.userAddress.userAddressdetail = ''
|
|
|
|
// var params = {
|
|
|
|
// text: data.address
|
|
|
|
// }
|
|
|
|
// parseAddress(params).then(res => { // 粘贴详细信息的接口
|
|
|
|
// console.log(res)
|
|
|
|
// if (res.status == 200 && res.message == "success") {
|
|
|
|
// this.$forceUpdate(); // 定位后,界面没有反应,因此加上强制刷新
|
|
|
|
// this.userAddress.userAddressdetail = res.data.town + res.data.detail;
|
|
|
|
// this.$set(this.userAddress, 'selectAddress', parseInt(res.data.county_info.city_id));
|
|
|
|
// this.addressInfo[0] = res.data.province_info ? res.data.province_info : {};
|
|
|
|
// this.addressInfo[1] = res.data.city_info ? res.data.city_info : {};
|
|
|
|
// this.addressInfo[2] = res.data.county_info ? res.data.county_info : {};
|
|
|
|
// }
|
|
|
|
// }).catch(res => {
|
|
|
|
// console.log("没有地址信息")
|
|
|
|
// })
|
|
|
|
// wx.hideLoading();
|
|
|
|
// })
|
|
|
|
// },
|
|
|
|
// fail: (res) => {
|
|
|
|
// console.log(res)
|
|
|
|
// wx.hideLoading();
|
|
|
|
// wx.showToast({
|
|
|
|
// title: res.errMsg,
|
|
|
|
// icon: 'none',
|
|
|
|
// duration: 1000
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// },
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad(options) {
|
|
|
|
let that = this;
|
|
|
|
let data = JSON.parse(options.data);
|
|
|
|
let points = data.points.map(e => {
|
|
|
|
return e.name
|
|
|
|
}).join('、')
|
|
|
|
that.setData({
|
|
|
|
dataList: data,
|
|
|
|
points
|
|
|
|
})
|
|
|
|
// that.getPatrolRecord()
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
|
|
|
onReady() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
*/
|
|
|
|
onHide() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
*/
|
|
|
|
onUnload() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户点击右上角分享
|
|
|
|
*/
|
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|