// pages/trip/trip.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    windowHeight:'',
    height:'',
    order:'',
    date:[],
    markers:[],
    polyline:[],
    latitude:'',
    longitude:'',
    url:'',
    index:'',
    img:app.globalData.imgUrl
  },
  onLoad: function (options) {
    var that = this;
    console.log(options,'传值')
    let order_no=options.order_no
    // my.getSystemInfo({
    //   success: function (res) {
    //     console.log(res.windowHeight);
    //     that.setData({ windowHeight: res.windowHeight})
    //   }
    // })
    // this.setData({order:options.order})
    // if(options.index){
    //   if (options.index == 0) {
    //     that.setData({
    //       url : '/order?order_no='
    //     })
    //   }
    //   if (options.index == 1) {
    //     that.setData({
    //       url : '/rent/order?no='
    //     })
    //   }
    //   this.setData({index:options.index})
    // }
    // if(options.index){
    //   if (options.index == 'true') {
    //     that.setData({
    //       url : '/order?order_no='
    //     })
    //     this.setData({index:0})
    //   }
    //   if (options.index == 'false') {
    //     that.setData({
    //       url : '/rent/order?no='
    //     })
    //     this.setData({index:1})
    //   }
    // }
    // var query = my.createSelectorQuery();
    // query.select('.box').boundingClientRect();
    // query.exec(function (res) {
    //   console.log(res)
    //   console.log(res[0].height)
    //   that.setData({ height: res[0].height });
    // })
    // my.getLocation({
    //   type:'gcj02',
    //   success: function(res) {
    //     var latitude = res.latitude
    //     var longitude = res.longitude
    //     that.setData({ longitude: longitude, latitude: latitude })
    //   },
    // })
    // this.load(); 
    this.getTrack(order_no);  //获取行车轨迹及订单信息
  },
   // 获取行车轨迹及订单信息
   getTrack(order_no){
    var that = this;
    my.showLoading({
      content: '加载中...',
    })
    console.log(that.data.url)
    app.request('/order?order_no=' + order_no+'&include=locations','','GET').then(res=>{
      console.log(res)
      if(res.status == 200){
        my.hideLoading()
        that.setData({ date: res.data });
        let points = res.data.locations.data;
        var center = parseInt(points.length/2)
        var obj = {};
        obj.points = points;
        obj.width = 2;
        obj.color = '#f8c700';
        obj.borderWidth = 1;
        obj.borderColor = '#f8c700';
        that.setData({ polyline: that.data.polyline.concat(obj) })
        if (points.length>0){
          var maker = [];
          maker = maker.concat(points[0]);
          maker = maker.concat(points[points.length - 1])
          for (var i = 0; i < maker.length; i++) {
            maker[i].width =32;
            maker[i].height = 32;
            maker[i].zIndex = 1111;
          }
          //在地图上显示两个坐标
          maker[0].iconPath = 'http://resource.bike.hanyiyun.com/weapp/start1.png'
          maker[1].iconPath = 'http://resource.bike.hanyiyun.com/weapp/end1.png'
          that.setData({ markers: maker, longitude: points[center].longitude, latitude: points[center].latitude })
        } else {
          my.getLocation({
            type: 'gcj02',
            success: function (res) {
              var latitude = res.latitude
              var longitude = res.longitude
              that.setData({ longitude: longitude, latitude: latitude })
            },
          })
        }
      }
    })
  },
  //计费规则
  chargeRule:function(){
    my.navigateTo({
      url:'/pages/charge_rule/charge_rule',
    })
  },
  //不认可收费
  noAgree:function(){
    my.makePhoneCall({
      number:my.getStorageSync({'key':'home'}).data.customer_service_phone,
    })
  },
  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {

  },

})