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

  /**
   * 页面的初始数据
   */
  data: {
    pointId: null,
    look: false,//false预约服务 true导航查看个租使用
    // time: '0:0',//运营时间
    locMap: {
      latitude: 30.334546,
      longitude: 120.121121,
      markers: [
        {
          id: 1,
          latitude: 0,
          longitude: 0,
          width: 30,
          height: 30,
          iconPath: imgName('pointloc.png'),
        }
      ]
    },
    point:{},//站点
    imgToloc: imgName('toloc.png'),
    imgLoc: imgName('pointloc.png'),
    imgNav: imgName('navigate.png'),
    imgPhone: imgName('security_settings_telephone_active.png'),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      look: options.look ? true : false
    })
   let point=wx.getStorageSync('point')
       //获取站点信息
    let {locMap} = this.data
    locMap.latitude = point.latitude
    locMap.longitude = point.longitude
    locMap.markers[0].latitude = point.latitude
    locMap.markers[0].longitude = point.longitude
   this.setData({
    point,
    locMap,
   })

  },
  onUnload: function () {

  },
  showMyLoc() {
    if (!this.mapCtx) {
      this.mapCtx = wx.createMapContext('carMap')
    }
    this.mapCtx.moveToLocation()
  },
  //站点
  toPoint() {
    let that = this
    wx.openLocation({
      latitude: Number(that.data.point.latitude),
      longitude: Number(that.data.point.longitude),
      scale: 28
    })
  },
  //拨打电话
  callPointPhone(e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.id
    })
  },
  //需要服务
  needServer(){
    // let hasCar=wx.getStorageSync('user').userMapp.isUseVehicle
    // if(hasCar){
      wx.navigateTo({
        url: `/pages/server/server?pointId=${this.data.pointId}`,
      })
    // }else{
      // alertTip('你当前并没有使用车辆')
    // }
  }
})