<template lang="html">
  <div class="span" >
    <div class="mystyle2 ">
      <label class="control-label">汇总项</label>
      <input type="checkbox" id="year" value="year"  v-model="nameForSql"/>
      <label for="year">年份</label>
      <input type="checkbox" checked id="month" value="month" v-model="nameForSql"/>
      <label for="month">月份</label>
      <input type="checkbox" id="week" value="week" v-model="nameForSql"/>
      <label for="week">周</label>
      <input type="checkbox" id="day" value="day" v-model="nameForSql"/>
      <label for="day">日</label>
      <input type="checkbox" id="f_userType" value="f_user_type" v-model="nameForSql"/>
      <label for="f_userType">用户类型</label>
      <input type="checkbox" id="f_gasproperties" value="f_gasproperties" v-model="nameForSql"/>
      <label for="f_gasproperties">用气性质</label>
      <input type="checkbox" id="f_orgid" value="f_orgid" v-model="nameForSql"/>
      <label for="f_orgid">组织机构</label>
      <span style="float: right">
        <button class="button_search button_spacing" @click="searchData">查询</button>
        <button @click="$parent.notShowEform()" class="button_clear button_spacing" style="width: max-content">隐藏汇总</button>
        <export-excel :data="getCondition" class="button_export button_spacing"
                      :field="getfield"
                      sqlurl="rs/logic/exportfile" sql-name="NewDrillErrorEform" template-name='异常分析汇总'
                      :choose-col="true"></export-excel>
        <report-print class="button_export button_spacing" style="width: max-content" id="table" top='3cm' left='0' width='100%' height='100%'></report-print></span>
    </div>
    <div id="table">
      <table  class="table table-bordered">
        <thead class="text-left">
        <tr style="text-align:center">
          <p style="padding: 8px;text-align:center">用户用气汇总</p>
        </tr>
        <tr>
          <th v-if="nameForSql.includes('year')" style="text-align:center">年份</th>
          <th v-if="nameForSql.includes('month')" style="text-align:center">月份</th>
          <th v-if="nameForSql.includes('week')" style="text-align:center">周</th>
          <th v-if="nameForSql.includes('day')" style="text-align:center">日</th>
          <th v-if="nameForSql.includes('f_user_type')" style="text-align:center">用户类型</th>
          <th v-if="nameForSql.includes('f_gasproperties')" style="text-align:center">用气性质</th>
          <th v-if="nameForSql.includes('f_orgname')" style="text-align:center">组织机构</th>
          <th style="text-align:center"><nobr>总待处理</nobr></th>
          <th style="text-align:center"><nobr>总已处理</nobr></th>
          <th style="text-align:center"><nobr>所选异常待处理</nobr></th>
          <th style="text-align:center"><nobr>所选异常已处理</nobr></th>
        </tr></thead>
        <tbody>
        <tr v-for="item in model2">
          <td style="text-align:center" v-if="nameForSql.includes('year')">{{item.year}}</td>
          <td style="text-align:center" v-if="nameForSql.includes('month')">{{item.month}}</td>
          <td style="text-align:center" v-if="nameForSql.includes('week')">{{item.week}}</td>
          <td style="text-align:center" v-if="nameForSql.includes('day')">{{item.day}}</td>
          <td style="text-align:center" v-if="nameForSql.includes('f_user_type')">{{item.f_user_type}}</td>
          <td style="text-align:center" v-if="nameForSql.includes('f_gasproperties')">{{item.f_gasproperties}}</td>
          <td style="text-align:center" v-if="nameForSql.includes('f_orgname')">{{item.f_orgname}}</td>
          <td style="text-align:center">{{item.f_type1}}</td>
          <td style="text-align:center">{{item.f_type2}}</td>
          <td style="text-align:center">{{item.f_type3}}</td>
          <td style="text-align:center">{{item.f_type4}}</td>
        </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
  import {PagedList} from 'vue-client'
  import { all, HttpResetClass } from 'vue-client'
  export default {
    props:{
      signtype: {
        type: String,
        default: ''
      },
      condition: {
        type: String,
        default: '1=1'
      },
      // condition: {
      //   type: String,
      //   default: '1=1'
      // },
      // groupNameByDate: {
      //   type: [],
      //   default:['year']
      // }
    },
    data(){
      return{
        model2:null,
        nameForSql:['year'],
        groupNameForSql :'year',
        exportfield:{"year":"年份","month":"月份","week":"周","day":"日",
          "f_user_type":"用户类型","f_gasproperties":"用气性质","f_orgname":"组织机构"}
      }
    },
    ready (){
    },
    methods :{
      async searchData(){
        if(this.groupNameForSql && this.groupNameForSql !== 'undefined') {
          console.log(this.signtype)
          let load = new HttpResetClass()
          let res = await load.load('POST', 'rs/sql/signAnalysisEform',
            {data: {condition: this.condition, groupname: this.groupNameForSql,types:this.signtype}},
            {resolveMsg: null, rejectMsg: null})
          console.log('res返回', res)
          this.model2 = res.data
          console.log('res返回123', this.model2)
        }else{
          this.$showAlert('请选择汇总项', 'warning', 3000)
        }
      },
      //拼接groupName1
      getGroupName1(){
        console.log("this.nameForSql.length："+this.nameForSql.length)
        let str= ''
        let i=0
        for(;i<this.nameForSql.length-1;i++){
          str +=this.nameForSql[i]+','
        }
        str +=this.nameForSql[i]
        this.groupNameForSql =str.trim()
      }
    },
    computed: {
      getfield(){
        var fields={}
        let i = 0
        for (; i < this.nameForSql.length; i++) {
          if(this.nameForSql[i] in this.exportfield ){
            fields[this.nameForSql[i]]=this.exportfield[this.nameForSql[i]]
          }
        }
        fields.f_type1="总待处理"
        fields.f_type2="总已处理"
        fields.f_type3="所选异常待处理"
        fields.f_type4="所选异常已处理"
        return fields
      },
      getCondition() {
        return {
          condition: this.conditionForSql,
          groupname: this.groupNameForSql

        }
      }
    },
    watch:{
      'nameForSql'(){
        // this.nameForSql =this.groupNameByDate;
        this.getGroupName1()
      }
    }
  }
</script>

<style scoped>
  .mystyle2{
    width: 100%;
    height: 35px;
    /*background: #00A3F0;*/
    padding-left: 15px;
    float: left;
  }
  .datapanel {
    color: #333;
    background-color: white;
    box-shadow: darkgrey 0.5px 0.5px 0.5px 0.5px ;
    padding: 10px 30px 10px 30px;
    border-radius:15px;
  }

</style>
