<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>
        </tr>
      </template>
      <template partial='body'>
        <td>{{row.f_checker}}</td>
        <td>{{row.task}}</td>
        <td>{{row.accomplished}}</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(`${this.$androidUtil.getProxyUrl()}/rs/sql/统计安检员月任务?pageNo=1&pageSize=9999` , {
        data: {
            id: Vue.user.id,
            org_id: Vue.user.parentid,
            f_plan_year: self.c_plan_year[0],
            f_plan_month: self.c_plan_month[0],
            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>
