<template>
    <div>
     <!-- 过滤筛选: <el-input v-model="search" clearable size="small" style="width: 250px" placeholder="筛选数据"/> -->
     <!-- <el-button @click="exportExcel" style="float:right;margin-bottom:10px" size="small" type="primary">导出Excel文件</el-button> -->
    
     
    </div>
</template>
<script>
import {getheight} from '../../assets/commjs/common'
import pagination from '../components/pagination/index'
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
import json2csv from "json2csv"
export default {
    computed:{
        // 实时监听表格
            tables: function() {
                const search = this.search
                if (search) {
                    return this.tableData.filter(dataNews => {
                        return Object.keys(dataNews).some(key => {
                            return String(dataNews[key]).toLowerCase().indexOf(search) > -1
                        })
                    })
                }
                return this.tableData
            }
        },
    data(){
       return {
        search:'',
        typedata:'电网拓扑',
        tableheight:undefined,   
        pageData: {
         pageNum: 3,
         pageSize: 15,
         total: 100
        },
        device:1
         
        
       }       
    },
    watch:{
       classvalue:function(a,b){
       if(a=='Power_Network'){
         this.typedata ='电网拓扑'
       }else if (a=='Manufacturer'){
         this.typedata ='终端厂家'
       }else if (a=='Voltage_Level'){
         this.typedata ='电压等级'  
       }else if (a=='Load_Type'){
         this.typedata ='干扰源类型'  
       }
     }
    },
    props:{
      classvalue:{
        type:String,
        default:undefined,
      },
      tableData:{
        type:Array,
        default:[]
      },
      loading:{type:Boolean,default:false}
    },
    components:{
      pagination
    },
    created(){
        
    },
    mounted(){
     //  this.tableheight = (getheight()*2.02)
       this.device=window.devicePixelRatio
      //   if(this.device==1){
      //  this.tableheight =(getheight()*2.12)
      // }
      // if(this.device==1.25){
      //   this.tableheight =(getheight()*2.21)
      // }
      // if(this.device==1.5){
      //   this.tableheight =(getheight()*1.93)
      // }
    },
    methods:{
         // 判断是否IE浏览器
       MyBrowserIsIE() {
      let isIE = false;
      if (
        navigator.userAgent.indexOf("compatible") > -1 &&
        navigator.userAgent.indexOf("MSIE") > -1
      ) {
        // ie浏览器
        isIE = true;
      }
      if (navigator.userAgent.indexOf("Trident") > -1) {
        // edge 浏览器
        isIE = true;
      }
      return isIE;
     }, 
     //创建a标签下载
      createDownLoadClick(content, fileName) {
      const link = document.createElement("a");
      link.href = encodeURI(content);
      link.download = fileName;
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
        },  
      exporeCSV(rows) {
      
      try {
        const result = json2csv.parse(rows, {
          // fields: fields,
          excelStrings: true
        });
        if (this.MyBrowserIsIE()) {
          // IE10以及Edge浏览器
          var BOM = "\uFEFF";
          // 文件转Blob格式
          var csvData = new Blob([BOM + result], { type: "text/csv" });
          navigator.msSaveBlob(csvData, `导出数据.csv`);
        } else {
          let csvContent = "data:text/csv;charset=utf-8,\uFEFF" + result;
          // 非ie 浏览器
          this.createDownLoadClick(csvContent, `导出数据.csv`);
        }
      } catch (err) {
        alert(err);
      }
     },
      exportExcel () {
                /* generate workbook object from table */
                let wb = XLSX.utils.table_to_book(document.querySelector('#rebateSetTable'));
                /* get binary string as output */
                let wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
                try {
                    FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), '数据表.xlsx');
                } catch (e)
                {
                    if (typeof console !== 'undefined'){}
                      //  console.log(e, wbout)
                }
                return wbout
     },
      changePageNum(data){
      this.pageData.pageNum = data
      this.$emit('changePageNumf')
      alert('父组件当前44444页'+ this.pageData.pageNum)
     },
     changePageSize(data){
        this.pageData.pageSize = data
        this.$emit('changePageSizef')
        alert('父组件当前4444条数'+ this.pageData.pageSize)
     },
     sortchange(){
       
     }
    }
    
}
</script>
<style lang="less" scoped>

</style>