// pages/components/deep-select/index.js
import Toast from '@vant/weapp/toast/toast';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    columns:{
      type:Array
    },
    title:{
      type:String
    },
    title1:{
      type:String
    },
    
  },
  /**数据监听 */
  observers: {
    columns: function (val) {
      console.log(val)
      if(val.length > 0){
        this.setData({
          floorList:val[0].floorList
        })
      }
    },
   
  },
  lifetimes: {
    created: function(){
    //在组件实例刚刚被创建时执行,注意此时不能调用 setData
    },
    attached: function () {
        //在组件实例进入页面节点树时执行
      
    },
    ready: function () {
        // 在组件在视图层布局完成后执行
        

    },
    detached: function () {
        // 在组件实例被从页面节点树移除时执行
    },
    
  },
  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    
    startDateData:[],
    endDateData:[],

    condition:{
      floorNum:'',
      buildingNum:'',
      startDate:'',
      endDate:'',
    },
    floorList:[]
   
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //打开筛选弹窗
    showPopup() {
   
      this.setData({ show: true });
    },
    //关闭筛选弹窗
    onClose() {
      this.setData({ show: false });
    },

    //单元楼
    onBuildSelectChange(event){   
        this.setData({
          'condition.buildingNum': event.detail.value.id,
          floorList:event.detail.value.floorList
        })
    },
    //楼层
    onFloorSelectChange(event){   
      this.setData({
       'condition.floorNum': event.detail.value.id,
      })
  },


    //开始日期
    onStartDate(e){
        this.setData({
          'condition.startDate': e.detail,
        })
    },
    //结束日期
    onEndDate(e){
      this.setData({
        'condition.endDate': e.detail,
      })
    },
    
    //确认按钮
    onConfirm(){
      var start = new Date(this.data.condition.startDate)
      var end = new Date(this.data.condition.endDate)
      if(start > end){
        Toast.fail('开始时间不能大于结束时间');
      }else{
        this.triggerEvent('screen',this.data.condition)
        this.setData({ show: false});
      } 
    }
  }
})