<template>
  <div class="flex">
   <form class="form-inline">
      <div class="form-group">
        <label for="c_plan_year">年份：</label>
        <v-select id="c_plan_year" :value.sync="c_plan_year"
        :options='c_year_list' close-on-select clear-button></v-select>
        <label for="c_plan_month">月份：</label>
        <v-select id="c_plan_month" :value.sync="c_plan_month"
        :options='c_month_list' close-on-select clear-button></v-select>
        <button type="button" class="btn btn-default" @click="search()">查询</button>
      </div>
      <div class="form-group">
        部门:
        <chooser :userid.sync='f.id' resource-type="organization" :width='200' :select-data.sync='model.chosenOrg'></chooser>
      </div>
      {{model.chosenOrg.fullname}}
    </form>
    <div class="span">
      <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_repairman}}</td>
          <td>{{row.checked}}</td>
          <td>{{row.checking}}</td>
          <td>{{row.unchecked}}</td>
        </template>
      </data-grid>
    </span>
    <div style="height:50px;"></div>
  </div>
</template>

<script>
import { PagedList } from 'vue-client'
import Vue from 'vue'

export default {
  title: '维修员月任务',
  props: ['f'],
  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('rs/sql/跟踪维修员月任务', 20,
    {id: 'this.id', org_id: 'this.chosenOrg.id', f_plan_year: 'this.f_plan_year', f_subcompany: 'this.f_subcompany',
    f_plan_month: 'this.f_plan_month', f_ym: 'this.f_ym'})
    model.chosenOrg = {id:0}
    return {
      c_plan_year: year + '',
      c_year_list: options,
      c_month_list: moptions,
      c_plan_month: moptions[new Date().getMonth()].value,
      model: model
    }
  },
  ready () {
    this.model.id = this.f.id
    this.model.chosenOrg.id = this.f.parent.id
    this.model.f_plan_year = this.c_plan_year[0]
    this.model.f_plan_month = this.c_plan_month[0]
    this.model.f_subcompany = Vue.f_subcompany
    this.model.f_ym = this.c_plan_year[0] + '-' + (this.c_plan_month[0].length > 1 ? this.c_plan_month[0] : '0' + this.c_plan_month[0])
    this.$watch('c_plan_year', function (val) {
        this.model.f_plan_year = val[0]
        this.model.f_ym = val[0] + '-' + (this.c_plan_month[0].length > 1 ? this.c_plan_month[0] : '0' + this.c_plan_month[0])
    })
    this.$watch('c_plan_month', function (val) {
        this.model.f_plan_month = val[0]
        this.model.f_ym = this.c_plan_year[0] + '-' + (val[0].length > 1 ? val[0] : '0' + val[0])
    })
  },
  methods: {
    search () {
      this.model.rows = []
      this.model.search()
    }
  }
}
</script>
