hv_behavior.js 1.35 KB
// components/reserve/search/how/hv.js
import util from '../../../../utils/util'
module.exports = Behavior({
  properties: {
    ckdata:{
      type:Object,
      val:null,
    },
  },
  data: {
    spi:-1
  },
  observers: {
    'ckdata': function() {
      this.checkedDefEvent()
    }
  },
  methods: {
    checked(e,hasCurrent=false){
      let index=util.attr(e,'index')
      let val=util.attr(e,'val')
      let type=util.attr(e,'type')
      let obj={
        spi:index,
      }
      if(hasCurrent){
        let current=index-2
        if(type=='date'){
          current=current>10?10:current
        }else if(type=='pnum'){
          current=current>26?26:current
        }
        obj.current=current>-1?current:0
      }
      this.setData(obj)
      this.triggerEvent('event',{index,val,type})
    },
    checkedDefEvent(){
      console.log('this.type',this.type)
      let type=this.type
      let ckdata = {}
      if (!this.data.ckdata) {//初始化值
        if(type == 'dur') return;
        let index, val
        if (type == 'pnum') {
          index = 3
          val = this.data.items[index]
        } else if (type == 'date') {
          index = 0
          val = this.data.items[index]
        }
        ckdata = {index, val, type}
      }else{
        ckdata = this.data.ckdata
      }
      this.checked({currentTarget:{dataset:ckdata}},true)
    },
  }
})