// pages/freeTravel/freeList/freeList.js
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLogin: app.isLogin,
    site: {
      companyId: app.state.companyId,
      cityId: app.state.cityId,
      siteName: app.state.siteName,
    },
    dates: [],
    isShowType:1,
    //开始时间
    sDate:'',
    eDate:'',
    datecount: [
      {
        id: 1,
        name: "1天"
      }, {
        id: 2,
        name: "2天"
      }, {
        id: 3,
        name: "3天"
      }, {
        id: 4,
        name: "4天"
      }, {
        id: 5,
        name: "5天"
      }, {
        id: 6,
        name: "6天"
      }, {
        id: 7,
        name: "7-8天"
      }, {
        id: 9,
        name: "9-10天"
      }, {
        id: 10,
        name: "10天以上"
      },
    ],
    ScreenStatus: false,
    listmsg: {
      minTripDay: -1,
      maxTripDay: -1,
      pageIndex: 1,
      pageSize: 10,
      lineId: 0,
      lineTeamId: 0,
      dayNum: -1,
      monthdate: [],
      priceTag: [],
      startCityId: 0,
      cityId: app.state.cityId,
      startDate: '',
      endDate: '',
      minPrice: '',
      maxPrice: '',
      companyId: app.state.companyId,
      priceOrderByField: 0,
      searchKey: '',
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    let City = this.selectComponent('#CityComp');
    City.getCityList();
    this.getThemeTag();
  },
  ChangeSite(val) {
    console.log(val.detail);
    this.setData({
      site: val.detail
    })
    this.onLoad();
  },
  ScreenOpen() {
    this.setData({
      ScreenStatus: true,
    })
  },
  CloseScreen(e) {
    if (e.target.dataset.target == "self") {
      this.setData({
        ScreenStatus: false,

      })
    }
  },
  // 获取主题标签
  getThemeTag() {
    let tagmsg = {
      name: 'theme',
      code: 1,
    }
    let that = this;
    app.$api('travel_get_GetTravelPriceTag', tagmsg).then(res => {
      console.log(res);
      let ThemeTagList = res;
      ThemeTagList.forEach(item => {
        item.show = 0;
      })
      that.setData({
        ThemeTagList: ThemeTagList
      })
    }).catch(err => { })
  },
  PriceTag(e) {
    let that = this;
    console.log(e.target.dataset.tag);
    let listmsg = that.data.listmsg;
    let tag = e.target.dataset.tag;
    let index = e.target.dataset.index;
    let priceTag = that.data.listmsg.priceTag;
    let ThemeTagList = that.data.ThemeTagList;
    priceTag = [];
    that.setData({
      listmsg: listmsg
    })

    ThemeTagList.forEach(item => {
      item.SNO = 0;
    })
    if (index != 0) {
      priceTag.push(tag.ID);
      that.data.listmsg.priceTag = priceTag;
      priceTag.forEach(tag => {
        ThemeTagList.forEach(item => {
          if (tag == item.ID) {
            item.SNO = -1;
          }
        })
      })
      that.setData({
        ThemeTagList: ThemeTagList,
        listmsg: listmsg
      })
      console.log("listmsg", listmsg);
    }
    this.GetList();
  },
  GetList() {

  },
  // 点击改变出游方式
  changeType(e){
    let type=e.target.dataset.type;
    this.setData({
      isShowType: type
    })
  },
  //选择时间
  bindDateChange(e){
    console.log(e);
    let sDate = e.detail.value;
    console.log(sDate)
    this.setData({
      sDate:sDate
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})