var app = getApp() Page({ data: { markers: [], polyline: [], controls: [], hasEmptyGrid: false, bikeId: '', bike_no: '', longitude: '', latitude: '', startTime: "", //开始时间 默认昨天 endTime: "", //结束时间 默认今天 }, onLoad: function (options) { let that = this; that.setData({ bikeId: options.id, bike_no: options.bike_no, }); that.getPosition(); that.timeInit(); }, //获取当前车辆信息 getPosition() { wx.showLoading({ title: '获取位置中...', }) let that = this; let data = { bike_no: that.data.bike_no } app.request('bike/position', data, 'GET').then(res => { wx.hideLoading(); console.log(res); if (res.data[0] == 0) { wx.showToast({ title: '暂无车辆最后位置信息~', icon: 'none' }) wx.getLocation({ type: 'gcj02', success: function (res) { var latitude = res.latitude var longitude = res.longitude that.setData({ longitude: longitude, latitude: latitude }) }, }) } else { let position = []; position[0] = { width: 32, height: 32, zIndex: 1111, iconPath: 'http://resource.bike.hanyiyun.com/common/start-location-mark-old.png', longitude: res.data[0], latitude: res.data[1] } that.setData({ markers: position, longitude: res.data[0], latitude: res.data[1] }) } }) }, //初始化日期 timeInit() { let that = this; let start = new Date(); start.setTime(start.getTime()-24*60*60*1000) let startTime = that.getTime(start) let tom = new Date(); // tom.setTime(tom.getTime() + 24 * 60 * 60 * 1000); let end = that.getTime(tom); that.setData({ startTime: startTime, endTime: end }) }, //获取年月日 时分秒 getTime(date) { var year = date.getFullYear(); var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate() var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours() var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes() var today = year + "-" + month + "-" + day + " " + hours + ":" + minute; return today; }, start(e) { this.setData({ startTime: e.detail.dateString }) }, end(e) { this.setData({ endTime: e.detail.dateString }) }, show: function () { wx.showLoading({ title: '加载中...', }) var that = this; let start = new Date(that.data.startTime).getTime(); let end = new Date(that.data.endTime).getTime(); if (start > end) { wx.showToast({ title: '开始日期不能大于结束日期', icon: 'none' }) } else { that.setData({ markers: [] }) var data = { 'bike_no': that.data.bike_no, 'time_between[0]': that.data.startTime, 'time_between[1]': that.data.endTime, } app.request('bike/bikeLocation', data, 'POST').then(res => { wx.hideLoading(); console.log(res,'车辆位置') if (res.data == '') { wx.showToast({ title: '暂无骑行轨迹~', icon: 'none' }) } else { that.setData({ polyline:res.data.all_locations, markers:res.data.points }) } }) } }, hidn() { let that = this; that.timeInit(); that.setData({ polyline: [], markers: '', }) }, })