<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%"
                  :select-year="true"
                  :disabled-days-of-week="[]"
                  :format="'yyyy'"
                  :show-rest-button="reset"
                  :value.sync="model.start_time"
                  v-model="model.start_time"
                  condition="tcpi.f_last_check_date >= '{}-01-01 00:00:00' and tcpi.f_last_check_date <= '{}-12-31 23:59:59'">
                </datepicker>
              </div>
<!--              <div class="form-group col-sm-4">-->
<!--                <label class="font_normal_body">结束时间:</label>-->
<!--                <datepicker-->
<!--                  placeholder='请选择'-->
<!--                  :select-year="true"-->
<!--                  :disabled-days-of-week="[]"-->
<!--                  style="width:60%"-->
<!--                  :format="'yyyy'"-->
<!--                  :show-rest-button="reset"-->
<!--                  :value.sync="model.end_time"-->
<!--                  v-model="model.end_time"-->
<!--                  condition="">-->
<!--                </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="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 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="f_checker = '{}'">
              </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="safeStatisticsMonth" 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"
                          :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>1月</nobr>
              </th>
              <th>
                <nobr>2月</nobr>
              </th>
              <th>
                <nobr>3月</nobr>
              </th>
              <th>
                <nobr>4月</nobr>
              </th>
              <th>
                <nobr>5月</nobr>
              </th>
              <th>
                <nobr>6月</nobr>
              </th>
              <th>
                <nobr>7月</nobr>
              </th>
              <th>
                <nobr>8月</nobr>
              </th>
              <th>
                <nobr>9月</nobr>
              </th>
              <th>
                <nobr>10月</nobr>
              </th>
              <th>
                <nobr>11月</nobr>
              </th>
              <th>
                <nobr>12月</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.month1 }}</td>
            <td style="text-align: center">{{ row.month2 }}</td>
            <td style="text-align: center">{{ row.month3 }}</td>
            <td style="text-align: center">{{ row.month4 }}</td>
            <td style="text-align: center">{{ row.month5 }}</td>
            <td style="text-align: center">{{ row.month6 }}</td>
            <td style="text-align: center">{{ row.month7 }}</td>
            <td style="text-align: center">{{ row.month8 }}</td>
            <td style="text-align: center">{{ row.month9 }}</td>
            <td style="text-align: center">{{ row.month10 }}</td>
            <td style="text-align: center">{{ row.month11 }}</td>
            <td style="text-align: center">{{ row.month12 }}</td>
            <td style="text-align: center">{{ row.countarea }}</td>
          </template>
          <template partial="foot">
            <td style="text-align: center" colspan="2"><span><b>合计：</b></span></td>
            <td style="text-align: center">{{ model.sums.month1 }}</td>
            <td style="text-align: center">{{ model.sums.month2 }}</td>
            <td style="text-align: center">{{ model.sums.month3 }}</td>
            <td style="text-align: center">{{ model.sums.month4 }}</td>
            <td style="text-align: center">{{ model.sums.month5 }}</td>
            <td style="text-align: center">{{ model.sums.month6 }}</td>
            <td style="text-align: center">{{ model.sums.month7 }}</td>
            <td style="text-align: center">{{ model.sums.month8 }}</td>
            <td style="text-align: center">{{ model.sums.month9 }}</td>
            <td style="text-align: center">{{ model.sums.month10 }}</td>
            <td style="text-align: center">{{ model.sums.month11 }}</td>
            <td style="text-align: center">{{ model.sums.month12 }}</td>
            <td style="text-align: center">{{ model.sums.countarea }}</td>
          </template>
        </data-grid>
      </criteria-paged>
    </div>
  </div>
</template>

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

export default {
  name: "safeStatisticsMonth",
  title: "安检报表月",
  data() {

    return {
      model: new PagedList("/rs/sql/safeStatisticsMonth", 999, {orgid: this.$login.f.orgid}, {
        month1: '',
        month2: '',
        month3: '',
        month4: '',
        month5: '',
        month6: '',
        month7: '',
        month8: '',
        month9: '',
        month10: '',
        month11: '',
        month12: '',
        countarea: ''
      }),
            resids:{},
      searchData:{
        condition: "1=1",
        orgid: this.$login.f.orgid
      },
      print_model:{},
      user_types: [{label:'全部',value:''},{label:'民用',value:'民用'},{label:'非民用',value:'非民用'}],
      excelHeaders:{
        'f_residential_area': '小区名称',
        'month1': '1月',
        'month2': '2月',
        'month3': '3月',
        'month4': '4月',
        'month5': '5月',
        'month6': '6月',
        'month7': '7月',
        'month8': '8月',
        'month9': '9月',
        'month10': '10月',
        'month11': '11月',
        'month12': '12月',
        'countarea':'小计'
      },
      printshow: false,
      defaultPrint: ['f_residential_area', 'month1', 'month2', 'month3', 'month4', 'month5', 'month6', 'month7', 'month8', 'month9', 'month10', 'month11', 'month12','countarea'],
      sumsmodel: {},
    }
  },
  ready() {
    // this.model.search('1=1')
  },
  methods: {
    async selfSearch(args) {
      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': '合计',
        'month1': this.sumsmodel.month1,
        'month2': this.sumsmodel.month2,
        'month3': this.sumsmodel.month3,
        'month4': this.sumsmodel.month4,
        'month5': this.sumsmodel.month5,
        'month6': this.sumsmodel.month6,
        'month7': this.sumsmodel.month7,
        'month8': this.sumsmodel.month8,
        'month9': this.sumsmodel.month9,
        'month10': this.sumsmodel.month10,
        'month11': this.sumsmodel.month11,
        'month12': this.sumsmodel.month12,
        'countarea':this.sumsmodel.countarea
      })
      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.start_time : ''}`
    },
  }
}
</script>

<style scoped>

</style>
