
let app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    msg: {
      teamType: 0,
      idDes: "",
      tcid: "",
    },
    imgCover: [],
    dataList: {},
    isLogin: app.isLogin,
    toDayObj: {},
    priceList: [],
    FlightList: [],
    feature: {},
    dayList: [],
    serve:false,
  },




  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this;
    let msg = {
      teamType: 0,
      idDes: "",
      tcid: "",
      cityId: app.state.cityId,
    }
    if (options) {
      console.log("options", options)
      msg.configId = decodeURIComponent(options.idDes);
      msg.tcid = options.tcid;
      // msg.configId = options.idDes = decodeURIComponent("5aEwngdTBnM%3D%0A");
      // msg.tcid = options.tcid = "3458";
      if (options.teamType){
        msg.teamType = options.teamType; 
      }
      that.setData({
        msg: msg
      })
      this.getData();
    }

  },
  getData() {
    let that = this;
    app.$api('b2b_get_GetB2BTravelInfoV1', that.data.msg).then(res => {
      
      let data = res;
      data.priceList.forEach(item => {
        item.date = item.startDate.split("-")[1] + "/" + item.startDate.split("-")[2];
      })
      let FlightList = "";
      FlightList = data.currentPriceInfo && data.currentPriceInfo.priceFlight ? data.currentPriceInfo.priceFlight : '';
      data.dayList.forEach(dayitem => {
        dayitem.trafficList = [];
        dayitem.ScenicList = [];
        dayitem.HotelList = [];
        dayitem.RestaList = [];
        dayitem.tipList = [];
        dayitem.title = {};
        dayitem.dayArray.forEach(typeitem => {
          if (typeitem.type == 1) {
            dayitem.trafficList.push(typeitem);
          }
          if (typeitem.type == 2) {
            dayitem.ScenicList.push(typeitem);
          }
          if (typeitem.type == 3) {
            dayitem.HotelList.push(typeitem);
          }
          if (typeitem.type == 4) {
            dayitem.RestaList.push(typeitem);
          }
          if (typeitem.type == 6) {
            dayitem.tipList.push(typeitem);
          }
          if (typeitem.type == 6) {
            dayitem.title = typeitem;
          }
        })
      });
      that.setData({
        imgCover: JSON.parse(res.imgCover),
        dataList: res,
        toDayObj: data.currentPriceInfo,
        priceList: data.priceList,
        FlightList: FlightList,
        feature: data.feature.tripImageList,
        dayList: data.dayList,
      })
      WxParse.wxParse('feeInclude', 'html', res.feature.feeInclude, that, 0);
      WxParse.wxParse('warmTip', 'html', res.feature.warmTip, that, 0);
      WxParse.wxParse('visaRemark', 'html', res.feature.warmTip, that, 0);
      WxParse.wxParse('b2BRemark', 'html', res.feature.warmTip, that, 0);
      
      
    }).catch(err => {})
  },
  closeServe(e){
    let self=e.target.dataset.self;
    if(self=="self"){
      this.setData({
        serve:false
      })
    }
  },
  oPenServe(){
    this.setData({
      serve: true
    })
  },

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

  },

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

  },
  StartYd() {
    let msg = this.data.msg;
    wx.navigateTo({
      url: '/pages/GroupTour/ChDateNum/ChDateNum?idDes=' + encodeURIComponent(msg.configId) + "&tcid=" + msg.tcid + "&teamType=" + msg.teamType,
    })
  },
  serveView(){

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

  },

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

  },

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

  },

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

  },

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

  }
})