<template>
  <div>
    <form>
      <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>
    </form>
    <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>
    <div style="height:50px;"></div>
  </div>
</template>

<script>
import co from 'co'
import Vue from 'vue'

let aggCheckerTask = function * (self) {
    let result = yield self.$resetpost(Vue.url + 'sql/统计维修员月任务?pageNo=1&pageSize=9999', {
        data: {
            id: Vue.user.id,
            org_id: Vue.user.parentid,
            f_subcompany: Vue.user.f_subcompany,
            f_ym: self.c_plan_year[0] + '-' + (self.c_plan_month[0].length > 1 ? self.c_plan_month[0] : '0' + self.c_plan_month[0])
        }
    }, {
        resolveMsg: null,
        rejectMsg: '提取任务出错'
    })
    self.$set("model.rows", result.data)
}

export default {
  title: '维修员月任务',
  data() {
    let options = []
    let year = (new Date()).getFullYear()
    options.push({label: year+'', value: year+''})
    year++
    options.push({label: year+'', value: year+''})
    let moptions = []
    for(let i=1; i<=12; i++)
      moptions.push({label: i + '', value: i + ''})
    return {
      c_plan_year: options[0].value,
      c_year_list: options,
      c_month_list: moptions,
      c_plan_month: moptions[new Date().getMonth()].value,
      model: {
        rows: [],
      }
    }
  },
  ready () {
    this.search()
  },
  methods: {
    search () {
      let fp = aggCheckerTask(this)
      co(fp)
    }
  }
}
</script>
