// reportForm/index/index.js
|
var dateTimePickerCtrl = require('../../utils/dateTimePicker.js'); //日期控件
|
var Constant = require('../../utils/constant.js');
|
var util = require('../../utils/util.js');
|
Page({
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
width: '',
|
height: '',
|
colHeight: '',
|
colWidth: '',
|
scrollTop: 0,
|
VerticalNavTop: 0,
|
stationName: '', //泵站名称
|
stationID: '', //泵站id
|
requestData: {
|
stationID: "",
|
year: '',
|
month: '',
|
},
|
dateStart: "",
|
dateEnd: "",
|
startDate: "",
|
endDate: "",
|
selectDate: '', //日期选择后的日期
|
isShowFilter: false, //是否显示日期筛选
|
isLeftScroll: false, //判断左边的scroll-view 的方法是否调用
|
isRightScroll: false, //判断右边的scroll-view 的方法是否调用
|
tabDateList: [], //存储日期的数组
|
tabHeadList: [], //存储表头内容的数组
|
timeList: [], //存储开关机时间、用电量、供水量的数组,
|
list: [], //存储表格内容元素宽高的数组
|
load: true,
|
},
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad: function (options) {
|
console.log(options, 328)
|
let that = this;
|
wx.getSystemInfo({ //获取设备的宽度和高度
|
success: (res) => {
|
console.log(res.windowWidth, res.windowHeight, '设备物理宽高')
|
that.setData({
|
width: res.windowWidth,
|
height: res.windowHeight
|
})
|
},
|
fail: (err) => {
|
console.log(err)
|
}
|
})
|
that.initialDateTimePicker();
|
var requestData = that.data.requestData
|
requestData.stationID = options.id
|
that.setData({
|
stationID: options.id,
|
requestData: requestData,
|
stationName: options.name
|
})
|
that.initData();
|
},
|
//初始化数据
|
initData: function () {
|
wx.showLoading({
|
title: '数据加载中...',
|
})
|
var that = this
|
var requestData = that.data.requestData
|
wx.request({
|
url: Constant.BASE_SERVER_URL + 'Main/Web/PumpRunParas/GetMonthDetailSumDataByStationID',
|
method: "GET",
|
data: {
|
StationID: requestData.stationID,
|
Year: requestData.year,
|
Month: requestData.month
|
},
|
success: res => {
|
console.log(res,83)
|
wx.hideLoading()
|
var tabDateList = that.data.tabDateList; //表格左侧日期列表
|
var tabHeadList = that.data.tabHeadList; //表头
|
var list = []; //表格内容-各个机组的时间
|
|
// console.log(res.data.Data, 291)
|
// console.log(timeList, 292)
|
var result = res.data.Data
|
if (res.data.Code != 0) {
|
wx.showToast({
|
title: '数据加载失败',
|
icon: 'none',
|
duration: 2000
|
})
|
return;
|
}
|
//构造表格需要的数据格式
|
var temp = result[0];
|
var recordArr = result;
|
|
var temp1 = 0
|
var arrtest = []
|
for (var i = 0; i < recordArr.length - 1; i++) {
|
var test = {}
|
if (recordArr[i].SumDay != recordArr[i + 1].SumDay) {
|
// console.log(temp1, i)
|
for (var j = temp1; j < i + 1; j++) {
|
test['kaiji' + j + 1] = recordArr[j].RunHours;
|
test['kaiji' + j + 2] = recordArr[j].D;
|
test['kaiji' + j + 3] = recordArr[j].Q;
|
}
|
temp = recordArr[i + 1]
|
temp1 = i + 1
|
arrtest.push(test)
|
}
|
if (i == recordArr.length - 2) {
|
for (var j = temp1; j < recordArr.length; j++) {
|
test['kaiji' + j + 1] = recordArr[j].RunHours;
|
test['kaiji' + j + 2] = recordArr[j].D;
|
test['kaiji' + j + 3] = recordArr[j].Q;
|
}
|
arrtest.push(test)
|
}
|
}
|
// console.log(arrtest, '列表主体数据')
|
|
for (let i = 0; i < result.length; i++) {
|
var info = result[i]
|
tabDateList.push(info.SumDay) //获取日期
|
var tabHead = { //临时存储表头信息
|
PumpId: info.PumpId,
|
PumpName: info.PumpName,
|
child: ['开机时间(h)', '用电量', '供水量']
|
}
|
tabHeadList.push(tabHead)
|
}
|
|
//作用于表格左右滚动组件的适配
|
for (let k = 0; k < util.unique(tabDateList).length; k++) {
|
list.push({
|
id: k
|
})
|
}
|
that.setData({
|
tabDateList: util.unique(tabDateList),
|
tabHeadList: util.uniqueArr(tabHeadList),
|
timeList: arrtest,
|
list: list,
|
})
|
},
|
|
fail: err => {
|
wx.hideLoading();
|
if (err.errMsg == "request:fail ")
|
wx.showToast({
|
title: '网络请求失败',
|
icon: 'none',
|
duration: 2000
|
})
|
// console.log(err)
|
}
|
})
|
},
|
//监听左侧滚动事件
|
leftScroll: function (e) {
|
// this.setData({
|
// isLeftScroll: true,
|
// isRightScroll: false,
|
// leftScrollTop: e.detail.scrollTop
|
// })
|
},
|
VerticalMain(e) {
|
let that = this;
|
let list = that.data.list;
|
let listbak = that.data.list;
|
let tabHeight = 0;
|
if (this.data.load) {
|
list = listbak
|
for (let i = 0; i < list.length; i++) {
|
let view = wx.createSelectorQuery().select("#main-" + list[i].id);
|
view.fields({
|
size: true
|
}, data => {
|
// console.log(data)
|
list[i].top = tabHeight;
|
tabHeight = tabHeight + data.height;
|
list[i].bottom = tabHeight;
|
}).exec();
|
}
|
console.log(list, 111111);
|
that.setData({
|
load: false,
|
list: list
|
})
|
}
|
let scrollTop = e.detail.scrollTop;
|
// console.log(e.detail.scrollTop)
|
that.setData({
|
// VerticalNavTop: (list[i].id) * 26,
|
VerticalNavTop: scrollTop
|
})
|
// console.log(that.data.VerticalNavTop)
|
},
|
//监听右侧滚动事件
|
rightScroll: function (e) {
|
// console.log(e.detail.scrollTop)
|
this.setData({
|
isLeftScroll: true,
|
rightScrollTop: e.detail.scrollTop,
|
})
|
},
|
//开关机总表明细
|
toDetial: function (e) {
|
console.log(e.currentTarget.dataset.id, 284)
|
var selectDate = this.data.selectDate
|
var year = this.data.requestData.year
|
var month = this.data.requestData.month
|
wx.navigateTo({
|
url: '../Detail/index?id=' + e.currentTarget.dataset.id + '&year=' + year + '&month=' + month + '&name=' + e.currentTarget.dataset.pumpName + '&selectDate=' + selectDate,
|
})
|
},
|
//显示隐藏日期筛选查询
|
filterClick: function () {
|
var isShowFilter = this.data.isShowFilter
|
if (isShowFilter) {
|
isShowFilter = false
|
} else {
|
isShowFilter = true
|
}
|
this.setData({
|
isShowFilter: isShowFilter
|
})
|
},
|
//获取日期
|
initialDateTimePicker: function () {
|
var that = this;
|
var requestData = that.data.requestData;
|
var setDateStart = dateTimePickerCtrl.getDate(1);
|
var setDateEnd = dateTimePickerCtrl.getDate();
|
console.log('当前日期', setDateEnd)
|
requestData.year = setDateEnd.substring(0, 4)
|
requestData.month = setDateEnd.substring(5, 7)
|
that.setData({
|
requestData: requestData,
|
dateStart: setDateStart,
|
dateEnd: setDateEnd.substring(0, 7),
|
endDate: setDateEnd,
|
selectDate: setDateEnd.substring(0, 7)
|
});
|
},
|
//点击选择年、月份的事件
|
changeDateStart(e) {
|
console.log(e.detail.value)
|
var requestData = this.data.requestData
|
var year = e.detail.value.substring(0, 4);
|
var month = e.detail.value.substring(5, 7);
|
requestData.year = year
|
requestData.month = month
|
this.setData({
|
tabDateList: [],
|
requestData: requestData,
|
dateEnd: e.detail.value,
|
isShowFilter: false,
|
selectDate: e.detail.value
|
});
|
console.log(e.detail.value, year, month)
|
this.initData();
|
},
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady: function () {
|
//获取开机时间、用电量、供水量表格的宽高
|
let that = this
|
// 获取元素宽高进行表格适配
|
setTimeout(function () {
|
let query = wx.createSelectorQuery();
|
query.selectAll('.med_body > .body_item').boundingClientRect();
|
query.exec(function (rect) {
|
// console.log(rect, 163)
|
// console.log(rect[0][0].height)
|
// console.log(rect[0][0].width)
|
if (rect[0].length == 0) {
|
wx.showModal({
|
title: '提示',
|
content: '表格图像加载错误\n请检查您的网络重新进入该页面',
|
showCancel: false,
|
success: res => {
|
if (res.confirm) {
|
console.log('用户点击确定')
|
return;
|
}
|
}
|
})
|
}
|
that.setData({
|
colHeight: rect[0][0].height + 'px',
|
colWidth: rect[0][0].width + 'px'
|
})
|
})
|
}, 500)
|
},
|
|
/**
|
* 生命周期函数--监听页面显示
|
*/
|
onShow: function () {},
|
|
/**
|
* 生命周期函数--监听页面隐藏
|
*/
|
onHide: function () {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面卸载
|
*/
|
onUnload: function () {
|
|
},
|
|
/**
|
* 页面相关事件处理函数--监听用户下拉动作
|
*/
|
onPullDownRefresh: function () {
|
|
},
|
|
/**
|
* 页面上拉触底事件的处理函数
|
*/
|
onReachBottom: function () {
|
|
},
|
|
/**
|
* 用户点击右上角分享
|
*/
|
onShareAppMessage: function () {
|
return Constant.Share;
|
},
|
})
|