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

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let userInfo = wx.getStorageSync('userInfo')  // 获取用户信息
    this.setData({ userInfo })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getStoreInfo()  // 获取商店信息
  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: 'Bingo果汁冰',
      path: '/pages/index/index',
      success: function (res) {
        // 转发成功
      },
    }
  },

  // 获取商店信息
  getStoreInfo() {
    let that = this
    wx.request({
      url: hostname + 'Goods/get_business_info',
      data: { business_id },
      header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
      method: 'POST',
      dataType: 'JSON',
      success: function (res) {
        let storeInfo = JSON.parse(res.data).data
        that.setData({ storeInfo })
        wx.setStorageSync('address', storeInfo.business_address)
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  // 联系商家
  contactStore() {
    let { business_phone } = this.data.storeInfo
    wx.makePhoneCall({
      phoneNumber: business_phone,
    })
  },
  navAbout() {
    wx.navigateTo({
      url: '../about/about',
    })
  },
  navAddress() {
    wx.navigateTo({
      url: '../navPage/navPage',
    })
  },
  navCoupon(){
    wx.navigateTo({
      url: '../coupon/coupon',
    })
  }
})