// pages/zl_detail/index.js
const { request, serverName, imgServer } = require('../../utils/services');
const WxParse = require('../../common/component/wxParse/wxParse.js');
const { defaultImg } = require('../../utils/images');
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    readActive:false,
    active: false,
    isLike: false,
    imgServer,
    longitude: 113.324520,
    latitude: 23.099994,
    likeNum:526,
    tour_info_data:[{
      title:'地址：',
      txt:'北京市朝阳区崔各乡庄各庄村顺白马路马嘻路口100米路北'
    }, {
      title: '开放时间',
      txt: '周二到周日10：00-18：00 （每周一闭馆）'
      }, {
        title: '电话：',
        txt: '+86 10 8456654654'
      }],
    relatedActivitiesLength:0,
    
  },
  readMore: function () {
    let readActive= !this.data.readActive,
      relatedActivities = this.data.pavilionDetail.relatedActivities,
      pavilionDetail = this.data.pavilionDetail,
      fullRelatedActivities = this.data.relatedActivities;
    
    this.setData({
      readActive:true,
      pavilionDetail
    })
  },
  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      pavilionId: options.id,
      serverName,
      defaultImg
    })
  },
  addLike: function () {
    if (this.data.isLike) {
      this.setData({
        isLike: !this.data.isLike,
        likeNum: this.data.likeNum - 1
      })
    } else {
      this.setData({
        isLike: !this.data.isLike,
        likeNum: this.data.likeNum + 1
      })
    }
  },

  navigateToLocation: function () {
    let { latitude, longitude } = this.data;
    wx.openLocation({
      latitude: latitude,
      longitude: longitude,
      scale: 28,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { }
    });
  },

  getPavilionDetail: function () {
    let pavilionId = this.data.pavilionId;
    request["getPavilionDetail"]({
      pavilionId: pavilionId
    },"", res => {
      let { data: pavilionDetail } = res.data;
      let { description, relatedActivities, openTime } = pavilionDetail;

      let lessRelatedActivities = [];
      
      relatedActivities.forEach((currentValue) => {
        if (currentValue.product) {
          currentValue.product.link = escape(currentValue.product.link);
          currentValue.product.imageUrl = escape(currentValue.product.imageUrl);
        }
      })
      this.setData({
        pavilionDetail,
        relatedActivitiesLength: pavilionDetail.relatedActivities.length,
        relatedActivities
      });
      WxParse.wxParse('description', 'html', description, this, 5);
      WxParse.wxParse('openTime', 'html', openTime, this, 5);
    })
  },
  clickCell: function () {
    this.setData({
      active: !this.data.active
    })
  },
 


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

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

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

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

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

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

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