<template>
  <div  class="flex">
    <criteria-paged :model="model" v-ref:paged :pager="false">
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <!--<div :class="{'form-group col-sm-3':$parent.$parent.$parent.isdetail,'form-group col-sm-2':!$parent.$parent.$parent.isdetail}">
              <label class="font_normal_body">组织机构</label>
              <res-select restype='organization'
                          class="select select_list"
                          style="width: 60%"
                          @res-select="$parent.$parent.getorg"
                          :initresid='$parent.$parent.curorgid'>
              </res-select>
            </div>-->
            <div :class="{'col-sm-6':$parent.$parent.$parent.isdetail,'col-sm-4':!$parent.$parent.$parent.isdetail}">
              <role-selector-safe
                role-name="安检员"
                role-lable="安&ensp;检&ensp;员"
                @re-res="$parent.$parent.getorg"
                :value.sync="model.f_checker_id"
                v-model="model.f_checker_id"
                :value-multiple="true"
                :value-close="false"
                condition="f_checker_name in {}">
              </role-selector-safe>
            </div>
            <div  :class="{'form-group col-sm-3':$parent.$parent.$parent.isdetail,'form-group col-sm-2':!$parent.$parent.$parent.isdetail}">
              <label class="font_normal_body">小区名称</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_residential_area" placeholder='小区名称'
                     condition="f_residential_area like '%{}%'" v-next-el="cx" v-el:qjmc>
            </div>
            <div  :class="{'form-group col-sm-3':$parent.$parent.$parent.isdetail,'form-group col-sm-2':!$parent.$parent.$parent.isdetail}">
              <label class="font_normal_body">计划名称</label>
              <v-select class="select_list select"
                        placeholder='计划名称' style="width: 60%"
                        :search="true"
                        v-model="model.f_plan_name"
                        :value.sync="model.f_plan_name"
                        :options='$parent.$parent.planName'
                        condition="f_plan_id = '{}'"
                        :value-single="true"
                        close-on-select clear-button></v-select>

            </div>
            <!--<div  :class="{
            'form-group col-sm-3':$parent.$parent.$parent.isdetail,'form-group col-sm-2':!$parent.$parent.$parent.isdetail}">
              <label class="font_normal_body">安&ensp;检&ensp;员</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_checker_name" placeholder='安检员'
                     condition="f_checker_name like '%{}%'" v-next-el="cx" v-el:qjmc>
            </div>-->
            <div class="form-group col-sm-2" v-if="!$parent.$parent.$parent.isdetail"></div>
            <div  :class="{'form-group col-sm-3':$parent.$parent.$parent.isdetail,'form-group col-sm-2':!$parent.$parent.$parent.isdetail}" style="float:right; padding-right: 25px">
              <div class="span" style="float:right;">
                <div style="float: right;margin-left:10px" class="button_spacing"
                     :class="{'button_shrink_left':!$parent.$parent.$parent.isdetail,'button_shrink_right':$parent.$parent.$parent.isdetail}"
                     @click="$parent.$parent.hiddenr()"></div>
                <div class="button_spacing" style="float: right;margin-left:10px"
                     :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                     @click="$parent.$parent.hidden()">
                </div>
