<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' class="search_area" @condition-changed='$parent.search' v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial @keyup.enter="search()">
          <div class="row">
            <div :class="{'form-group col-sm-6':$parent.$parent.$parent.showItem,'form-group col-sm-4':!$parent.$parent.$parent.showItem}" style="margin: 0">
              <role-selector-safe
                role-name="安检员"
                :value-multiple="true"
                :value-close="false"
                role-lable="安&ensp;检&ensp;员"
                @re-res="$parent.$parent.getRes"
                :value.sync="model.f_checker_id"
                v-model="model.f_checker_id">
              </role-selector-safe>
            </div>
            <div :class="{'form-group col-sm-3':$parent.$parent.$parent.showItem,'form-group col-sm-2':!$parent.$parent.$parent.showItem}">
              <label class="font_normal_body">安检起始</label>
              <datepicker
                :value.sync="$parent.$parent.f_start_time"
                placeholder='安检起始' style="width:60%"
                :show-rest-button="reset">
              </datepicker>
            </div>
            <div :class="{'form-group col-sm-3':$parent.$parent.$parent.showItem,'form-group col-sm-2':!$parent.$parent.$parent.showItem}">
              <label class="font_normal_body">安检截止</label>
              <datepicker
                :value.sync="$parent.$parent.f_end_time"
                placeholder='安检截止' style="width:60%"
                :show-rest-button="reset">
              </datepicker>
            </div>
            <div style="width: auto;margin-top:8px;float: right" :class="{'form-group col-sm-3':$parent.$parent.$parent.showItem,'form-group col-sm-2':!$parent.$parent.$parent.showItem}">
              <export-excel-safe   :data="$parent.$parent.searchData"
                                   :field="$parent.$parent.excelHeaders"
                                   progress="safeGetExportProgress"
                                   sqlurl="rs/logic/SafeExportExcel"
                                   sql-name="YuYueplanCount"
                                   template-name='预约安检安检明细'
              ></export-excel-safe>
              <button type="button" class="button_search button_spacing" @click="search()" @keyup.enter="search()">查询</button>
              <div class="button_spacing"
                   :class="{'button_shrink_left':$parent.$parent.$parent.showItem,'button_shrink_right':!$parent.$parent.$parent.showItem}"
                   @click="$parent.$parent.hiddenr()"></div>
            </div>
          </div>
        </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>
            <th>预约安检拒检</th>
            <th>预约安检激光检测</th>
            <th>入户率</th>
            <th>安检率</th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center">{{row.f_checker_name}}</td>
          <td style="text-align: center">{{row.count}}</td>
          <td style="text-align: center">{{row.ruhu}}</td>
          <td style="text-align: center">{{row.daofang}}</td>
          <td style="text-align: center">{{row.jujian}}</td>
          <td style="text-align: center">{{row.jiance}}</td>
          <td style="text-align: center">{{row.ruhu_rate}}</td>
          <td style="text-align: center">{{row.check_rate}}</td>
        </template>
        <template partial="foot">
          <td style="text-align: center"><span><b>合计：</b></span></td>
          <td style="text-align: center">{{model.sums.count}}</td>
          <td style="text-align: center">{{model.sums.ruhu}}</td>
          <td style="text-align: center">{{model.sums.daofang}}</td>
          <td style="text-align: center">{{model.sums.jujian}}</td>
          <td style="text-align: center">{{model.sums.jiance}}</td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>
<script>
import {PagedList} from 'vue-client'

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/YuYueplanCount', 20, {}, {count:'',ruhu:'',daofang:'',jujian:'',jiance:''})
    model.f_filialeids = `('${this.$login.f.orgid}')`
    return {
      excelHeaders:{
        'f_checker_name': '安检员',
        'count': '总数',
        'ruhu': '入户',
        'jujian': '拒检',
        'daofang': '到访不遇',
        'jiance': '激光检测',
        'ruhu_rate':'入户率',
        'check_rate':'安检率'
      },
      checker: this.$login.f,
      checkers: [],
      checkersname: [],
      checkStates: this.$appdata.getParam('安检状态'),
      f: this.$login.f,
      criteriaShow: false,
      model: model,
      c_year_list: options,
      f_check_start:'',
      f_check_end: '',
      f_start_time:'',
      f_end_time:''
    }
  },
  methods: {
    handleKeyUp(e) {
      if (e.key === 'Enter') {
        this.selfsearch()
      }
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
    hiddenr() {
      this.$parent.showItem = !this.$parent.showItem
    },
    search(args) {
      if (args.condition) {
        args.condition += ` and tcp.f_filialeid='${this.$login.f.orgid}'`
      }
      if (this.f_start_time) {
        args.condition += ` and tcp.f_upload_date>='${this.f_start_time}'`
      }
      if (this.f_end_time) {
        args.condition += ` and tcp.f_upload_date<='${this.f_end_time}'`
      }
      if(args.model.f_checker_id){
        args.condition += ` and tcp.f_checker_name in ${args.model.f_checker_id}`
      }
      this.model.search(args.condition, args.model)
    },
    getRes(obj){
      this.model.f_filialeids = this.$login.convertToIn(obj.resids);
    },
    selfsearch() {
      this.$refs.paged.$refs.cri.search()
    },
  },
  ready() {
  },
  beforeDestroy() {
    document.removeEventListener('keyup', this.handleKeyUp)
  },
  watch: {
    'model.rows.length'() {
      // 如果查询无结果，将合计置为0
      if(this.model.rows.length < 1 &&this. model.sums){
        this.model.sums.ruhu = 0
        this.model.sums.jujian = 0
        this.model.sums.daofang = 0
        this.model.sums.jiance=0
      }
    }
  },
  computed: {
  }
}
</script>
