<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 partial>
            <div class="row">
              <div class="form-group col-sm-4">
                <label class="font_normal_body">开始时间:</label>
                <datepicker
                  placeholder='请选择'
                  style="width:60%"
                  :disabled-days-of-week="[]"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  :value.sync="model.start_time"
                  v-model="model.start_time"
                  condition="tcp.f_upload_date >= '{} 00:00:00'">
                </datepicker>
              </div>
              <div class="form-group col-sm-4">
                <label class="font_normal_body">结束时间:</label>
                <datepicker
                  placeholder='请选择'
                  :disabled-days-of-week="[]"
                  style="width:60%"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  :value.sync="model.end_time"
                  v-model="model.end_time"
                  condition="tcp.f_upload_date <= '{} 23:59:59'">
                </datepicker>
              </div>
              <div class="col-sm-4 form-group">
                <label class="font_normal_body">小区名称：</label>
                <input style="width: 60%" class="input_search" v-model="model.f_residential_area"
                       placeholder="请输入小区（可模糊查询）" condition="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="tcp.f_check_type = '{}'"></v-select>
              </div>
              <div class="col-sm-4 form-group" style="margin: 0">
                <role-selector-safe
                  role-name="安检员"
                  :resobjprop.sync="$parent.$parent.resids"
                  role-lable="安&nbsp;检&nbsp;员&nbsp;"
                  @re-res="$parent.$parent.getRes"
                  :value.sync="model.f_checker_id"
                  v-model="model.f_checker_id"
                  condition="tcp.f_checker_name = '{}'">
                </role-selector-safe>
              </div>
              <div style="float: right">
                <export-excel-safe :data="$parent.$parent.searchData"
                                   :field="$parent.$parent.excelHeaders"
                                   progress="safeGetExportProgress"
                                   sqlurl="rs/logic/SafeExportExcel" sql-name="communityDetail" template-name='小区隐患明细'
                                   :choose-col="true"></export-excel-safe>
              </div>
              <print-data-safe :sum-field="$parent.$parent.excelHeaders" :model="$parent.$parent.print_model" :field="$parent.$parent.excelHeaders"
                          :defaultfield="$parent.$parent.defaultPrint" :chooserow="true"
                          :titletable="'小区隐患明细'" :starthead="$parent.$parent.getstart"
              ></print-data-safe>
              <button class="button_spacing button_search" @click="search()">查询</button>
            </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>
            </tr>
          </template>
          <template partial='body'>

            <td style="text-align: center">{{ $index + 1 }}</td>
            <td style="text-align: center">{{ row.f_residential_area }}</td>
            <td style="text-align: center">{{ row.yhhs }}</td>
            <td style="text-align: center">{{ row.yclyh }}</td>
            <td style="text-align: center">{{ row.clzyh }}</td>
            <td style="text-align: center">{{ row.wcl }}</td>
          </template>
          <template partial="foot">
            <td style="text-align: center" colspan="2"><span><b>合计：</b></span></td>
            <td style="text-align: center">{{ model.sums.yhhs }}</td>
            <td style="text-align: center">{{ model.sums.yclyh }}</td>
            <td style="text-align: center">{{ model.sums.clzyh }}</td>
            <td style="text-align: center">{{ model.sums.wcl }}</td>
          </template>
        </data-grid>
      </criteria-paged>
    </div>
  </div>
</template>

<script>
import {PagedList} from "vue-client";

export default {
  name: "communityDetail",
  title: "小区隐患明细",
  data() {
    return {
      model: new PagedList("/rs/sql/communityDetail", 999, {orgid: this.$login.f.orgid}, {
        yhhs: '',
        yclyh: '',
        clzyh: '',
        wcl:''
      }),
      resids: {},
      searchData: {
        condition: "1=1",
        orgid: this.$login.f.orgid
      },
      print_model:{},
      user_types: [{label:'全部',value:''},{label:'民用',value:'民用'},{label:'非民用',value:'非民用'}],
      excelHeaders: {
        'f_residential_area': '小区名称',
        'yhhs': '存在隐患户数',
        'wcl': '未处理户数',
        'yclyh': '已处理户数',
        'clzyh': '处理中户数',
      },
      printshow: false,
      defaultPrint: ['f_residential_area','yhhs','yclyh','clzyh','wcl'],
      sumsmodel: {},
    };
  },
  ready() {
    // this.model.search('1=1')
  },
  methods: {
    async selfSearch(args) {
      args.condition += ` and f_defect_content like '%有隐患%'`
      await this.model.search(args.condition, args.model, args.condValue)
      this.searchData.condition = args.condition
      this.sumsmodel = this.$refs.paged.$refs.grid.model.sums;
      this.print_model = JSON.parse(JSON.stringify(this.$refs.paged.$refs.grid.model))
      this.print_model.rows.push({
        f_residential_area: '合计',
        yhhs: this.sumsmodel.yhhs,
        yclyh: this.sumsmodel.yclyh,
        clzyh: this.sumsmodel.clzyh,
        wcl: this.sumsmodel.wcl,
      })
      this.print_model.totalPage = 0
    },
    getRes(obj) {
      //tag
      this.resids = {res: obj.res[0], resids: obj.resids[0]}
      this.model.f_filialeids = this.$login.convertToIn(obj.resids);
    },
    // 打印
    stamp() {
      this.printshow = true
    },
    close() {
      this.printshow = false
    }
  },
  computed:{
    getstart(){
      return `开始时间：${this.$refs.paged.$refs.criteria.model.start_time} 结束时间：${this.$refs.paged.$refs.criteria.model.end_time}`
    },
  }
}
</script>

<style scoped>

</style>
