<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="{'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-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>-->
                <button id="btnaaa" style="float: right" class="button_search" @click="$parent.$parent.getGroupName1(),search(),$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}" >
              <label class="font_normal_body">起始时间</label>
              <datepicker
                :value.sync="$parent.$parent.f_check_start"
                placeholder='起始时间' style="width:60%"
                :format="'yyyy-MM-dd 00:00:00'"
                :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}" >
              <label class="font_normal_body">结束时间</label>
              <datepicker
                :value.sync="$parent.$parent.f_check_end"
                placeholder='结束时间' style="width:60%"
                :format="'yyyy-MM-dd 23:59:59'"
                :show-rest-button="reset">
              </datepicker>
            </div>
          </div>
        </div>

      </criteria>
      <data-grid :model="model" partial='list'  class="list_area table_sy"  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>
            <th>
              <nobr>入户率</nobr>
            </th>
            <!--<th>-->
            <!--<nobr>查看</nobr>-->
            <!--</th>-->
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center">{{$index + 1}}</td>
            <td style="text-align:center">{{row.f_checker_name}}</td>
            <td style="text-align:center"><nobr>{{row.yijian}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.ruhu}}({{row.daofang3}})</nobr></td>
            <td style="text-align:center">{{row.daofang}}</td>
            <td style="text-align:center"><nobr>{{row.jujian}}</nobr></td>
            <td style="text-align:center"><nobr>{{(row.ruhu/row.yijian*100).toFixed(2)}}%</nobr></td>

          </tr>
        </template>
        <template partial='foot' >
          <td style="text-align:center" v-show="model.rows.length!='0'"></td>
          <td style="text-align:center" v-show="model.rows.length!='0'">合计</td>
          <td style="text-align:center" v-show="model.rows.length!='0'"><nobr>{{model.sums.yijian}}</nobr></td>
          <td style="text-align:center" v-show="model.rows.length!='0'"><nobr>{{model.sums.ruhu}}({{model.sums.daofang3}})</nobr></td>
          <td style="text-align:center" v-show="model.rows.length!='0'">{{model.sums.daofang}}</td>
          <td style="text-align:center" v-show="model.rows.length!='0'"><nobr>{{model.sums.jujian}}</nobr></td>
          <td style="text-align:center" v-show="model.rows.length!='0'" ><nobr>{{ (model.sums.ruhu*100/model.sums.yijian).toFixed(2)}}%</nobr></td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>

  import {PagedList} from 'vue-client'
  import { HttpResetClass } from 'vue-client'
  export default {
    data () {
      return {
        model: new PagedList('rs/sql/checkerCount', 99999,{},{yijian:'',ruhu:'',daofang:'',jujian:'',daofang3:''}),
        // 公司下拉
        curorgid: [this.$login.f.orgid],
        row: {},
        f_orgid: '',
        nameForSql: [],
        groupNameForSql: '',
        listflag:false,
        nameflag:false,
        criteriaShow: false,
        f_check_start:'',
        f_check_end:'',
        planName:[{label: '全部', value: ''}],
      }
    },
    props: {
      row: {},
      config: {},
      ispartial: false,
      f_filialeid: {
        type: String
      }
    },
    ready () {

      this.search()

    },
    methods: {
      hiddenr() {
        this.$parent.isdetail = !this.$parent.isdetail
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
       },
      search () {
        this.$refs.paged.$refs.cri.search()
        this.$dispatch('search')

      },
      getorg (val) {
        if(val && val.length > 0){
          this.f_orgid = this.$login.convertToIn(val)
          this.f_filialeid = val[0]
        }
      },
      selfSearch (args) {
        if (!this.f_orgid) {
          this.getorg([this.$login.f.orgid])
        }
        if (this.f_orgid) {
          args.condition = `f_filialeid  in ${this.f_orgid} and ${args.condition}`
        }
        if(this.f_check_start){
          args.condition += ` and f_upload_date>='${this.f_check_start}' `
        }
        if(this.f_check_end){
          args.condition += ` and f_upload_date<='${this.f_check_end}' `
        }
        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']
        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]].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))
      }
    }
  }
</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>
