<template>
  <div id='app' class="auto select-overspread form-horizontal">
    <div class="auto">
      <div class="col-sm-3 form-input-group">
        <label class="control-label">安检员</label>
        <v-select :value.sync="model.name" v-model='model.name'
                  :value-single="true"
                  :options='checkers' placeholder='安检员'
                  close-on-select ></v-select>
      </div>
      <div class="col-sm-3 form-input-group">
        <label class="control-label" >时间</label>
        <datepicker placeholder="时间"
                    :value.sync="model.date"
                    v-model="model.date"
                    :format="'yyyy-MM-dd'">
        </datepicker>
      </div>
      <div class="col-sm-2" >
        <button class="btn btn-primary btn-block" v-on:click="getData">查询</button>
      </div>
    </div>
  </div>
</template>

<script>
  import co from 'co'
  let select = function * (self) {
    let getGasman = yield self.$resetpost('/rs/search', {
      source: 'this.getParentByType($department$).getAllChildrens().where(row.getAttributes().get($rolestr$).indexOf($安检员$) != -1))',
      userid: self.$login.f.id
    }, {resolveMsg: null, rejectMsg: null})
    console.log("安检员000000", getGasman.data)
    getGasman.data.forEach((checker)=>{
      self.checkers.push({label:checker.name,value:checker.name})
    })
    console.log("安检员111111", getGasman.data)
  }

  export default {
    props:['outerurl','filiale'],
    data () {
      return {
        url:this.outerurl,
        subcompany :this.filiale,
        condition: '',
        model:{},
        checkers:[]
      }
    },
    watch:{
      outerurl(newValue){
        this.url = newValue;
      }
    },
    methods: {
      getData: function () {
        // 调用子组件的方法,拼接条件
        // this.$refs.search.search();
        // 向后台发起请求
        if(!this.model.name){
          this.$showAlert('请选择安检员!!!','warning',900)
          return
        }
        if(!this.model.date){
          this.$showAlert('请选择时间!!!','warning',900)
          return
        }
        this.$http.post(this.url, {data:{name: this.model.name,date:this.model.date}})
          .then(respose => {
              // 拼接结果为需求固定格式
              let rs = {name:'路线',points:[]}
              respose.data.forEach((item,index)=>{
                let r ={name:'1',lnglat:[]}
                r.lnglat = [item.longitude,item.latitude]
                rs.points.push(r)
              })
              this.data = rs
              this.$emit('input',this.data)
            },
            (error)=>{
              console.log("请求失败！"+JSON.stringify(error));
            }
          )
      }
    },
    watch: {
      'f_fengongsi' (val) {
        this.$emit('getfengongsi',val)
      }
    },
    ready(){
      let gen = select(this)
      return co(gen)
    }
  }
</script>
