let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: false,
    autoplay: false,
    interval: 5000,
    duration: 1000,
    idDes: '',
    data: {},
    tcState:false,
    msg:{
      adultNum: 0,
      childNum:0,
      diningId: 0,
      mealId: 0,
      priceId: 0,
    },
    dateMsg:{
      idDes:'',
    },
    tcActive:-1,
    mealName:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    console.log(options);
    if (options.idDes) {
      that.data.msg.diningId = options.id;
      that.setData({
        idDes: decodeURIComponent(options.idDes),
        msg:that.data.msg
      })
    }
    // that.data.msg.diningId = 1640;
    // that.setData({
    //   idDes: decodeURIComponent("6jijCeixL9w%3D%0A"),
    //   msg: that.data.msg
    // })
    that.getData();
  },
  yD(){
    let that=this;
    let msg=that.data.msg;
    if (msg.adultNum + msg.childNum<1){
      wx.showToast({
        title: "至少选择一人",
        icon: 'none',
        duration: 1000
      })
      return;
    }
    if (msg.mealId==0){
      wx.showToast({
        title: "请选择套餐",
        icon: 'none',
        duration: 1000
      })
      return;
    }
    wx.setStorage({
      key: "Foodmsg",
      data: that.data.msg,
    })
    wx.setStorage({
      key: "FooddateMsg",
      data: that.data.dateMsg,
    })
    wx.navigateTo({
      url: '/pages/local/FoodOrder/FoodOrder',
    })

  },
  getMeal(e){
    let item = e.currentTarget.dataset.item;
    let index = e.currentTarget.dataset.index;
    this.data.dateMsg.idDes=item.idDes;
    this.data.msg.mealId=item.id;
    this.data.tcActive = index;
    this.setData({
      dateMsg: this.data.dateMsg,
      msg: this.data.msg,
      tcActive: this.data.tcActive,
      mealName: item.mealName
    })
  },
  subtract(e) {
    let type = e.target.dataset.type;
    if(type=="cr"){
      let adultNum = this.data.msg.adultNum;
      adultNum > 0 ? adultNum-- : 0;
      this.data.msg.adultNum = adultNum
    }else{
      let childNum = this.data.msg.childNum;
      childNum > 0 ? childNum-- : 0;
      this.data.msg.childNum = childNum
    }
    
    this.setData({
      msg: this.data.msg
    })
  },
  add(e) {
    let type = e.target.dataset.type;
    if (type == "cr") {
      let adultNum = this.data.msg.adultNum;
      adultNum = ++adultNum;
      this.data.msg.adultNum = adultNum
    }else{
      let childNum = this.data.msg.childNum;
      childNum = ++childNum;
      this.data.msg.childNum = childNum
    }

    
    this.setData({
      msg: this.data.msg
    })
  },
  inputPurchase(e) {
    let type = e.target.dataset.type;
    let val = e.detail.value;
    if (type == "cr") {
      this.data.msg.adultNum = val;
    }else{
      this.data.msg.childNum = val;
    }
    
    
    this.setData({
      msg: this.data.msg
    })
  },
  goUrl(e) {
    let item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '/pages/local/TicketOrder/TicketOrder?idDes=' + encodeURIComponent(item.idDes),
    })
  },
  openTcView(){
    this.setData({
      tcState:true,
    })
  },
  closeTcView(e) {
    let val = e.target.dataset.self;
    if(val=="self"){
      this.setData({
        tcState: false,
      })
    }
    
  },
  getData() {
    app.$apiJavaNew('/api/b2b/food/getFoodInfo', { idDes: this.data.idDes }).then(res => {
      console.log("res",res);
      this.setData({
        data: res
      })


    }).catch(err => { })
  },


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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})