<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search'>
        <!--<form class="form-inline" partial>-->
          <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
            <label class="control-label">年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;份</label>
            <v-select id="f_plan_year" :value.sync="$parent.$parent.model.f_plan_year" style="margin-top: 8px"
                      placeholder="年份" :options='$parent.$parent.c_year_list' close-on-select clear-button> </v-select>
          </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
            <label class="control-label">安&nbsp;&nbsp;检&nbsp;员</label>
            <v-select :value.sync="model.f_checker_id" v-model='model.f_checker_id'
                      :value-single="true" style="margin-top: 8px"
                      :options='$parent.$parent.checkersname' placeholder='安检员'
                      close-on-select
                      condition="c.f_checker = '{}'"></v-select>
          </div>
          <div class="form-group" style = "float:left;margin-top:8px">
            <button type="button" class="button_search button_spacing" @click="search()">查询</button>
          </div>
          <div>
            {{$parent.$parent.model.chosenOrg.fullname}}
          </div>
        <!--</form>-->
          </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>年份</th>
            <th>月份</th>
            <th>安检员</th>
            <th>计划数</th>
            <th>已检</th>
            <th>未检</th>
          </tr>
        </template>
        <template partial='body'>
          <td>{{row.f_plan_year}}</td>
          <td>{{row.f_plan_month}}</td>
          <td>{{row.f_checker}}</td>
          <td>{{row.c}}</td>
          <td>{{row.checked}}</td>
          <td>{{row.unchecked}}</td>
        </template>
        <template partial="foot">
          <td colspan="6"><span><b>计划项总数：{{ model.sums.c }}</b></span></td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>
<script>
  import { PagedList } from 'vue-client'
  import co from 'co'
  import Vue from 'vue'
  import * as Util from '../Util'

  let select = function * (self) {
    let getGasman = yield self.$resetpost('/rs/search', {
      source: 'this.getParentByType($organization$).getChildByName($安检员$).getUsers()',
      userid: self.$login.f.id
    }, {resolveMsg: null, rejectMsg: null})
    console.log('获取安检员', getGasman)
    getGasman.data.forEach((checker)=>{
      self.checkers.push({label:checker.name,value:checker})
    self.checkers.push({label:checker.name,value:checker})
    self.checkersname.push({label:checker.name,value:checker.name})
  })
    self.checkersname.push({label:'全部',value:''})
  }

  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 model = new PagedList('rs/sql/planCount', 20,
        {f_plan_year: 'this.f_plan_year[0]', f_checker: 'this.chosenOrg.name', f_subcompany: 'this.f_subcompany'}, {c: ''})
      model.f_plan_year = year + ''
      model.chosenOrg = {id:0, name: ''}
      return {
        checker:this.$login.f,
        checkers:[],
        checkersname:[],
        f:this.$login.f,
        model: model,
        c_year_list: options
      }
    },
    ready () {
      this.model.id = this.$login.f.id
      this.model.f_subcompany = this.$login.f.f_fengongsi

      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>
