// pages/ManyStore/ManyStore.js
const app = getApp(),
  { hostname,business_id } = app.globalData;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sub:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getsubstore(that)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
     * 用户点击右上角分享
     */
  onShareAppMessage: function (res) {
    var userid = wx.getStorageSync('openId')
    // var userid = 1

    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: app.globalData.share_title,
      path: '/pages/index/index?u_openid=' + userid,
      success: function (res) {
        var pages = getCurrentPages()    //获取加载的页面
        var currentPage = pages[pages.length - 1]    //获取当前页面的对象
        //点击分享传进userid 截取userid 从onload拿到
        var url = currentPage.route + '?u_openid=' + userid;  //当前页面url
        console.log(url, '/pages/index/index?u_openid=' + userid);
      },
      fail: function (res) {
        // 转发失败
      },
    }
  },
  gosub(e){
    var business_id = e.currentTarget.dataset.business_id;
   wx.navigateTo({
     url: 'subStore/subStore?business_id=' + business_id
   })
  },
// 获取子门店信息
  getsubstore(that){
    console.log(business_id)
    wx.request({
      url: hostname +'ManyStore/SubsidiaryStore' ,
      data:{business_id },
      header:{'content-type':'application/x-www-form-urlencoded'},
      method:'POST',
      success:function(res){
        console.log(res)
        if(res.data.status==1){
          that.setData({ sub:res.data.data })
        }else{
          that.setData({ sub:[] })
        }
      }
    })
  },
  // 前往地图导航
  goAddress(e) {
    console.log(e.currentTarget.dataset.lnglat)
    wx.navigateTo({
      url: '../navPage/navPage?business_id=' + e.currentTarget.dataset.business_id,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  // 前往拨打电话
  callPhone(e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.phone,
    })
  }
})