epmet 工作端 小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

408 lines
11 KiB

import api from "../../../../utils/request";
import { formatDate,dateTimePicker, getMonthDay, getNewDateArry, getLoopArray } from "../../../../utils/util"
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
pageType: 'mine',
gridName: '',
patrolInfo: {
staffPatrolRecId: '',
latestSerialNum: '',
status: '',
gridName: '',
patrolStartTime: '',
gridId: '',
carmDown: ''
},
patrolStatus: 'patrolling',
showBot: false,
gridId: '',
staffId: '',
staffName: '',
patrolDate: '',
timePicker: [
// "2021-05-01",
// "2021-05-03",
// "2021-05-04"
],
recordList: [
// {
// "staffPatrolRecId": "54902",
// "totalTimeDesc": "1小时02分",
// "patrolStartTime": "1622713164908",
// "patrolEndTime": "1622712593237",
// "status": "",
// "latestChangeDesc": "DUAThkxkNN",
// isOpen: false,
// "details": [
// {
// "uploadTime": "1623219227104",
// "latitude": "1rYHnwBPVw",
// "longitude": "OdLQpWHPAh",
// "speed": "1h7kwVVDAn",
// "flag": "Z5QibXj48h"
// },
// {
// "uploadTime": "1623219721123",
// "latitude": "5IdyTX2Pnk",
// "longitude": "wBk6zhAN5q",
// "speed": "QYUiPwTDm6",
// "flag": "o2Djlnz9zz"
// },
// {
// "uploadTime": "1623218979229",
// "latitude": "HTrDfDcC7p",
// "longitude": "TZbjbNVv4O",
// "speed": "u9piMU1Y8C",
// "flag": "NBJEklj0k5"
// }
// ]
// },
// {
// "staffPatrolRecId": "54902",
// "totalTimeDesc": "1小时02分",
// "patrolStartTime": "1622713164908",
// "patrolEndTime": "1622712593237",
// "status": "end",
// "latestChangeDesc": "DUAThkxkNN",
// isOpen: false,
// "details": [
// {
// "uploadTime": "1623219227104",
// "latitude": "1rYHnwBPVw",
// "longitude": "OdLQpWHPAh",
// "speed": "1h7kwVVDAn",
// "flag": "Z5QibXj48h"
// },
// {
// "uploadTime": "1623219721123",
// "latitude": "5IdyTX2Pnk",
// "longitude": "wBk6zhAN5q",
// "speed": "QYUiPwTDm6",
// "flag": "o2Djlnz9zz"
// },
// {
// "uploadTime": "1623218979229",
// "latitude": "HTrDfDcC7p",
// "longitude": "TZbjbNVv4O",
// "speed": "u9piMU1Y8C",
// "flag": "NBJEklj0k5"
// }
// ]
// }
],
dateTimeArray1: null,
dateTime1: null,
startYear: '2021',
endYear: '2021',
startTime: [],
endTime: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: async function (options) {
let { pageType, gridId, staffId, gridName } = this.data
if (options.pageType) {
pageType = options.pageType
}
await this.initPatro()
gridName = app.globalData.gridName
gridId = app.globalData.user.agencyId
staffId = app.globalData.user.id
this.setData({
gridId,
staffId,
pageType,
gridName,
staffName: options.staffName,
patrolDate: formatDate(new Date())
})
await this.getTimePicker(this.data.gridId, this.data.staffId)
await this.getRecordList(this.data.gridId, this.data.staffId)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
initPage() {
},
initPicker() {
const startTime = getNewDateArry(this.data.patrolInfo.patrolStartTime.substr(0,10))
// const startTime = getNewDateArry('2021-06-16 16:00:54')
const endTime = getNewDateArry()
console.log('date', startTime, endTime)
var obj1 = dateTimePicker(startTime[0], endTime[0], startTime[1], endTime[1], startTime[2], endTime[2], startTime[3], endTime[3], startTime[4], endTime[4]);
// 精确到分的处理,将数组的秒去掉
//var lastArray = obj1.dateTimeArray.pop();
//var lastTime = obj1.dateTime.pop();
// console.log('date', new Date('2021-06-10 16:56:54'))
this.setData({
dateTimeArray1: obj1.dateTimeArray,
dateTime1: obj1.dateTime,
startTime,
endTime
});
console.log('dateTime1', obj1.dateTime)
},
async startPatrol() {
await app.startPatrol()
this.initPatro()
},
async endPatrol(time) {
await app.closePatrol(time)
this.initPatro()
this.getRecordList(this.data.gridId, this.data.staffId)
},
handleTips() {
this.initPicker()
wx.showToast({
title: '请选择结束时间',
icon: 'none',
duration: 1500
})
},
handleShowBot(e) {
const index = e.currentTarget.dataset.index
let { recordList } = this.data
recordList[index].isOpen = !recordList[index].isOpen
this.setData({
recordList
})
},
handlePickerChange(e) {
console.log('eeeee', e)
const value = e.detail.value
this.setData({
patrolDate: this.data.timePicker[value]
})
this.getRecordList(this.data.gridId, this.data.staffId)
},
toMapPage(e) {
const index = e.currentTarget.dataset.index;
const { recordList } = this.data;
wx.setStorageSync(
"tempPatrolPoints",
recordList[index].details.map((item) => {
return {
longitude: item.longitude,
latitude: item.latitude,
};
})
);
wx.navigateTo({
url: 'map/index',
})
},
async getTimePicker(gridId, staffId) {
const res = await api.post(
"data/aggregator/epmetuser/patrolleddatelist",
{
staffId,
gridId
},
{
// isMock: true,/
// isQuiet: true/
}
);
if (res.code === 0) {
// branchInfo = { ...data }
this.setData({
timePicker: res.data.list
})
}
},
async initPatro() {
const res = await api.post(
"epmetuser/staffpatrol/init",
{
gridId: app.globalData.user.agencyId
},
{
// isMock: true,/
// isQuiet: true/
}
);
if (res.code === 0) {
// branchInfo = { ...data }
this.setData({
patrolInfo: res.data
})
app.globalData.patrol.status = res.data.status
app.globalData.patrol.staffPatrolRecId = res.data.staffPatrolRecId
this.initPicker()
}
},
async getRecordList(gridId, staffId) {
const res = await api.post(
"data/aggregator/epmetuser/recordlist",
{
patrolDate: this.data.patrolDate,
gridId:app.globalData.user.agencyId,
userId:app.globalData.user.id
},
{
// isMock: true,/
// isQuiet: true/
}
);
if (res.code === 0) {
// branchInfo = { ...data }
this.setData({
recordList: res.data
})
}
},
// 选择日期时间
changeDateTime1(e) {
this.setData({
dateTime1: e.detail.value
});
const { dateTimeArray1, dateTime1 } = this.data
const time = `${dateTimeArray1[0][dateTime1[0]]}-${dateTimeArray1[1][dateTime1[1]]}-${dateTimeArray1[2][dateTime1[2]]} ${dateTimeArray1[3][dateTime1[3]]}:${dateTimeArray1[4][dateTime1[4]]}:00`
// dateTimeArray1[0][dateTime1[0]]
this.endPatrol(time)
console.log('arrrttttttdateTime1', time)
},
changeDateTimeColumn1(e) {
const { endTime, startTime } = this.data
var arr = this.data.dateTime1,
dateArr = this.data.dateTimeArray1;
arr[e.detail.column] = e.detail.value;
console.log('value', e.detail.value, e.detail.column, arr)
dateArr[2] = getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]], startTime[1], endTime[1], startTime[2], endTime[2]);
const month = dateArr[1][arr[1]]
const day = dateArr[2][arr[2]]
const hour = dateArr[3][arr[3]]
const min = dateArr[4][arr[4]]
if (month == startTime[1] && day == startTime[2] && month == endTime[1] && day == endTime[2]) {
dateArr[3] = getLoopArray(startTime[3], endTime[3]);
dateArr[4] = getLoopArray(startTime[4], endTime[4]);
console.log('d1 if', month, day, hour, startTime[3])
} else if (month == startTime[1] && day == startTime[2] && (month !== endTime[1] || day !== endTime[2])) {
dateArr[3] = getLoopArray(startTime[3], 23);
dateArr[4] = getLoopArray(startTime[4], 59);
console.log('d1 elseif', month, day, hour, startTime[3])
} else if (month == endTime[1] && day == endTime[2]) {
dateArr[3] = getLoopArray(0, endTime[3]);
dateArr[4] = getLoopArray(0, endTime[4]);
console.log('d1 else if if', month, day, hour, startTime[3])
} else {
dateArr[3] = getLoopArray(0, 23);
dateArr[4] = getLoopArray(0, 59);
console.log('d1 else', month, day, hour, startTime[3])
}
console.log('arrrtttttt', month, day, hour, startTime[3])
if (hour) {
console.log('arrrtttttthhhh', month, day, hour, startTime[3])
if (month == startTime[1] && day == startTime[2] && month == endTime[1] && day == endTime[2]) {
if (hour == startTime[3] && hour == endTime[3]) {
dateArr[4] = getLoopArray(startTime[4], endTime[4]);
} else if (hour == startTime[3] && hour != endTime[3]) {
dateArr[4] = getLoopArray(startTime[4], 59);
} else if (hour == endTime[3]) dateArr[4] = getLoopArray(0, endTime[4]);
else dateArr[4] = getLoopArray(0, 59);
console.log('h1 if', month, day, hour, startTime[3])
} else if (month == startTime[1] && day == startTime[2] && hour == startTime[3]) {
console.log('h1 else if', month, day, hour, startTime[3])
dateArr[4] = getLoopArray(startTime[4], 59);
} else if (month == endTime[1] && day == endTime[2] && hour == endTime[3]) {
dateArr[4] = getLoopArray(0, endTime[4]);
console.log('h1else if if', month, day, hour, startTime[3])
} else {
console.log('h1else', month, day, hour, startTime[3])
dateArr[4] = getLoopArray(0, 59);
}
}
// arr = []
// dateArr.forEach((current, index) => {
// console.log('dateTime', current.indexOf(endTime[index]))
// arr.push(current.indexOf(endTime[index]));
// });
// if (hour == startTime[3])
// dateArr[3] = getLoopArray(dateArr[0][arr[0]], dateArr[1][arr[1]], 6, 10, 23);
this.setData({
dateTimeArray1: dateArr,
dateTime1: arr
});
},
async getGridList() {
const {
data: {
data: { code, data },
},
msg,
} = await api.post(
"gov/mine/agency/getmygrids",
{},
{
// isMock: true,
// isQuiet: true
}
);
if (msg === "success" && code === 0) {
return data;
} else {
return [];
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})