<!--                <export-excel-safe   :data="$parent.$parent.exportParameter"
                                     :field="$parent.$parent.exportExcelField"
                                     sqlurl="rs/logic/SafeExportExcel" sql-name="getCheckPlanAreaList"
                                     template-name='安检汇总' :choose-col="true">
                </export-excel-safe>-->
                <button
                       id="btnaaaa" style="float: right" class="button_search"
                          v-if="$parent.$parent.excelStart"
                        @click="$parent.$parent.exportexcel()"
                        v-el:cx>导出</button>
                <button id="btnaaa" style="float: right" class="button_search"
                        @click="$parent.$parent.getGroupName1(),search(),$parent.$parent.getexportExcelField(),$parent.$parent.$parent.isdetail=false,$parent.$parent.listflag=false"
                        v-el:cx>查询</button>
              </div>
            </div>
            <div  :class="{'form-group col-sm-3':$parent.$parent.$parent.isdetail,'form-group col-sm-2':!$parent.$parent.$parent.isdetail}" v-if="$parent.$parent.criteriaShow">
              <label class="font_normal_body">起始时间</label>
              <datepicker
                :value.sync="$parent.$parent.f_check_start"
                placeholder='起始时间' style="width:60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM'"
                :select-month="true"
                :show-rest-button="reset">
              </datepicker>
            </div>
            <div  :class="{'form-group col-sm-3':$parent.$parent.$parent.isdetail,'form-group col-sm-2':!$parent.$parent.$parent.isdetail}" v-if="$parent.$parent.criteriaShow">
              <label class="font_normal_body">结束时间</label>
              <datepicker
                :value.sync="$parent.$parent.f_check_end"
                placeholder='结束时间' style="width:60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM'"
                :select-month="true"
                :show-rest-button="reset">
              </datepicker>
            </div>
            <div  :class="{'form-group col-sm-3':$parent.$parent.$parent.isdetail,'form-group col-sm-2':!$parent.$parent.$parent.isdetail}" v-if="$parent.$parent.criteriaShow">
              <label class="font_normal_body">安检时间</label>
              <datepicker
                :value.sync="$parent.$parent.f_safe_start"
                placeholder='结束时间' style="width: 60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd 00:00:00'"
                :show-rest-button="reset"
                v-model="$parent.$parent.f_safe_start"
                >
              </datepicker>
            </div>
            <div  :class="{'form-group col-sm-3':$parent.$parent.$parent.isdetail,'form-group col-sm-2':!$parent.$parent.$parent.isdetail}" v-if="$parent.$parent.criteriaShow">
              <label class="font_normal_body">安检时间</label>
              <datepicker
                :value.sync="$parent.$parent.f_safe_end"
                placeholder='结束时间' style="width: 60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd 23:59:59'"
                :show-rest-button="reset"
                v-model="$parent.$parent.f_safe_end"
                >
              </datepicker>
            </div>
            <div  :class="{'form-group col-sm-3':$parent.$parent.$parent.isdetail,'form-group col-sm-2':!$parent.$parent.$parent.isdetail}" v-if="$parent.$parent.criteriaShow">
              <label class="font_normal_body">业务部门</label>
              <v-select :value.sync="model.department" v-model='model.department'
                        :multiple="true"
                        class="select_list select"
                        :options='$parent.$parent.departments' placeholder='部门'
                        close-on-select
                        condition="department in {}"></v-select>
            </div>
          </div>
          <div class="row">
            <div class="col-sm-12">
              <label class="control-label" style="color: #c7254e">汇 总 项</label>
              <input type="checkbox" id="f_plan_month" value="f_plan_month"  v-model="$parent.$parent.nameForSql"/>
              <label for="f_plan_month">计划月份</label>
              <input type="checkbox" id="f_no_checkplan" value="f_no_checkplan" v-model="$parent.$parent.nameForSql"/>
              <label for="f_no_checkplan">计划类型</label>
              <input type="checkbox" id="f_residential_area" value="f_residential_area" v-model="$parent.$parent.nameForSql"/>
              <label for="f_residential_area">小区名称</label>
              <input type="checkbox" id="f_plan_name" value="f_plan_name" v-model="$parent.$parent.nameForSql"/>
              <label for="f_plan_name">计划名称</label>
              <input type="checkbox" id="f_checker_name" value="f_checker_name" v-model="$parent.$parent.nameForSql"/>
              <label for="f_checker_name">安检员</label>
              <input type="checkbox" id="f_user_type" value="f_user_type" v-model="$parent.$parent.nameForSql"/>
              <label for="f_user_type">用户类型</label>
              <input type="checkbox" id="department" value="department" v-model="$parent.$parent.nameForSql"/>
              <label for="f_user_type">部门</label>
              <input type="checkbox" id="f_user_number" value="f_user_number" v-model="$parent.$parent.nameForSql"/>
              <label for="f_checker_name">档案数量</label>
            </div>
          </div>
        </div>

      </criteria>
      <data-grid id="excelid" :model="model" partial='list' class="list_area table_sy excelid"  v-ref:grid>
        <template partial='head'>
          <tr>
            <th>
              <nobr>序号</nobr>
            </th>
            <th v-if="$parent.$parent.$parent.nameForSql.includes('f_plan_month')"><nobr>计划月份</nobr></th>
            <th v-if="$parent.$parent.$parent.nameForSql.includes('f_no_checkplan')"><nobr>计划类型</nobr></th>
            <th v-if="$parent.$parent.$parent.nameForSql.includes('f_residential_area')"><nobr>小区名称</nobr></th>
            <th v-if="$parent.$parent.$parent.nameForSql.includes('f_plan_name')"><nobr>计划名称</nobr></th>
            <th v-if="$parent.$parent.$parent.nameForSql.includes('f_checker_name')"><nobr>安检员</nobr></th>
            <th v-if="$parent.$parent.$parent.nameForSql.includes('f_user_type')"><nobr>用户类型</nobr></th>
            <th v-if="$parent.$parent.$parent.nameForSql.includes('department')"><nobr>部门</nobr></th>
            <th v-if="$parent.$parent.$parent.nameForSql.includes('f_user_number')"><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>
            <th>
              <nobr>拆除</nobr>
            </th>
            <th>
              <nobr>停用</nobr>
            </th>
            <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>到访不遇3+</nobr>
            </th>
            <th>
              <nobr>上门率</nobr>
            </th>
            <th>
              <nobr>安检率</nobr>
            </th>
            <th>
              <nobr>完成率</nobr>
            </th>
            <!--<th>-->
            <!--<nobr>查看</nobr>-->
            <!--</th>-->
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center;border-right: 1px solid ">{{$index + 1}}</td>
<!--            <td style="text-align:center"  v-if="$parent.$parent.$parent.nameForSql.includes('f_plan_month')">{{row.f_plan_month.indexOf('*&')!=-1?'':row.f_plan_month}}</td>-->
<!--            <td style="text-align:center"  v-if="$parent.$parent.$parent.nameForSql.includes('f_no_checkplan')">{{row.f_no_checkplan.indexOf('*&')!=-1?'':row.f_no_checkplan}}</td>-->
<!--            <td style="text-align:center"  v-if="$parent.$parent.$parent.nameForSql.includes('f_residential_area')">{{row.f_residential_area.indexOf('*&')!=-1?'':row.f_residential_area}}</td>-->
<!--            <td style="text-align:center"  v-if="$parent.$parent.$parent.nameForSql.includes('f_plan_name')">{{row.f_plan_name.indexOf('*&')!=-1?'':row.f_plan_name}}</td>-->
<!--            <td style="text-align:center"  v-if="$parent.$parent.$parent.nameForSql && $parent.$parent.$parent.nameForSql.includes('f_checker_name')">{{row.f_checker_name && row.f_checker_name.indexOf('*&')!=-1?'':row.f_checker_name}}</td>-->
            <td style="text-align:center" :class="{'td-0':row.f_plan_month==undefined,'td-1':model.rows && model.rows.length!=($index+1)&&row.f_plan_month.indexOf('*&')==-1,'td-2':model.rows && model.rows.length!=($index+1)&&row.f_plan_month.indexOf('*&')!=-1,'td-3':model.rows && model.rows.length==($index+1)&&row.f_plan_month.indexOf('*&')!=-1,'td-4':model.rows && model.rows.length==($index+1)&&row.f_plan_month.indexOf('*&')==-1}" v-if="$parent.$parent.$parent.nameForSql.includes('f_plan_month')">{{row.f_plan_month.indexOf('*&')!=-1?'':row.f_plan_month}}</td>
            <td style="text-align:center" :class="{'td-0':row.f_no_checkplan==undefined,'td-1':model.rows && model.rows.length!=($index+1)&&row.f_no_checkplan.indexOf('*&')==-1,'td-2':model.rows && model.rows.length!=($index+1)&&row.f_no_checkplan.indexOf('*&')!=-1,'td-3':model.rows && model.rows.length==($index+1)&&row.f_no_checkplan.indexOf('*&')!=-1,'td-4':model.rows && model.rows.length==($index+1)&&row.f_no_checkplan.indexOf('*&')==-1}" v-if="$parent.$parent.$parent.nameForSql.includes('f_no_checkplan')">{{row.f_no_checkplan.indexOf('*&')!=-1?'':row.f_no_checkplan}}</td>
            <td style="text-align:center" :class="{'td-0':row.f_residential_area==undefined,'td-1':model.rows && model.rows.length!=($index+1)&&row.f_residential_area.indexOf('*&')==-1,'td-2':model.rows && model.rows.length!=($index+1)&&row.f_residential_area.indexOf('*&')!=-1,'td-3':model.rows && model.rows.length==($index+1)&&row.f_residential_area.indexOf('*&')!=-1,'td-4':model.rows && model.rows.length==($index+1)&&row.f_residential_area.indexOf('*&')==-1}" v-if="$parent.$parent.$parent.nameForSql.includes('f_residential_area')">{{row.f_residential_area.indexOf('*&')!=-1?'':row.f_residential_area}}</td>
            <td style="text-align:center" :class="{'td-0':row.f_plan_name==undefined,'td-1':model.rows && model.rows.length!=($index+1)&&row.f_plan_name.indexOf('*&')==-1,'td-2':model.rows && model.rows.length!=($index+1)&&row.f_plan_name.indexOf('*&')!=-1,'td-3':model.rows && model.rows.length==($index+1)&&row.f_plan_name.indexOf('*&')!=-1,'td-4':model.rows && model.rows.length==($index+1)&&row.f_plan_name.indexOf('*&')==-1}" v-if="$parent.$parent.$parent.nameForSql.includes('f_plan_name')">{{row.f_plan_name.indexOf('*&')!=-1?'':row.f_plan_name}}</td>
            <td style="text-align:center" :class="{'td-0':row && !row.f_checker_name,'td-1':model.rows && model.rows.length!=($index+1)&&row.f_checker_name && row.f_checker_name.indexOf('*&')==-1,'td-2':model.rows && model.rows.length!=($index+1)&&row.f_checker_name &&row.f_checker_name.indexOf('*&')!=-1,'td-3':model.rows && model.rows.length==($index+1)&&row.f_checker_name &&row.f_checker_name.indexOf('*&')!=-1,'td-4':model.rows && model.rows.length==($index+1)&&row.f_checker_name &&row.f_checker_name.indexOf('*&')==-1}" v-if="$parent.$parent.$parent.nameForSql && $parent.$parent.$parent.nameForSql.includes('f_checker_name')">{{row.f_checker_name && row.f_checker_name.indexOf('*&')!=-1?'':row.f_checker_name}}</td>
            <td style="text-align:center" :class="{'td-0':row && !row.f_user_type,'td-1':model.rows && model.rows.length!=($index+1)&&row.f_user_type && row.f_user_type.indexOf('*&')==-1,'td-2':model.rows && model.rows.length!=($index+1)&&row.f_user_type &&row.f_user_type.indexOf('*&')!=-1,'td-3':model.rows && model.rows.length==($index+1)&&row.f_user_type &&row.f_user_type.indexOf('*&')!=-1,'td-4':model.rows && model.rows.length==($index+1)&&row.f_user_type &&row.f_user_type.indexOf('*&')==-1}" v-if="$parent.$parent.$parent.nameForSql && $parent.$parent.$parent.nameForSql.includes('f_user_type')">{{row.f_user_type && row.f_user_type.indexOf('*&')!=-1?'':row.f_user_type}}</td>
            <td style="text-align:center" :class="{'td-0':row && !row.department,'td-1':model.rows && model.rows.length!=($index+1)&&row.department && row.department.indexOf('*&')==-1,'td-2':model.rows && model.rows.length!=($index+1)&&row.department &&row.department.indexOf('*&')!=-1,'td-3':model.rows && model.rows.length==($index+1)&&row.department &&row.department.indexOf('*&')!=-1,'td-4':model.rows && model.rows.length==($index+1)&&row.department &&row.department.indexOf('*&')==-1}" v-if="$parent.$parent.$parent.nameForSql && $parent.$parent.$parent.nameForSql.includes('department')">{{row.department && row.department.indexOf('*&')!=-1?'':row.department}}</td>
            <td style="text-align:center" v-if="$parent.$parent.$parent.nameForSql.includes('f_user_number')">{{row.f_user_number}}</td>
            <td style="text-align:center">{{row.f_plan_total}}</td>
            <td style="text-align:center">{{row.f_weishangmen}}</td>
            <td style="text-align:center">{{row.f_weijian}}</td>
            <td style="text-align:center">{{row.f_yishangmen}}</td>
            <td style="text-align:center">{{row.f_yijian}}</td>
            <td style="text-align:center"><nobr>{{row.f_yiwancheng}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_ruhu}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_chaichu}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_tingyong}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_weitongqi}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_jujian}}</nobr></td>
            <td style="text-align:center">{{row.f_buyu}}</td>
            <td style="text-align:center">{{row.f_buyu2}}</td>
            <td style="text-align:center">{{row.f_buyu3}}</td>
            <td style="text-align:center">{{row.f_buyu4}}</td>
            <td style="text-align:center"><nobr>{{row.f_shangmen_bv}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_check_bv}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_wangcheng_bv}}</nobr></td>
            <!--<td style="text-align: center;">-->
            <!--<button class="btn btn-link" @click.stop="$parent.$parent.$parent.showhistory(row)">查看</button>-->
            <!--</td>-->
          </tr>
        </template>
        <template partial='foot'>
          <td style="text-align: center" ><span><b>合计：</b></span></td>
          <th v-if="$parent.$parent.$parent.nameForSql.includes('f_plan_month')"></th>
          <th v-if="$parent.$parent.$parent.nameForSql.includes('f_no_checkplan')"></th>
          <th v-if="$parent.$parent.$parent.nameForSql.includes('f_residential_area')"></th>
          <th v-if="$parent.$parent.$parent.nameForSql.includes('f_plan_name')"></th>
          <th v-if="$parent.$parent.$parent.nameForSql.includes('f_checker_name')"></th>
          <th v-if="$parent.$parent.$parent.nameForSql.includes('f_user_type')"></th>
          <th v-if="$parent.$parent.$parent.nameForSql.includes('department')"></th>
          <th v-if="$parent.$parent.$parent.nameForSql.includes('f_user_number')"></th>
          <td style="text-align: center">{{model.sums.f_plan_total}}</td>
          <td style="text-align: center">{{model.sums.f_weishangmen}}</td>
          <td style="text-align: center">{{model.sums.f_weijian}}</td>
          <td style="text-align: center">{{model.sums.f_yishangmen}}</td>
          <td style="text-align: center">{{model.sums.f_yijian}}</td>
          <td style="text-align: center">{{model.sums.f_yiwancheng}}</td>
          <td style="text-align: center">{{model.sums.f_ruhu}}</td>
          <td style="text-align: center">{{model.sums.f_chaichu}}</td>
          <td style="text-align: center">{{model.sums.f_tingyong}}</td>
          <td style="text-align: center">{{model.sums.f_weitongqi}}</td>
          <td style="text-align: center">{{model.sums.f_jujian}}</td>
          <td style="text-align: center">{{model.sums.f_buyu}}</td>
          <td style="text-align: center">{{model.sums.f_buyu2}}</td>
          <td style="text-align: center">{{model.sums.f_buyu3}}</td>
          <td style="text-align: center">{{model.sums.f_buyu4}}</td>
          <td style="text-align: center">{{(parseFloat(model.sums.f_yishangmen) / parseFloat(model.sums.f_plan_total) * 100).toFixed(2) + '%'}}</td>
          <td style="text-align: center">{{(parseFloat(model.sums.f_ruhu) / parseFloat(model.sums.f_plan_total) * 100).toFixed(2) + '%'}}</td>
          <td style="text-align: center">{{(parseFloat(model.sums.f_yiwancheng) / parseFloat(model.sums.f_plan_total) * 100).toFixed(2) + '%'}}</td>

        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
  /**
   *阶梯气价查询列表
   */
  import {PagedList} from 'vue-client'
  import { HttpResetClass } from 'vue-client'
  import XLSX from 'xlsx'
  export default {
    data () {
      return {
        model: new PagedList('rs/sql/getCheckPlanAreaList', 99999,{},{
          f_plan_total:'',
          f_weishangmen:'',
          f_weijian:'',
          f_yishangmen:'',
          f_yijian:'',
          f_yiwancheng:'',
          f_ruhu:'',
          f_chaichu:'',
          f_tingyong:'',
          f_weitongqi:'',
          f_jujian:'',
          f_buyu:'',
          f_buyu2:'',
          f_buyu3:'',
          f_buyu4:'',
        }),
        // 公司下拉
        curorgid: [this.$login.f.orgid],
        row: {},
        f_orgid: '',
        nameForSql: [],
        groupNameForSql: '',
        listflag:false,
        nameflag:false,
        criteriaShow: false,
        f_check_start:new Date().getFullYear() + '-01',
        f_check_end:new Date().getFullYear() + '-12',
        f_safe_start:'',
        f_safe_end:'',
        planName:[{label: '全部', value: ''}],
        departments:[],
        exportExcelField: {
          f_plan_total:'计划总数',
          f_weishangmen:'未上门',
          f_weijian:'未安检',
          f_yishangmen:'已上门',
          f_yijian:'已安检',
          f_yiwancheng:'已完成',
          f_ruhu:'入户',
          f_chaichu:'拆除',
          f_tingyong:'停用',
          f_weitongqi:'未通气',
          f_jujian:'拒检',
          f_buyu:'到访不遇1',
          f_buyu2:'到访不遇2',
          f_buyu3:'到访不遇3',
          f_buyu4:'到访不遇3+',
          f_shangmen_bv:'上门率',
          f_check_bv:'安检率',
          f_wangcheng_bv:'完成率'
        }
      }
    },
    props: {
      row: {},
      config: {},
      ispartial: false,
      f_filialeid: {
        type: String
      }
    },
    ready () {
      this.nameForSql = ['f_plan_month', 'f_plan_name','f_checker_name','f_user_type','department']
      this.groupNameForSql = 'f_plan_month', 'f_plan_name','f_checker_name','f_user_type,department'
      this.pl()
      this.dp()
      // this.search()

    },
    methods: {
      exportexcel(){
        //tag
// 以上四行也可以直接一行搞定，如果不需要对表格数据进行修改的话
        const aa = document.getElementsByClassName("list_area table_sy excelid")[0]
        console.log(aa)
        let workbook = XLSX.utils.table_to_book(document.getElementsByClassName("list_area table_sy excelid")[0])
        try {
          XLSX.writeFile(workbook, '安检情况汇总导出.xlsx');
        } catch(e) {
          //tag;
        }
      },
      // 获取导出列
      getexportExcelField(){
        this.exportExcelField = {
          f_plan_total:'计划总数',
          f_weishangmen:'未上门',
          f_weijian:'未安检',
          f_yishangmen:'已上门',
          f_yijian:'已安检',
          f_yiwancheng:'已完成',
          f_ruhu:'入户',
          f_chaichu:'拆除',
          f_tingyong:'停用',
          f_weitongqi:'未通气',
          f_jujian:'拒检',
          f_buyu:'到访不遇1',
          f_buyu2:'到访不遇2',
          f_buyu3:'到访不遇3',
          f_buyu4:'到访不遇3+',
          f_shangmen_bv:'上门率',
          f_check_bv:'安检率',
          f_wangcheng_bv:'完成率'
        }
        let forName = this.groupNameForSql.split(",")
        for (let i = 0; i < forName.length; i++) {
          let ff = forName[i]
          if (ff==='f_plan_month') {
            this.exportExcelField.f_plan_month='计划月份'
          }
          if (ff==='f_no_checkplan') {
            this.exportExcelField.f_no_checkplan='计划类型'
          }
          if (ff==='f_plan_name') {
            this.exportExcelField.f_plan_name='计划名称'
          }
          if (ff==='f_checker_name') {
            this.exportExcelField.f_checker_name='安检员'
          }if (ff==='f_residential_area') {
            this.exportExcelField.f_residential_area='小区名称'
          }if (ff==='f_user_number') {
            this.exportExcelField.f_user_number='档案数量'
          }
        }
      },
       pl() {
         let getGasman = new HttpResetClass()
         getGasman.load('POST', `rs/sql/safe_singleTable_OrderBy`, {
          data: {
            items: "id,f_plan_name",
            tablename: "t_check_plan",
            condition: `f_filialeid = '${this.curorgid}'`,
            orderitem: "id"
          }
        }, {resolveMsg: null, rejectMsg: null}).then((plne) => {
          //tag
          //tag
          //tag
          for (let i = 0; i < plne.data.length; i++) {
            this.planName.push({label: plne.data[i].f_plan_name, value: plne.data[i].id})
          }
          //tag
        })
      },
      dp() {
        let depnames = new HttpResetClass()
        depnames.load('POST', `rs/sql/safe_singleTable_GroupBy`, {
          data: {
            items: " u.f_department_name ",
            tablename: "  t_check_plan cp left join t_user u on cp.f_checker_id=u.id ",
            condition: `f_filialeid = '${this.curorgid}' and u.f_department_name is not null `,
            groupitem: "u.f_department_name "
          }
        }, {resolveMsg: null, rejectMsg: null}).then((dpna) => {
          //tag
          //tag
          //tag
          for (let i = 0; i < dpna.data.length; i++) {
            this.departments.push({label: dpna.data[i].f_department_name, value: dpna.data[i].f_department_name})
          }
          //tag
        })
      },
      hiddenr() {
        this.$parent.isdetail = !this.$parent.isdetail
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
       },
      search () {
        this.$refs.paged.$refs.cri.search()
        this.$dispatch('search')
      },
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val.resids)
        this.f_filialeid = val[0]

      },
      selfSearch (args) {
        if (!this.f_orgid) {
          this.getorg([this.$login.f.orgid])
          args.condition = `f_filialeid  in ('${this.$login.f.orgid}') and ${args.condition}`
        }
        if (this.f_orgid) {
          args.condition = `f_filialeid  in ${this.f_orgid} and ${args.condition}`
        }
        if(this.f_check_start && this.f_check_end){
          if(new Date(this.f_check_start).getFullYear() == new Date(this.f_check_end).getFullYear() ){
            args.condition += ` and f_year>=${new Date(this.f_check_start).getFullYear()} and f_month>=${new Date(this.f_check_start).getMonth()+1} and f_month<=${new Date(this.f_check_end).getMonth()+1}`
          }else {
            args.condition += ` and (
              (f_year = ${new Date(this.f_check_start).getFullYear()} and f_month >= ${new Date(this.f_check_start).getMonth()+1})
              or
               ( f_year > ${new Date(this.f_check_start).getFullYear()} and  f_year < ${new Date(this.f_check_end).getFullYear()})
              or
               (f_year = ${new Date(this.f_check_end).getFullYear()} and f_month <= ${new Date(this.f_check_end).getMonth()+1}))`
          }
        } else {
          if(this.f_check_start){
            args.condition += ` and f_year>=${new Date(this.f_check_start).getFullYear()} and f_month>=${new Date(this.f_check_start).getMonth()+1}`
          }
          if(this.f_check_end){
            args.condition += ` and f_year<=${new Date(this.f_check_end).getFullYear()} and f_month<=${new Date(this.f_check_end).getMonth()+1}`
          }
        }
        if(this.f_safe_start && this.f_safe_end){
          args.condition += `and f_offsite_time >= '${this.f_safe_start}' and f_offsite_time <= '${this.f_safe_end}' `
        } else {
          if(this.f_safe_start){
            args.condition += ` and f_offsite_time >='${this.f_safe_start}'`
          }
          if(this.f_safe_end){
            args.condition += ` and f_offsite_time <='${this.f_safe_end}'`
          }
        }
        this.$refs.paged.$refs.grid.$el.scrollTop = 0
        if (this.groupNameForSql=='undefined'){
          //tag
          this.$showMessage("请至少选择一项进行汇总")
          return
        }
        this.model.paramSource = {groupName: `'${this.groupNameForSql}'`}
        this.model.search(args.condition, args.model)
      },

      // 拼接groupName1
      getGroupName1 () {
        var temp=['f_plan_month','f_no_checkplan','f_residential_area','f_plan_name','f_checker_name','f_user_number','f_user_type','department']
        var newtemp=[]

        for (var i=0;i<temp.length;i++){
          for (var j=0;j<this.nameForSql.length;j++){
            //tag
            if(temp[i]==this.nameForSql[j]){
              newtemp.push(this.nameForSql[j])
            }
          }
        }
        let str = ''

        for (var i=0;i < newtemp.length - 1; i++) {
          str += newtemp[i] + ','
        }
        str += newtemp[i]
        this.groupNameForSql = str.trim()
      }
    },
    watch: {
      // 'nameForSql' () {
      //
      //   this.getGroupName1()
      // },
      'nameForSql' () {
        var e = document.createEvent("MouseEvents");
        e.initEvent("click", true, true);
        document.getElementById("btnaaa").dispatchEvent(e);
      },
      'model.rows'(){
        //tag
        if(this.listflag){
          return;
        }
        this.listflag=true
        //tag
        var temp=['f_plan_month','f_no_checkplan','f_residential_area','f_plan_name','f_checker_name','f_user_number']
        var newtemp=[]
        for (var i=0;i<temp.length;i++){
          for (var j=0;j<this.nameForSql.length;j++){
            //tag
            if(temp[i]==this.nameForSql[j]){
              newtemp.push(this.nameForSql[j])
            }
          }
        }
        if((newtemp.includes('f_user_number')&&newtemp.length==2)||(!newtemp.includes('f_user_number')&&newtemp.length==1)){
          return
        }
        var temp=JSON.parse(JSON.stringify(this.model.rows))

        //遍历查询结果 为指定列增加样式
        for (var i=0;i<newtemp.length-1;i++){
          if(newtemp[i]=='f_user_number'){
            return;
          }
          //tag
          var ss=''
          for (var j=0;j<temp.length;j++){
            if(j>0&&i>0){
              var flag=false
              for(var t=i-1;t>-1;t--){
                //tag
                //tag
                //tag
                //tag
                if(temp[j-1][newtemp[t]]!=temp[j][newtemp[t]]&&(temp[j][newtemp[t]] !=null && temp[j][newtemp[t]].indexOf('*&') )==-1){
                  flag=true
                  break
                }
              }
              //tag
              if(flag){
                ss=temp[j][newtemp[i]]
                continue
              }
            }
            if(temp[j][newtemp[i]]==ss){
              temp[j][newtemp[i]]=temp[j][newtemp[i]]+'*&'
            }else {
              ss=temp[j][newtemp[i]]
            }
          }
        }
        //tag
        this.model.rows=JSON.parse(JSON.stringify(temp))
      }
    },
    computed:{
      exportParameter(){
        // excel 导出条件拼接
        return {
            condition: this.$refs.paged.model.condition,
            groupName: this.groupNameForSql
          }
      },
      excelStart () {
        return this.$login.r.includes('安检员考核导出')
      }
    }
  }
</script>

<style scoped>

  .td-0{
    border: 1px solid #000000;
  }

  .td-1{
    border: none;
    border-top: 1px solid #000000;
    border-left: 1px solid #000000;
    border-right: 1px solid #000000;
  }

  .td-2{
    border: none;
    border-left: 1px solid #000000;
    border-right: 1px solid #000000;
  }
  .td-4{
    border: none;
    border-top: 1px solid #000000;
    border-left: 1px solid #000000;
    border-right: 1px solid #000000;
    border-bottom: 1px solid #000000;
  }
  .td-3{
    border: none;
    border-left: 1px solid #000000;
    border-right: 1px solid #000000;
    border-bottom: 1px solid #000000;
  }
</style>
