<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' class="search_area" @condition-changed='$parent.search' v-ref:criteria>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">&nbsp;公&nbsp;&nbsp;&nbsp;&nbsp;司&nbsp;</label>
              <right-tree :userid.sync='$parent.$parent.userid' style="width: 60%;" :source.sync='$parent.$parent.source' @re-res="$parent.$parent.getRes" ></right-tree>
            </div>
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">统计年份</label>
              <datepicker  placeholder="截止年份" style="width:60%"
                           v-model="$parent.$parent.yearDate"
                           :value.sync="$parent.$parent.yearDate"
                           :format="'yyyy'"
                           :show-reset-button="true"
                           :select-year="true">
              </datepicker>
            </div>
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">小区名称</label>
              <input type="text" class="input_search" v-model="model.f_residential_area"
                     style="width: 60%" placeholder="小区名称"
                     condition="u1.f_residential_area like'%{}%'"
              >
            </div>
            <div class="col-sm-4" >
              <div class="span" style="float: right;margin-top: 8px">
                <button class="button_search button_spacing" @click="search">查询</button>
                <export-excel :data="$parent.$parent.searchData"
                              :field="$parent.$parent.excelHeaders"
                              sqlurl="api/af-safecheck/logic/exportfile" sql-name="getAreaSafecheckTreatmentList" :template-name="$parent.$parent.excelTitle"></export-excel>
                <div style="float: right" 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>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid class="list_area table_sy">
        <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;white-space:nowrap;">{{row.f_residential_area}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.count_user_number}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_xinzeng_number}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_yixiafa_number}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_weixiafa_number}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_yijian_number}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_weijian_number}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_orgname}}</td>
        </template>
      </data-grid>
    </criteria-paged>

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

export default {
  title: '小区安检情况',
  data() {
    let model = new PagedList('api/af-safecheck/sql/getAreaSafecheckTreatmentList', 20, {
      f_filialeid: 'this.f_filialeids',
      yearDate: 'this.yearDate'
    })
    model.f_filialeids = "('"+this.$login.f.orgid+"')"
    model.yearDate = (new Date()).getFullYear().toString()
    return {
      userid: this.$login.f.id,
      model: model,
      source: `tool.getFullTree(this.getRights().where(row.getType() != $zone$).where(row.getType() == $organization$))`,
      yearDate: (new Date()).getFullYear().toString(),
      searchData: {
        condition: "1=1",
        f_filialeid: `('${this.$login.f.orgid}')`,
        yearDate: (new Date()).getFullYear().toString()
      },
      excelHeaders:{
        'f_residential_area': '小区名称',
        'count_user_number': '应检数',
        'f_xinzeng_number': '新增户数',
        'f_yixiafa_number': '已下发数',
        'f_weixiafa_number': '未下发数',
        'f_yijian_number': '已检入户数',
        'f_weijian_number': '未检入户数',
        'f_orgname': '公司机构'
      },
      excelTitle: `用户小区安检情况汇总导出`
    }
  },
  ready() {

  },
  methods: {
    search(args) {
      // 当前组件赋值
      this.model.yearDate = this.yearDate
      // 给兄弟组件赋值
      this.$parent.$refs.detail.f_filialeids = this.model.f_filialeids
      this.$parent.$refs.detail.yearDate = this.model.yearDate
      // 给导出excel数据条件赋值
      this.searchData.f_filialeid=  this.model.f_filialeids
      this.searchData.yearDate=  this.model.yearDate
      this.searchData.condition=  args.condition

      this.model.search(args.condition, args.model)
    },
    getRes(obj) {
      this.excelTitle = `${obj.res[0]}用户小区安检情况汇总导出`
      this.model.f_filialeids = this.$login.convertToIn(obj.resids);
    },
    hiddenr() {
      this.$parent.showItem = !this.$parent.showItem
    },
  },
  computed: {
    selected() {
      return this.$refs.paged.$refs.grid.selected
    }
  }
}
</script>
