//Component Object

let LD = {
  name:'不限',
  id:''
}

import { bindInput } from '../../utils/utils'


Component({
  properties: {
    arr:{
      type:Array,
      value:[],
      observer: function() {
        
      }
    },
    active:{
      type:String,
      value:'',
      observer: function() {
        
      }
    },
    
    city:{
      type:String,
      value:'',
      observer: function(val) {
        this.setData({
          selectObj:{
            quyu: {
              name:val,
              id:''
            },
            didian: LD,
            xianshi: LD
          }
        })
      }
    }
  },
  data: {
    selectObj:{},
    min:'',
    max:''
  },
  methods: {
    bindInput,
    handleClick(e){
      console.log(this.properties.arr)
      let {type,row} = e.currentTarget.dataset
      let tmp = {}
      tmp[type] = row
      let obj =  {
        selectObj:Object.assign(this.data.selectObj,tmp)
      }
      if (type==='quyu') {
        obj = {
          selectObj:Object.assign(this.data.selectObj,{
            didian: LD,
            xianshi:LD
          })
        }
      }
      if (type==='didian') {
        obj = {
          selectObj:Object.assign(this.data.selectObj,{
            xianshi: LD
          })
        }
      }
      if (type === 'jiage') {
        obj = {
          selectObj:Object.assign(this.data.selectObj,tmp),
          minjiage: '',
          maxjiage: ''
        }
      }
      if (type === 'jushi') {
        obj = {
          selectObj:Object.assign(this.data.selectObj,tmp),
          minjushi: '',
          maxjushi: ''
        }
      }
      if (type === 'yushi') {
        obj = {
          selectObj:Object.assign(this.data.selectObj,tmp),
          minyushi: '',
          maxyushi: ''
        }
      }
      Object.keys(this.data.selectObj).forEach(item=>{
        let i =this.data.selectObj[item]
        i.name = i.name.replace('不限','')
      })
      this.setData(obj)
      this.triggerEvent('selecthandle',{
        type,
        selectObj:this.data.selectObj
      })
    },
    comfirm(e){
      let {type} = e.currentTarget.dataset
      let tmp = {}
      let min =this.data['min'+type]
      let max =this.data['max'+type]
      tmp[type] = (!isNaN(min)&&!isNaN(max))?`${min}#${max}`:''
      
      // console.log(tmp);
      // let test = new RegExp(/\D/g)
      
      this.triggerEvent('comfirmhandle',tmp)
    }
  },
  created: function() {

  },
  attached: function() {

  },
  ready: function() {

  },
  moved: function() {

  },
  detached: function() {

  }
});
  