<template>
  <div id='app' class="basic-main" style="height: 100%">
    <criteria-paged :model="model" :pager='false'>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' class="search_area">
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="form-group col-sm-4"  >
              <label class="font_normal_body">小&emsp;&emsp;区</label>
              <input type="text" class="input_search" v-model="model.f_residential_area"
                     style="width: 60%" placeholder="小区" condition="tcpi.f_residential_area like '%{}%'">
            </div>
            <div class="form-group col-sm-4">
              <label class="font_normal_body">用户类型</label>
              <v-select :value.sync="model.f_user_type" v-model='model.f_user_type'
                        :value-single="true" style="width: 60%"
                        class="select_list select"
                        :options='$parent.$parent.user_types' placeholder='用户类型'
                        close-on-select
                        condition="tcpi.f_user_type = '{}'"></v-select>
            </div>
          </div>
          <div class="row">
            <div class="col-sm-4 form-group">
              <label for="startDate" class="font_normal_body">计划开始:</label>
              <datepicker id="startDate" placeholder="计划开始"
                          v-model="model.startDate"
                          :value.sync="model.startDate"
                          style="width: 60%;"
                          :select-year="true"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-01-01 00:00:00'"
                          condition="tcp.f_create_time >= '{}'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <div class="col-sm-4 form-group">
              <label for="endDate" class="font_normal_body">计划结束:</label>
              <datepicker id="endDate" placeholder="计划结束"
                          v-model="model.endDate"
                          :select-year="true"
                          :value.sync="model.endDate"
                          :disabled-days-of-Week="[]"
                          style="width: 60%;"
                          condition="tcp.f_create_time <= '{}'"
                          :format="'yyyy-12-31 23:59:59'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <div class="col-sm-4 form-group" style="margin-top: 8px">
              <button class="button_search button_spacing" @click="search()">查询</button>
              <report-print id='yearPrint' top='3cm' left='0' width='100%' height='100%' :preview="true"></report-print>
              <report-excel id='yearPrint'></report-excel>
            </div>
          </div>
        </div>
      </criteria>
      <div partial='list' id='yearPrint' class="list_area" style="overflow-y: scroll">
        <table class='tableprint' style="margin: 0px auto">
          <thead>
          <tr>
            <th colspan='12' style="font-weight: normal; text-align: left;">
              <h3 style="text-align: center">安检年报表</h3>
            </th>
          </tr>
          <tr>
            <th colspan='12' style="font-weight: normal; text-align: center;">
              计划开始日期：{{model.model.startDate}}&nbsp;&nbsp;&nbsp;
              计划结束日期：{{ model.model.endDate }}
            </th>
          </tr>
          </thead>
          <tr>
            <th colspan='12' style="font-weight: normal;">
              {{{ model.data.substring(26,model.data.length-8) }}}
            </th>
          </tr>
          <tr style="height: 100px"></tr>
        </table>
      </div>
    </criteria-paged>
  </div>

</template>

<script>
  import {DataModel, HttpResetClass} from 'vue-client'

  export default {
    title: '安检年报表',
    data () {
      let model = new DataModel('rs/report/safeStatisticsYear', {})
      // model.f_filialeid = '(' + this.$login.f.orgid + ')'
      return {
        user_types: [{label:'全部',value:''},{label:'民用',value:'民用'},{label:'非民用',value:'非民用'}],
        userid: this.$login.f.id,
        source: `tool.getFullTree(this.getRights().where(row.getType() != $zone$).where(row.getType() == $organization$))`,
        model: model
      }
    },
    methods: {
      getRes (obj) {
        this.model.f_filialeid = this.$login.convertToIn(obj.resids)
      },
      selfSearch (args) {
        let condition = {
          condition1 : args.condition,
          condition2 : `1=1 and f_entry_status = '入户'`
        }
        if (args.model.f_checker_id){
          condition.condition2 += ` and f_checker_name = '${args.model.f_checker_id}'`
        }
        if (args.model.f_user_type){
          condition.condition2 += ` and f_check_type = '${args.model.f_user_type}'`
        }
        if (args.model.f_residential_area){
          condition.condition2 += ` and f_residential_area = '${args.model.f_residential_area}'`
        }
        if (args.model.checkstart){
          condition.condition2 += ` and f_offsite_time >= '${args.model.checkstart}'`
        }
        if (args.model.checkend){
          condition.condition2 += ` and f_offsite_time <= '${args.model.checkend}'`
        }
        this.model.search(condition, args.model)
      }
    },
    ready () {
    },
    computed: {
      selected () {
        return this.$refs.grid.selected
      }
    }
  }
</script>
