const app = getApp(),
  { hostname } = getApp().globalData

Page({

  /**
   * 页面的初始数据
   */

  data: {
    markers: [{
      iconPath: "/images/location.png",
      id: 0,
      latitude: wx.getStorageSync('lat') || 23.257830,
      longitude: wx.getStorageSync('lng') || 116.428170,
      width: 25,
      height: 25
    }],
    controls: [{
      id: 1,
      iconPath: '/images/navigator.png',
      position: {
        left: 310,
        top: 500,
        width: 50,
        height: 50
      },
      clickable: true
    }],
  },
  onLoad(options) {
    let that = this
    let business_id;
    if (options.business_id) {
      business_id = options.business_id;
    } else {
      business_id = app.globalData.business_id;
    }
    wx.request({
      url: hostname + 'Goods/BusinessAddress',
      method: 'POST',
      data: { business_id },
      header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;' },
      success: (res) => {
        let { markers } = that.data;
        let dz = res.data.lnglat.split(/,/);
        if (res.data) {

          markers[0].longitude = dz[0]
          markers[0].latitude = dz[1]
        }
        that.setData({
          markers
        })
      }
    })
  },
  controltap(e) {
    let that = this
    console.log(that.data.markers[0].latitude, typeof that.data.markers[0].latitude)
    wx.getLocation({
      success: function (res) {
        wx.openLocation({
          latitude: Number(that.data.markers[0].latitude),
          longitude: Number(that.data.markers[0].longitude),
          name: wx.getStorageSync('address')
        })
      },
    })
  }
})