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.
 
 
 
 

194 lines
4.4 KiB

// package/inspectionRecord/inspectionRecord.js
import { getPatrolRecord } from "../../utils/getApiUrl";
import { Request } from "../../common";
const moment = require("../../utils/moment");
Page({
/**
* 页面的初始数据
*/
data: {
ResList: [ //阅读状态
{
value: 'all',
text: '全部',
},
{
value: 'normal',
text: '正常',
},
{
value: 'abnormal',
text: '异常',
}
],
ResIndex: 0, //巡检结果
dataList: [],
isPickerRender: false,
isPickerShow: false,
startTime: "开始日期", //开始日期
endTime: "结束日期", //结束日期
pickerConfig: { //自定义时间选择器配置项
endDate: true, //是否需要结束时间,为true时显示开始时间和结束时间两个picker
column: "day", //可选的最小时间范围day、hour、minute、second
dateLimit: true, //是否现在时间可选范围,false时可选任意时间;当为数字n时,范围是当前时间的最近n天
initStartTime: "", //picker初始时间
initEndTime: "", //picker初始结束时间
// limitStartTime: "", //最小可选时间
// limitEndTime: "" //最大可选时间
},
hidden: true,
},
// 巡检结果
bindPickerRes(e) {
let that = this;
that.setData({
ResIndex: e.detail.value
})
},
// 时间选择器显示
pickerShow: function () {
this.setData({
isPickerShow: true,
isPickerRender: true,
});
},
// 时间选择器隐藏
pickerHide: function () {
this.setData({
isPickerShow: false,
});
},
// 获取选择时间
setPickerTime: function (val) {
let data = val.detail;
this.setData({
startTime: data.startTime,
endTime: data.endTime
});
},
// 清空提交日期筛选框
bindClearDate() {
this.setData({
startTime: '开始日期',
endTime: '结束日期'
})
},
// 查询
bindSearch() {
this.getPatrolRecord();
},
// 查看详情
bindDetail(e) {
let data = e.currentTarget.dataset.item;
wx.navigateTo({
url: '/package/inspectionRecord/inspectionRecordDetail/inspectionRecordDetail?data=' + JSON.stringify(data),
})
},
// 获取巡检记录
getPatrolRecord: function () {
let that = this;
let { endTime, startTime, ResList, ResIndex } = that.data;
let sevenYearAgo = moment().subtract(7, 'days').format('YYYY-MM-DD 00:00:00');
let currentData = moment().startOf('days').format('YYYY-MM-DD 23:59:59');
console.log(currentData, 'currentData');
let alarm = ResList[ResIndex].value == 'all' ? 'null' : ResList[ResIndex].value == 'normal' ? false : true;
wx.showLoading({
title: '加载中'
})
Request.get(getPatrolRecord('all', startTime == '开始日期' ? sevenYearAgo : startTime + ' 00:00:00', endTime == '结束日期' ? currentData : endTime + ' 23:59:59', alarm, 'null')).then(res => {
if (res.length == 0) {
that.setData({
dataList: res,
hidden: false
})
wx.hideLoading()
return;
}
let dataSource = res.map(e => {
e.lastInspectionTime = moment(e.lastInspectionTime).format('YYYY-MM-DD');
e.inspectionTime = moment(e.inspectionTime).format('YYYY-MM-DD');
return e;
})
that.setData({
dataList: dataSource,
hidden: true
})
wx.hideLoading()
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getPatrolRecord();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
let that = this;
that.setData({
dataList: [],
ResIndex: 0, //巡检结果
startTime: "开始日期", //开始日期
endTime: "结束日期", //结束日期
})
that.getPatrolRecord()
// 手动控制回弹
wx.stopPullDownRefresh();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})