// pages/venueDetail/venueDetail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    baseUrl: 'http://192.168.0.109:8082/venuebooking/',
    imgRoute : 'route/file/downloadfile/true/',
    indicatorDots:  true,
    autoplay: true,

    venuesInfoId: '',
    venuesDetail:{},
    venuesProjectList: [],
    swiperImg:[],
    venueCharge: '',
    selectVenuesProject: '',
    selectVenuesProjectDetail: {}
  },

  //场馆详情接口
  getVenuesDetail: function(){
    var self = this;
    wx.request({
      url: self.data.baseUrl + 'app/venuesinfo/getvenuesinfobyidrelease/' + self.data.venuesInfoId,
      data: {
        resultLocation: 'TX'
      },
      success:(res) => {
        var swiperImg = res.data.venuePanorama.split(',');
        if(swiperImg.length <= 1){
          self.setData({
            indicatorDots: false,
            autoplay: false
          })
        }
        self.setData({
          venuesDetail: res.data,
          swiperImg: swiperImg,
          venueCharge: res.data.venueCharge
        });
        console.log(self.data.venuesDetail);
      }
    })
  },

  //获取项目列表
  listVenuesProject: function(){
    var self = this;
    wx.request({
      url: self.data.baseUrl + 'app/venuesproject/listprojectinforelease/' + self.data.venuesInfoId,
      success: (res) => {
        self.setData({
          venuesProjectList: res.data
        });
        if(self.data.venuesProjectList.length > 0){
          self.setData({
            selectVenuesProject: self.data.venuesProjectList[0].venuesProjectId
          });
          self.getVenuesProjectDetail();
        };
      }
    })
  },

  //切换当前选择项目
  changeVenuesProject: function(options){
    var venuesProjectId = options.currentTarget.dataset.id;
    if(this.data.selectVenuesProject == venuesProjectId){
      return false;
    };
    this.setData({
      selectVenuesProject: venuesProjectId
    });
    this.getVenuesProjectDetail();
  },

  //获取项目详情信息
  getVenuesProjectDetail: function(){
    var self = this;
    wx.request({
      url: self.data.baseUrl + 'app/venuesproject/getvenuesprojectdetailrelease/' + self.data.selectVenuesProject,
      success: function(res){
        self.setData({
          selectVenuesProjectDetail: res.data.data
        });
      }
    });
  },

  //场馆地图导航
  showMap: function(options){
    console.log(options);
    var dataObj = options.currentTarget.dataset
    console.log(dataObj.latitude + 0)
    wx.openLocation({//​使用微信内置地图查看位置。
      latitude: Number(dataObj.latitude),//要去的纬度-地址
      longitude: Number(dataObj.longitude),//要去的经度-地址
      name: dataObj.venuename,
      address: dataObj.venueposition
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      venuesInfoId: options.venuesInfoId
    });
    this.getVenuesDetail();
    this.listVenuesProject();
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})