<template>
    <div>
        <criteria-paged :model="model" v-ref:paged>
            <criteria partial='criteria' class="search_area" @condition-changed='$parent.search'>
                <!--<form class="form-inline" partial>-->
                <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>

                    <div class="col-sm-3 ">
                        <label class="font_normal_body">起始时间</label>
                        <datepicker
                                :value.sync="$parent.$parent.f_check_start"
                                placeholder='起始时间' style="width:60%"
                                :disabled-days-of-week="[]"
                                :format="'yyyy-MM'"
                                :select-month="true"
                                :show-rest-button="reset">
                        </datepicker>
                    </div>
                    <div class="col-sm-3 ">
                        <label class="font_normal_body">结束时间</label>
                        <datepicker
                                :value.sync="$parent.$parent.f_check_end"
                                placeholder='结束时间' style="width:60%"
                                :disabled-days-of-week="[]"
                                :format="'yyyy-MM'"
                                :select-month="true"
                                :show-rest-button="reset">
                        </datepicker>
                    </div>
                    <div class="col-sm-3 ">
                        <label class="font_normal_body">是否有隐患</label>
                        <v-select style="width:60% "
                                  class="select select_list"
                                  :value.sync="model.f_has_defect"
                                  v-model="model.f_has_defect"
                                  :options='$parent.$parent.hasDefectOptions'
                                  placeholder='片区/管理站'
                                  condition="ua.f_slice_area like '%{}%'"
                                  close-on-select>
                        </v-select>
                    </div>
                    <div class="col-sm-4">
                        <role-selector-safe
                                :left-width="'55%'"
                                :right-width="'55%'"
                                role-name="安检员"
                                role-lable="安&nbsp;检&nbsp;员"
                                @re-res="$parent.$parent.getRes"
                                :value.sync="model.f_checker_id"
                                v-model="model.f_checker_id"
                                condition="c.f_checker = '{}'">
                        </role-selector-safe>
                    </div>
                    <div class="col-sm-2 ">
                        <div class="button_spacing" style="float: right; margin-top: 8px;"
                             :class="{'button_shrink_left':$parent.$parent.$parent.showItem,'button_shrink_right':!$parent.$parent.$parent.showItem}"
                             @click="$parent.$parent.hiddenr()"></div>
                        <button type="button" style="float: right; margin-top: 8px;" 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 class="list_area table_sy">
                <template partial='head'>
                    <tr>
                        <th>安检员</th>
                        <th>计划数</th>
                        <th>已检</th>
                        <th>未检</th>
                    </tr>
                </template>
                <template partial='body'>
                    <td style="text-align: center">{{row.f_checker}}</td>
                    <td style="text-align: center">{{row.c}}</td>
                    <td style="text-align: center">{{row.checked}}</td>
                    <td style="text-align: center">{{row.unchecked}}</td>
                </template>
                <template partial="foot">
                    <td style="text-align: center"><span><b>合计：</b></span></td>
                    <td style="text-align: center">{{model.sums.c}}</td>
                    <td style="text-align: center">{{model.sums.checked}}</td>
                    <td style="text-align: center">{{model.sums.unchecked}}</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'


  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_filialeids: 'this.f_filialeids '
      })
      model.f_plan_year = year + ''
      model.f_filialeids = '('+this.$login.f.orgid+')'
      model.chosenOrg = {id: 0, name: ''}
      return {
        checker: this.$login.f,
        checkers: [],
        checkersname: [],
        hasDefectOptions:[{lable:'全部',value:''},{lable:'有隐患',value:'有隐患'},{lable:'无隐患',value:'无隐患'}],
        f: this.$login.f,
        model: model,
        c_year_list: options,
        f_check_start:'',
        f_check_end: ''
      }
    },
    methods: {
      hiddenr() {
        this.$parent.showItem = !this.$parent.showItem
      },
      search(args) {
        if (this.f_check_start) {
          args.condition += ` AND f_plan_year >= ${this.f_check_start.substr(0,4)} `
          args.condition += ` AND f_plan_month >= ${this.f_check_start.substr(5,2)} `
        }
        if (this.f_check_end) {
          args.condition += ` AND f_plan_year <= ${this.f_check_end.substr(0,4)} `
          args.condition += ` AND f_plan_month <= ${this.f_check_end.substr(5,2)} `
        }
        this.model.search(args.condition, args.model)
        //tag
        //tag
      },
      getRes(obj){
        this.model.f_filialeids = this.$login.convertToIn(obj.resids);
        //tag
      }
    },
    ready() {
      this.model.id = this.$login.f.id
      this.model.f_subcompany = this.$login.f.f_fengongsi
      this.model.f_filialeid = this.$login.f.orgid
    },

    watch: {
      'checker'() {
        // //tag
        //tag
        this.model.chosenOrg = this.checker[0]
      },
      'model.rows.length'() {
        // 如果查询无结果，将合计置为0
        if(this.model.rows.length < 1){
          this.model.sums.c = 0
          this.model.sums.checked = 0
          this.model.sums.unchecked = 0
        }
      }
    },
    computed: {
      selected() {
        // //tag
        // this.$parent.showItem=!this.$parent.showItem
        return this.$refs.paged.$refs.grid.selected
      }
    }
  }
</script>
