let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    IMG_NAME: app.IMG_NAME,
    index: 0,
    array: ['全部', '<=150㎡', '150-300㎡', '300-500㎡', '500-800㎡', '>=800'],
    currentTab: 0,
    homelist: [],
    name: '',
    minimum: '',
    maximum: '',
    active: '全部'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow() {
    this.getList()
  },

  onReady() {
    this.animation = wx.createAnimation()
  },

  isShowRule() {
    this.setData({
      isRuleTrue: false
    })
  },

  translate() {
    this.setData({
      isRuleTrue: true
    })
    this.animation.translate(-245, 0).step()
    this.setData({
      animation: this.animation.export()
    })
  },

  reset() {
    this.setData({
      active: '全部'
    })
  },

  submit() {
    let active = this.data.active
    if (active == '<=150㎡') {
      this.setData({
        maximum: 150
      })
    } else if (active == '150-300㎡') {
      this.setData({
        minimum: 150,
        maximum: 300
      })
    } else if (active == '300-500㎡') {
      this.setData({
        minimum: 300,
        maximum: 500
      })
    } else if (active == '500-800㎡') {
      this.setData({
        minimum: 500,
        maximum: 800
      })
    } else if (active == '>=800') {
      this.setData({
        minimum: 800
      })
    }
    this.getList(1)
  },

  tryDriver(e) {
    let name = e.currentTarget.dataset.name
    this.setData({
      active: name
    })
  },

  bindPickerChange(e) {
    let index = e.detail.value
    this.setData({
      index
    })

    switch (index) {
      case 1:
        this.setData({
          maximum: 150
        })
        break;
      case 2:
        this.setData({
          minimum: 150,
          maximum: 300
        })
        break;
      case 3:
        this.setData({
          minimum: 300,
          maximum: 500
        })
        break;
      case 4:
        this.setData({
          minimum: 500,
          maximum: 800
        })
        break;
      case 5:
        this.setData({
          minimum: 800
        })
    }
    this.getList()
  },

  getList(e) {
    var that = this
    app.AjaxRequest('get', {
      'content-type': 'application/json',
      'Authorization': 'Bearer ' + app.Getopenid()
    }, '/room/list', {
      name: that.data.name,
      minimum: that.data.minimum,
      maximum: that.data.maximum
    }, function (res) {
      if (res.code == 0) {
        if (e) {
          that.setData({
            isRuleTrue: false
          })
          that.animation.translate(0, 0).step()
          that.setData({
            animation: that.animation.export()
          })
        }
        that.setData({
          homelist: res.rows,
          minimum: '',
          maximum: ''
        })
      }
    })
  },

  navDetail(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../office/detail/detail?id=' + id,
    })
  },

  getName(e) {
    this.setData({
      name: e.detail.value
    })
  },

  search() {
    this.getList(this.data.name)
  }
})