|
|
@ -1,78 +1,81 @@ |
|
|
|
// pages/index/index.js
|
|
|
|
import { getProjectList } from "../../utils/getApiUrl"; |
|
|
|
import { getProjectList, getPatrolRecord } from "../../utils/getApiUrl"; |
|
|
|
import { Request } from "../../common"; |
|
|
|
const moment = require("../../utils/moment"); |
|
|
|
|
|
|
|
Page({ |
|
|
|
|
|
|
|
/** |
|
|
|
* 页面的初始数据 |
|
|
|
*/ |
|
|
|
data: { |
|
|
|
dataList: [], |
|
|
|
limit: 10, //条数
|
|
|
|
page: 0, //当前页
|
|
|
|
count: '', //总条数
|
|
|
|
keyName: '', //结构物名称
|
|
|
|
hidden: true, |
|
|
|
imgUrl: getApp().globalData.imgUrl |
|
|
|
project: [], |
|
|
|
todayRecord: [], // 今日巡检记录
|
|
|
|
markers: [], |
|
|
|
isShowCallout: false, |
|
|
|
}, |
|
|
|
|
|
|
|
// 输入框
|
|
|
|
formInp(e) { |
|
|
|
let that = this; |
|
|
|
that.setData({ |
|
|
|
keyName: e.detail.value |
|
|
|
setMarkers(project, todayRecord) { |
|
|
|
const markers = project.map(p => { |
|
|
|
let todayCount = 0; |
|
|
|
todayRecord.forEach(r => { |
|
|
|
if (r.projectId === p.id) { todayCount += 1 } |
|
|
|
}) |
|
|
|
return { |
|
|
|
id: p.id, |
|
|
|
latitude: p.latitude, |
|
|
|
longitude: p.longitude, |
|
|
|
name: p.name, |
|
|
|
iconPath: '/images/circle.png', |
|
|
|
width: 15, |
|
|
|
height: 15, |
|
|
|
callout: { |
|
|
|
content: `${p.name}\n今日巡检:${todayCount}次`, |
|
|
|
padding: 10, |
|
|
|
display: this.data.isShowCallout ? 'ALWAYS' : 'BYCLICK', |
|
|
|
}, |
|
|
|
} |
|
|
|
}) |
|
|
|
this.setData({ markers }) |
|
|
|
}, |
|
|
|
|
|
|
|
// 手机键盘点击完成按钮(回车事件)
|
|
|
|
bindconfirm() { |
|
|
|
let that = this; |
|
|
|
that.setData({ |
|
|
|
page: 0, //当前页
|
|
|
|
count: '', //总条数
|
|
|
|
dataList: [] |
|
|
|
// 获取结构物和今日巡检次数
|
|
|
|
getData() { |
|
|
|
const that = this; |
|
|
|
wx.showLoading({ title: '加载中' }) |
|
|
|
const promiseArr = []; |
|
|
|
promiseArr.push(Request.get(getProjectList(), {})); |
|
|
|
promiseArr.push(Request.get(getPatrolRecord('all', moment().format('YYYY-MM-DD') + ' 00:00:00', moment().format('YYYY-MM-DD') + ' 23:59:59', 'null', 'null'))); |
|
|
|
Promise.all(promiseArr).then(res => { |
|
|
|
wx.hideLoading() |
|
|
|
that.setData({ |
|
|
|
project: res[0].rows, |
|
|
|
todayRecord: res[1] |
|
|
|
}) |
|
|
|
that.setMarkers(res[0].rows, res[1]); |
|
|
|
// 缩放视野展示所有 markers
|
|
|
|
const mapCtx = wx.createMapContext('mapDom') |
|
|
|
mapCtx.includePoints({ |
|
|
|
points: res[0].rows, |
|
|
|
padding: [40, 40, 40, 40] |
|
|
|
}) |
|
|
|
}) |
|
|
|
that.getProjectList(); |
|
|
|
}, |
|
|
|
|
|
|
|
// 搜索表单
|
|
|
|
goSearch() { |
|
|
|
let that = this; |
|
|
|
that.setData({ |
|
|
|
page: 0, //当前页
|
|
|
|
count: '', //总条数
|
|
|
|
dataList: [] |
|
|
|
}) |
|
|
|
that.getProjectList(); |
|
|
|
showCallout() { |
|
|
|
this.setData( |
|
|
|
{ isShowCallout: !this.data.isShowCallout }, |
|
|
|
() => { this.setMarkers(this.data.markers, this.data.todayRecord); } |
|
|
|
); |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取巡检总览列表
|
|
|
|
getProjectList: function () { |
|
|
|
let that = this; |
|
|
|
let { page, limit, keyName } = that.data; |
|
|
|
let data = keyName ? { limit, page, name: keyName } : { limit, page } |
|
|
|
wx.showLoading({ |
|
|
|
title: '加载中', |
|
|
|
}) |
|
|
|
Request.get(getProjectList(), data).then(res => { |
|
|
|
if (res.rows.length == 0) { |
|
|
|
that.setData({ |
|
|
|
dataList: res.rows, |
|
|
|
hidden: false |
|
|
|
}) |
|
|
|
wx.hideLoading() |
|
|
|
return; |
|
|
|
} |
|
|
|
var arr1 = that.data.dataList; //从data获取当前dataList数组
|
|
|
|
var arr2 = res.rows; //从此次请求返回的数据中获取新数组
|
|
|
|
arr1 = arr1.concat(arr2); //合并数组
|
|
|
|
that.setData({ |
|
|
|
dataList: arr1, |
|
|
|
count: res.count, //总条数
|
|
|
|
hidden: true |
|
|
|
}) |
|
|
|
wx.hideLoading() |
|
|
|
}) |
|
|
|
onRefresh() { |
|
|
|
this.getData(); |
|
|
|
}, |
|
|
|
|
|
|
|
onMarkerTap(e) { |
|
|
|
console.log(e.detail.markerId, 'e.detail.markerId') |
|
|
|
wx.navigateTo({url: `/package/pointsStatus/pointsStatus?projectId=${e.detail.markerId}`}) |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
@ -104,7 +107,7 @@ Page({ |
|
|
|
url: '/pages/login/login' |
|
|
|
}); |
|
|
|
} else { |
|
|
|
this.getProjectList(); |
|
|
|
this.getData(); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
@ -112,60 +115,28 @@ Page({ |
|
|
|
* 生命周期函数--监听页面隐藏 |
|
|
|
*/ |
|
|
|
onHide() { |
|
|
|
this.setData({ |
|
|
|
dataList: [], |
|
|
|
keyName: '', |
|
|
|
page: 0, //当前页
|
|
|
|
count: '', //总条数
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 生命周期函数--监听页面卸载 |
|
|
|
*/ |
|
|
|
onUnload() { |
|
|
|
this.setData({ |
|
|
|
dataList: [], |
|
|
|
keyName: '', |
|
|
|
page: 0, //当前页
|
|
|
|
count: '', //总条数
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 页面相关事件处理函数--监听用户下拉动作 |
|
|
|
*/ |
|
|
|
onPullDownRefresh() { |
|
|
|
let that = this; |
|
|
|
that.setData({ |
|
|
|
dataList: [], |
|
|
|
keyName: '', |
|
|
|
page: 0, //当前页
|
|
|
|
count: '', //总条数
|
|
|
|
}) |
|
|
|
that.getProjectList() |
|
|
|
// 手动控制回弹
|
|
|
|
wx.stopPullDownRefresh(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 页面上拉触底事件的处理函数 |
|
|
|
*/ |
|
|
|
onReachBottom() { |
|
|
|
let _that = this; |
|
|
|
let page = _that.data.page + 1; //获取当前页数并+1
|
|
|
|
let { dataList, count } = _that.data; |
|
|
|
if (dataList.length == count) { |
|
|
|
wx.showToast({ |
|
|
|
title: '没有更多数据了...', |
|
|
|
icon: 'none', |
|
|
|
}) |
|
|
|
return; |
|
|
|
} |
|
|
|
_that.setData({ |
|
|
|
page: page, //更新当前页数
|
|
|
|
}) |
|
|
|
_that.getProjectList() |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|