<template>
  <el-table
    :data="tableData"
    ref="tableRef"
    highlight-current-row
    border
    >
      <el-table-column
        v-for="item in tableColums"
        :key="item.label"
        :label="item.label"
        :width="item.widthsty"
        :min-width="item.minwidthsty"
        align="center"
      >
        <template slot-scope="scope">
          <span>{{ scope.row[item.key] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" key="Copy" align="center" width="140">
        <template slot-scope="scope">
          <span class="editsty" @click="copyCode(scope.row)">
          <i class="el-icon-document-copy" />&nbsp;复制数据</span
        ><br />
        <span class="editsty" @click="viewTarget(scope.row)">查看数据</span>
      </template>
    </el-table-column>
    <div slot="empty">
      <tableNoData text="暂无指标" size="mini"/>
    </div>
  </el-table>
</template>
<script>
import { dataBaseInterface } from '@/api/api';
import * as preDictEdbInterface from '@/api/modules/predictEdbApi.js';
export default {
  props: {
    tableData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      tableColums: [
        {
          label: '指标名称',
          key: 'EdbName',
          enKey:'EdbNameEn',
					inputTip:'点击输入英文指标名称',
          minwidthsty: '150px',
        },
        {
          label: '指标ID',
          key: 'EdbCode',
          widthsty: '120px',
        },
        {
          label: '更新频度',
          key: 'Frequency',
          enKey:'FrequencyEn',
          minwidthsty: '60px',
        },
        {
          label: '单位',
          key: 'Unit',
          enKey:'UnitEn',
					inputTip:'英文单位',
          minwidthsty: '50px',
        },
        {
          label: '起始时间',
          key: 'StartDate',
          minwidthsty: '100px',
        },
        {
          label: '最新日期',
          key: 'LatestDate',
          minwidthsty: '90px',
        },
        {
          label: '最新值',
          key: 'LatestValue',
          minwidthsty: '90px',
        },
        {
          label: '最近更新',
          key: 'ModifyTime',
          minwidthsty: '100px',
        },
        {
          label: '数据来源',
          key: 'SourceName',
        },
      ],//表格列
    }
  },
  methods:{
    /* 用于复制指标 */
    async copyCode({EdbInfoId, EdbInfoCategoryType}) {
      let params = {
        PageSize: 100000,
        CurrentIndex: 1,
        EdbInfoId: EdbInfoId,
      }
      const res = EdbInfoCategoryType === 1 
        ? await preDictEdbInterface.edbDataInfo(params)
        : await dataBaseInterface.targetList(params);
      if (res.Ret !== 200) return

      let arr = res.Data.Item.DataList || [];

      let str = '日期\t 值\n';
      arr.forEach((item) => (str += `${item.DataTime}\t${item.Value}\n`));
      this.$copyText(str).then(
        (res) => {
          this.$message.success('已成功复制!');
        },
        (err) => {
          this.$message.error('复制失败!');
        }
      );
    },

    /* 查看数据 跳转指标库展开具体指标 */
    viewTarget({ UniqueCode,EdbInfoId,EdbInfoCategoryType,ClassifyId }) {
      let path = EdbInfoCategoryType ? '/predictEdb' : '/database';
      let {href} = this.$router.resolve({path, query: {
        code: UniqueCode,
        id: EdbInfoId,
        classifyId:ClassifyId
      }});
			window.open(href,'_blank');
    },
  },
}
</script>
<style scoped lang='scss'>

</style>
