<template>
  <div style="flex:1;" class="flex">
    <criteria-paged :model="model"  v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:criteria>
        <div novalidate class="row form-inline auto select-overspread" partial>
          <div class="form-group">
             <input type="text" class="form-control" v-model="model.f_plan_name" id="f_plan_name"
                    placeholder="计划名称"
             condition="f_plan_name like '%{}%'">
          </div>
          <div class="form-group">
             <v-select :value.sync="model.f_issued"
                 :options='$parent.$parent.op_issued' placeholder='是否下发'
                 close-on-select clear-button
                 v-model="model.f_issued" condition="f_issued='{}'"> </v-select>
          </div>
          <div class="form-group">
              <v-select id="c_plan_year" :value.sync="model.f_plan_year"
              :options='$parent.$parent.c_year_list' close-on-select clear-button
              v-model="model.f_plan_year" placeholder='计划年份'
              condition="f_plan_year={}"> </v-select>
          </div>
          <div class="form-group">
              <v-select id="c_plan_month" :value.sync="model.f_plan_month" placeholder='计划月份'
              :options='$parent.$parent.c_month_list' close-on-select clear-button
              v-model="model.f_plan_month" condition="f_plan_month='{}'"> </v-select>
          </div>
          <div class="form-group">
            <v-select id="checker" :value.sync="$parent.$parent.checker" placeholder='安检员'
                      :options='$parent.$parent.checkers' close-on-select clear-button> </v-select>
          </div>
          <div class="form-group">
            <button class="btn btn-success width-80" @click="search()">查询</button>
          </div>
        </div>
      </criteria>

      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>计划名称</th>
            <th>是否下发</th>
            <th>计划年月</th>
            <th>安检员</th>
          </tr>
        </template>
        <template partial='body'>
          <td>{{row.f_plan_name}}</td>
          <td>{{row.f_issued}}</td>
          <td>{{row.f_plan_year}}-{{row.f_plan_month}}</td>
          <td>{{row.f_checker}}</td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
  import co from 'co'
  import { PagedList } from 'vue-client'
  import Vue from 'vue'
  import * as Util from '../Util'

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('获取安检员', getGasman)
  getGasman.data.forEach((checker)=>{
    self.checkers.push({label:checker.name,value:checker})
  })
}
export default {
  title: '预约计划下发',
  data () {
    let options = []
    let year = (new Date()).getFullYear()
    for(let i = year - 8; i <= year +1; i++ )
      options.push({label: i+'', value: i+''})
    let moptions = []
    for(let i=1; i<=12; i++)
      moptions.push({label: i + '', value: i + ''})
    let model = new PagedList('api/af-safecheck/sql/预约计划下发', 20, { items: '"*"', tablename: '"t_check_plan"', groupitem: '""',
    orderitem: '"f_plan_month"', f_checker:'this.chosenOrg.name', f_checker_id: 'this.chosenOrg.id', f_subcompany: 'this.f_subcompany' })
    model.f_subcompany = this.$login.f.f_fengongsi
    model.chosenOrg = {id:0, name: ''}
    return {
      checker:this.$login.f,
      checkers:[],
      chosenOrg: {id:0,name:''},
      f:this.$login.f,
      c_year_list: options,
      c_month_list: moptions,
      model: model,
      op_issued: [
        {label: '是', value: '是'},
        {label: '否', value: '否'}
      ]
    }
  },
  ready(){
    let gen = select(this)
    return co(gen)
  },
  watch:{
    'checker'(){
      console.log("f_checker",this.checker)
      this.model.chosenOrg = this.checker[0]
    }
  },
  computed: {
    selected () {
      return this.$refs.paged.$refs.grid.selected
    }
  }
}
</script>
