<template>
  <div class="flex-row">
    <div class="basic-main">
      <criteria-paged :model="model" v-ref:paged>
        <criteria partial='criteria' class="search_area" @condition-changed='$parent.selfSearch' v-ref:criteria>
          <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <div class="row">
              <div class="form-group col-sm-2">
                <label class="font_normal_body">安检时间</label>
                <datepicker
                  :value.sync="model.f_start_time"
                  placeholder='开始时间' style="width: 60%"
                  :disabled-days-of-week="[]"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  v-model="model.f_start_time"
                  condition="f_offsite_time > ='{} 00:00:00'">
                </datepicker>
              </div>
              <div class="form-group col-sm-2">
                <label class="font_normal_body">安检时间</label>
                <datepicker
                  :value.sync="model.f_end_time"
                  placeholder='结束时间' style="width: 60%"
                  :disabled-days-of-week="[]"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  v-model="model.f_end_time"
                  condition="f_offsite_time <= '{} 23:59:59'">
                </datepicker>
              </div>
              <div class="form-group col-sm-2">
                <label class="font_normal_body">档案创建时间</label>
                <datepicker
                  :value.sync="$parent.$parent.da_starttime"
                  placeholder='开始时间' style="width: 60%"
                  :disabled-days-of-week="[]"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  v-model="$parent.$parent.da_starttime"
                  >
                </datepicker>
              </div>
              <div class="form-group col-sm-2">
                <label class="font_normal_body">档案创建时间</label>
                <datepicker
                  :value.sync="$parent.$parent.da_endtime"
                  placeholder='结束时间' style="width: 60%"
                  :disabled-days-of-week="[]"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  v-model="$parent.$parent.da_endtime">
                </datepicker>
              </div>
              <div class="form-group col-sm-2" style="width: auto;margin-top:8px;float: right">
                <export-excel-safe :data="$parent.$parent.searchData"
                                   :field="$parent.$parent.excelHeaders"
                                   :choose-col="true"
                                   sqlurl="rs/logic/SafeExportExcel" sql-name="summaryOfSecurityInspectionProgress" template-name='安检进度汇总'></export-excel-safe>
                <button class="button_spacing button_search" @click="search()">查询</button>
                <button class="button_spacing button_search" @click="model = {}">清空</button>
              </div>
            </div>
          </div>
        </criteria>
        <data-grid class="list_area table_sy" style="overflow: hidden" :model="model" partial='list' v-ref:grid>
          <template partial='head'>
            <tr>
              <th>
                <nobr>区域</nobr>
              </th>
              <th>
                <nobr>档案用户数</nobr>
              </th>
              <th>
                <nobr>计划内用户数</nobr>
              </th>
              <th>
                <nobr>已安检</nobr>
              </th>
              <th>
                <nobr>已入户</nobr>
              </th>
              <th>
                <nobr>入户率</nobr>
              </th>
              <th>
                <nobr>无计划安检数</nobr>
              </th>
              <th>
                <nobr>完成率</nobr>
              </th>
            </tr>
          </template>
          <template partial='body'>
            <td style="text-align: center" >{{row.f_user_region}}</td>
            <td style="text-align: center" >{{row.da_count}}</td>
            <td style="text-align: center" >{{row.f_plan_num}}</td>
            <td style="text-align: center" >{{row.f_safe_name}}</td>
            <td style="text-align: center" >{{row.f_ruhu_name}}</td>
            <td style="text-align: center" >{{row.f_ruhu_bv}}</td>
            <td style="text-align: center" >{{row.f_nosafe_num}}</td>
            <td style="text-align: center" >{{row.f_wc_bv}}</td>
          </template>
        </data-grid>
      </criteria-paged>
    </div>
  </div>
</template>

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

export default {
  title: '安检进度汇总',
  data() {
    return {
      model: new PagedList('rs/sql/summaryOfSecurityInspectionProgress', 20,{
        condition1:'this.condition1',
        condition2:'this.condition2',
      }),
      searchData: {
        condition1: "1=1",
        condition2: "1=1"
      },
      da_starttime:'',
      da_endtime:'',
      excelHeaders: {
        'f_user_region': '区域',
        'da_count': '档案数',
        'f_plan_num': '计划内用户数',
        'f_safe_name': '已安检',
        'f_ruhu_name': '已入户',
        'f_ruhu_bv': '入户率',
        'f_nosafe_num': '无计划安检数',
        'f_wc_bv': '完成率'
      }
    }
  },
  methods: {
    selfSearch(args) {
      let tempStr = args.condition
      let condition1 = tempStr
      let condition2 = ' 1=1 '
      if (this.da_starttime){
        condition2 += ` and tu.f_open_date >= '${this.da_starttime}' `
      }
      if (this.da_endtime){
        condition2 += ` and tu.f_open_date <= '${this.da_endtime}' `
      }

      this.model.condition1=condition1
      this.model.condition2=condition2

      this.searchData.condition1 = condition1
      this.searchData.condition2 = condition2
      this.model.search(args.condition, args.model, args.condValue)
    }
  },
  ready() {

  },
  watch: {

  },
  computed: {
    selected() {
      return this.$refs.paged.$refs.grid.selected
    }
  }

}
</script>
