<!--详情 -->
<template>

    <div class="tableBox" >
      <vxe-table border show-header-overflow show-overflow :row-config="{ isHover: true }" :data="myDataSetPage.tableData.impl.dataList" min-height="96">
        <!-- <vxe-column field="index" title="序号"></vxe-column> -->
        <vxe-column :field="'data.'+item" :title="item" v-for="item in columnList" :key="item"></vxe-column>
  
        <vxe-column field="operation" title="操作" width="150px">
          <template slot-scope="scope">
            <el-button type="text" :size="defaultFormItemSize" @click="check(scope.row)">查看</el-button>
            <el-button type="text" :size="defaultFormItemSize" @click="label(scope.row)" v-if="row.dimensionType===0" >标注</el-button>
            <el-button type="text" :size="defaultFormItemSize" @click="del(scope.row)">删除</el-button>
          </template>
        </vxe-column>
      </vxe-table>
      <el-row slot="pagination" type="flex" justify="end" style="margin-top: 16px;">
        <el-pagination :total="myDataSetPage.tableData.impl.totalCount" :current-page="myDataSetPage.tableData.impl.currentPage" :page-size="myDataSetPage.tableData.impl.pageSize" :page-sizes="[10, 20, 50, 100]" layout="total, prev, pager, next, sizes" @current-change="myDataSetPage.tableData.impl.onCurrentPageChange" @size-change="myDataSetPage.tableData.impl.onPageSizeChange">
        </el-pagination>
      </el-row>
    </div>

</template>

<script>
import { mapGetters } from 'vuex';
/* eslint-disable-next-line */
import { DropdownWidget, TableWidget, UploadWidget, ChartWidget } from '@/utils/widget.js';
import { DatasetData } from '@/api/gptController.js';
import label from './label.vue';
export default {
  data () {
    return {
      myDataSetPage: {

        tableData: {
          impl: new TableWidget(this.getwidgetData, true, true, false, undefined, false)
        }
      },
      columnList: []
    };
  },

  components: {},
  props: ['row'],
  computed: {
    ...mapGetters(['getMainContextHeight']),
    tableHeight () {
      return this.getMainContextHeight + 'px';
    }

  },

  methods: {
    getwidgetData (params) {
      if (params == null) params = {};
      params = {
        ...params,
        // orderParam: [
        //   {
        //     asc: true,
        //     dateAggregateBy: '',
        //     fieldName: ''
        //   }
        // ],
        // pageParam: {
        //   pageNum: 0,
        //   pageSize: 0
        // },
        versionId: this.row.versionId
      }

      return new Promise((resolve, reject) => {
        DatasetData.list(this, params).then(res => {
          let dataList = res.data.dataList.map((item) => {
            try {
              var obj = JSON.parse(item.data);
            } catch (err) {
              console.log('JSON解析错误：' + err);
            }
            return {
              ...item,
              data: obj
            }
          })
          if (this.columnList.length === 0) {
            for (const key in dataList[0].data) {
              if (Object.hasOwnProperty.call(dataList[0].data, key)) {
                this.columnList.push(key)
              }
            }
          }

          resolve({
            dataList,
            totalCount: res.data.totalCount
          });
        }).catch(e => {
          reject(e);
        });
      });
    },
    check (row) {
      this.$alert(row.data, '详情', {
        confirmButtonText: '确定',
        callback: action => {
      
        }
      });
    },
    label (row) { // 标注
      this.$dialog.show('标注', label, {
        area: ['70%', '50%']
      }, { row: row, columnList: this.columnList, refresh: this.refresh}).then(res => {
        this.refresh()
      }).catch(e => { });
    },
    del (item) {
      this.$confirm('是否确认删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = { id: item._id, versionId: item.versionId}
        DatasetData.delete(this, params).then(res => {
          this.$message.success('删除成功');
          this.refresh()
        }).catch(e => {
          console.log(e);
        });
      }
      );
    },
    refresh (reloadData = false) {
      if (reloadData) {
        this.myDataSetPage.tableData.impl.refreshTable(true, 1);
      } else {
        this.myDataSetPage.tableData.impl.refreshTable();
      }
    },
    onReset () {
      this.$refs.myDataSetPage.resetFields();
      this.refresh(true);
    },
    formInit () {
      this.refresh();
    }

  },

  mounted () {
    this.formInit()
  }

};
</script>
<style lang="scss" scoped>
@import "@/assets/style/element-variables.scss";
.topBox {
  background-color: white;
  width: 100%;
  height: 95px;
  margin-bottom: 16px;
  .title {
    color: $--color-text-primary;
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 8px;
    padding: 20px 20px 10px 20px;
  }
}
.instructions {
  padding: 0px 20px 20px 20px;

  .describe {
    color: $--color-text-secondary;
    margin-bottom: 16px;
  }
  .itemTitle {
    color: $--color-text-primary;
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 8px;
  }
  .head-index {
    font-size: 24px;
    color: #e8e9eb;
    line-height: 32px;
  }
  .itemDescribe {
    width: 170px;
    color: $--color-text-secondary;
  }
  .img {
    height: 72px;
    width: 140px;
  }
}
.tableBox {
  position: relative;
  background-color: white;
  width: 100%;
  padding: 20px;
  height: 100%;
  overflow: auto;
  .add {
    margin-bottom: 20px;
  }
}

</style>
