<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-month="true"
                  :disabled-days-of-week="[]"
                  :format="'yyyy-MM'"
                  :show-rest-button="reset"
                  :value.sync="model.start_time"
                  v-model="model.start_time"
                  condition="tcpi.f_last_check_date >= '{}-01 00:00:00' and tcpi.f_last_check_date <= '{}-31 23:59:59'">
                </datepicker>
              </div>
<!--              <div class="form-group col-sm-4">-->
<!--                <label class="font_normal_body">结束时间:</label>-->
<!--                <datepicker-->
<!--                  placeholder='请选择'-->
<!--                  :select-month="true"-->
<!--                  :disabled-days-of-week="[]"-->
<!--                  style="width:60%"-->
<!--                  :format="'yyyy-MM'"-->
<!--                  :show-rest-button="reset"-->
<!--                  :value.sync="model.end_time"-->
<!--                  v-model="model.end_time"-->
<!--                  condition="tcpi.f_last_check_date <= '{}-31 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="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="safeStatisticsDay" 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>13日</nobr>
              </th>
              <th>
                <nobr>14日</nobr>
              </th>
              <th>
                <nobr>15日</nobr>
              </th>
              <th>
                <nobr>16日</nobr>
              </th>
              <th>
                <nobr>17日</nobr>
              </th>
              <th>
                <nobr>18日</nobr>
              </th>
              <th>
                <nobr>19日</nobr>
              </th>
              <th>
                <nobr>20日</nobr>
              </th>
              <th>
                <nobr>21日</nobr>
              </th>
              <th>
                <nobr>22日</nobr>
              </th>
              <th>
                <nobr>23日</nobr>
              </th>
              <th>
                <nobr>24日</nobr>
              </th>
              <th>
                <nobr>25日</nobr>
              </th>
              <th>
                <nobr>26日</nobr>
              </th>
              <th>
                <nobr>27日</nobr>
              </th>
              <th>
                <nobr>28日</nobr>
              </th>
              <th>
                <nobr>29日</nobr>
              </th>
              <th>
                <nobr>30日</nobr>
              </th>
              <th>
                <nobr>31日</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.day1 }}</td>
            <td style="text-align: center">{{ row.day2 }}</td>
            <td style="text-align: center">{{ row.day3 }}</td>
            <td style="text-align: center">{{ row.day4 }}</td>
            <td style="text-align: center">{{ row.day5 }}</td>
            <td style="text-align: center">{{ row.day6 }}</td>
            <td style="text-align: center">{{ row.day7 }}</td>
            <td style="text-align: center">{{ row.day8 }}</td>
            <td style="text-align: center">{{ row.day9 }}</td>
            <td style="text-align: center">{{ row.day10 }}</td>
            <td style="text-align: center">{{ row.day11 }}</td>
            <td style="text-align: center">{{ row.day12 }}</td>
            <td style="text-align: center">{{ row.day13 }}</td>
            <td style="text-align: center">{{ row.day14 }}</td>
            <td style="text-align: center">{{ row.day15 }}</td>
            <td style="text-align: center">{{ row.day16 }}</td>
            <td style="text-align: center">{{ row.day17 }}</td>
            <td style="text-align: center">{{ row.day18 }}</td>
            <td style="text-align: center">{{ row.day19 }}</td>
            <td style="text-align: center">{{ row.day20 }}</td>
            <td style="text-align: center">{{ row.day21 }}</td>
            <td style="text-align: center">{{ row.day22 }}</td>
            <td style="text-align: center">{{ row.day23 }}</td>
            <td style="text-align: center">{{ row.day24 }}</td>
            <td style="text-align: center">{{ row.day25 }}</td>
            <td style="text-align: center">{{ row.day26 }}</td>
            <td style="text-align: center">{{ row.day27 }}</td>
            <td style="text-align: center">{{ row.day28 }}</td>
            <td style="text-align: center">{{ row.day29 }}</td>
            <td style="text-align: center">{{ row.day30 }}</td>
            <td style="text-align: center">{{ row.day31 }}</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.day1 }}</td>
            <td style="text-align: center">{{ model.sums.day2 }}</td>
            <td style="text-align: center">{{ model.sums.day3 }}</td>
            <td style="text-align: center">{{ model.sums.day4 }}</td>
            <td style="text-align: center">{{ model.sums.day5 }}</td>
            <td style="text-align: center">{{ model.sums.day6 }}</td>
            <td style="text-align: center">{{ model.sums.day7 }}</td>
            <td style="text-align: center">{{ model.sums.day8 }}</td>
            <td style="text-align: center">{{ model.sums.day9 }}</td>
            <td style="text-align: center">{{ model.sums.day10 }}</td>
            <td style="text-align: center">{{ model.sums.day11 }}</td>
            <td style="text-align: center">{{ model.sums.day12 }}</td>
            <td style="text-align: center">{{ model.sums.day13 }}</td>
            <td style="text-align: center">{{ model.sums.day14 }}</td>
            <td style="text-align: center">{{ model.sums.day15 }}</td>
            <td style="text-align: center">{{ model.sums.day16 }}</td>
            <td style="text-align: center">{{ model.sums.day17 }}</td>
            <td style="text-align: center">{{ model.sums.day18 }}</td>
            <td style="text-align: center">{{ model.sums.day19 }}</td>
            <td style="text-align: center">{{ model.sums.day20 }}</td>
            <td style="text-align: center">{{ model.sums.day21 }}</td>
            <td style="text-align: center">{{ model.sums.day22 }}</td>
            <td style="text-align: center">{{ model.sums.day23 }}</td>
            <td style="text-align: center">{{ model.sums.day24 }}</td>
            <td style="text-align: center">{{ model.sums.day25 }}</td>
            <td style="text-align: center">{{ model.sums.day26 }}</td>
            <td style="text-align: center">{{ model.sums.day27 }}</td>
            <td style="text-align: center">{{ model.sums.day28 }}</td>
            <td style="text-align: center">{{ model.sums.day29 }}</td>
            <td style="text-align: center">{{ model.sums.day30 }}</td>
            <td style="text-align: center">{{ model.sums.day31 }}</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: "safeStatisticsDay",
  title: "安检报表日",
  data() {
    return {
      model: new PagedList("/rs/sql/safeStatisticsDay", 999, {orgid: this.$login.f.orgid}, {
        day1: '',
        day2: '',
        day3: '',
        day4: '',
        day5: '',
        day6: '',
        day7: '',
        day8: '',
        day9: '',
        day10: '',
        day11: '',
        day12: '',
        day13: '',
        day14: '',
        day15: '',
        day16: '',
        day17: '',
        day18: '',
        day19: '',
        day20: '',
        day21: '',
        day22: '',
        day23: '',
        day24: '',
        day25: '',
        day26: '',
        day27: '',
        day28: '',
        day29: '',
        day30: '',
        day31: '',
        countarea:''
      }),
      resids: {},
      searchData: {
        condition: "1=1",
        orgid: this.$login.f.orgid
      },
      print_model:{},
      excelHeaders: {
        'f_residential_area': '小区名称',
        'day1': '1日',
        'day2': '2日',
        'day3': '3日',
        'day4': '4日',
        'day5': '5日',
        'day6': '6日',
        'day7': '7日',
        'day8': '8日',
        'day9': '9日',
        'day10': '10日',
        'day11': '11日',
        'day12': '12日',
        'day13': '13日',
        'day14': '14日',
        'day15': '15日',
        'day16': '16日',
        'day17': '17日',
        'day18': '18日',
        'day19': '19日',
        'day20': '20日',
        'day21': '21日',
        'day22': '22日',
        'day23': '23日',
        'day24': '24日',
        'day25': '25日',
        'day26': '26日',
        'day27': '27日',
        'day28': '28日',
        'day29': '29日',
        'day30': '30日',
        'day31': '31日',
        'countarea':'小计'
      },
      user_types: [{label:'全部',value:''},{label:'民用',value:'民用'},{label:'非民用',value:'非民用'}],
      printshow: false,
      defaultPrint: ['f_residential_area', 'day1',
        'day2',
        'day3',
        'day4',
        'day5',
        'day6',
        'day7',
        'day8',
        'day9',
        'day10',
        'day11',
        'day12',
        'day13',
        'day14',
        'day15',
        'day16',
        'day17',
        'day18',
        'day19',
        'day20',
        'day21',
        'day22',
        'day23',
        'day24',
        'day25',
        'day26',
        'day27',
        'day28',
        'day29',
        'day30',
        'day31','countarea'],
      sumsmodel: {},
    }
  },
  ready() {
    let a = new Date()
    let year = a.getFullYear()
    let month = '0'+(a.getMonth()+1)
    this.$refs.paged.$refs.criteria.model.start_time = year + '-'+ (month.substring(month.length-2))
    this.$refs.paged.$refs.criteria.model.end_time = year + '-'+ (month.substring(month.length-2))
  },
  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': '合计',
        'day1': this.sumsmodel.day1,
        'day2': this.sumsmodel.day2,
        'day3': this.sumsmodel.day3,
        'day4': this.sumsmodel.day4,
        'day5': this.sumsmodel.day5,
        'day6': this.sumsmodel.day6,
        'day7': this.sumsmodel.day7,
        'day8': this.sumsmodel.day8,
        'day9': this.sumsmodel.day9,
        'day10': this.sumsmodel.day10,
        'day11': this.sumsmodel.day11,
        'day12': this.sumsmodel.day12,
        'day13': this.sumsmodel.day13,
        'day14': this.sumsmodel.day14,
        'day15': this.sumsmodel.day15,
        'day16': this.sumsmodel.day16,
        'day17': this.sumsmodel.day17,
        'day18': this.sumsmodel.day18,
        'day19': this.sumsmodel.day19,
        'day20': this.sumsmodel.day20,
        'day21': this.sumsmodel.day21,
        'day22': this.sumsmodel.day22,
        'day23': this.sumsmodel.day23,
        'day24': this.sumsmodel.day24,
        'day25': this.sumsmodel.day25,
        'day26': this.sumsmodel.day26,
        'day27': this.sumsmodel.day27,
        'day28': this.sumsmodel.day28,
        'day29': this.sumsmodel.day29,
        'day30': this.sumsmodel.day30,
        'day31': this.sumsmodel.day31,
        '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>
