const { api, imgName, getUserInfo, wxLogin, alertTip, authAgainByUser, userLocation } = require('../../lib/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    polyline:[],
    markers:[],
    longitude: 120.126593,
    latitude: 30.342009,
    tripId:null,
    queryData:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    let data = wx.getStorageSync('trailQuery')
    this.setData({
      queryData:data
    })
    this.getTrack(data)
  },
  getTrack(data){
    api.get('gps/query',data)
    .then(({items})=>{
      let polyline = [{ points: [], color: '#b80303FF', arrowLine: true, width: 3}]
      if(items.length==0){
        alertTip('无详细行程轨迹数据',()=>{
          wx.navigateBack()
        })
        return
      }
      items.map(item=>{
        polyline[0].points.push({ latitude: item.lat, longitude: item.lng })
        return item
      })
      this.setData({
        polyline,
        longitude: items[0].lng,
        latitude: items[0].lat,
      })
    })
    .catch(err=>{
      console.log(err)
      alertTip(err)
    })
  }
})