<!-- 数据标注 -->
<template>
  <div style="position: relative">
    <el-collapse v-model="activeName" accordion ref="collapse" v-resize="resize" style="margin-bottom:20px">
      <el-collapse-item name="1">
        <template slot="title">
          <div class="title">使用流程</div>
        </template>
        <div class="instructions">
          <div class="instructionsList">
            <div class="item" v-for="(item, index) in instructionsList" :key="index">
              <div>
                <img class="img" :src="item.img" alt="" />

                <div class="itemTitle">
                  <span class="head-index">{{ index + 1 }} &nbsp;</span>{{ item.title }}
                </div>

                <div class="itemDescribe">{{ item.describe }}</div>
              </div>

              <i v-if="instructionsList.length!==index+1" class="el-icon-arrow-right" style="margin-left: 50px; font-size: 30px; font-weight: bolder;color:#b8babf"></i>
            </div>
          </div>
        </div>
      </el-collapse-item>
    </el-collapse>
    <div class="tableBox" :style="{ height: tableHeight }">
      <el-form ref="myDataSetPage" :model="myDataSetPage" label-width="75px" :size="defaultFormItemSize" label-position="right" @submit.native.prevent>
        <filter-box :item-width="350" @search="refresh()" @reset="onReset">
          <el-form-item label="数据集名称" prop="formFilter.versionName" label-width="80px">
            <el-input class="filter-item" v-model="myDataSetPage.formFilter.versionName" :clearable="true" placeholder="数据集名称" />
          </el-form-item>
        </filter-box>
      </el-form>

      <vxe-table border show-header-overflow show-overflow :row-config="{ isHover: true }" :data="myDataSetPage.tableData.impl.dataList" min-height="96">
        <vxe-column field="versionName" title="数据集名称 > 版本"></vxe-column>
        <vxe-column field="dimensionType" title="标注类型 > 模版">
          <template slot-scope="scope">
            {{ LabelType.getValue(scope.row.dimensionType) }}
          </template>
        </vxe-column>
        <vxe-column field="dataVolume" title="数据量"></vxe-column>
        <vxe-column field="datasetId" title="数据集ID"></vxe-column>
        <vxe-column field="markProgress" title="标注进度"></vxe-column>
        <vxe-column field="createTime" title="创建时间"></vxe-column>
        <vxe-column field="operation" title="操作">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-menu" :size="defaultFormItemSize" @click="all(scope.row)">详情</el-button>
            <!-- <el-button type="text" :size="defaultFormItemSize">标注</el-button> -->
            <!-- <el-button type="text" :size="defaultFormItemSize" @click="edit(scope.row)">编辑</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;width: 100%;">
        <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>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
/* eslint-disable-next-line */
import { DropdownWidget, TableWidget, UploadWidget, ChartWidget } from '@/utils/widget.js'
import { DatasetVersion } from '@/api/gptController.js'
import editOrAdd from './dialog/editOrAdd'
import versionsTableBox from './versionsTableBox/index.vue'
export default {
  data() {
    return {
      activeName: '1',
      collapseHeight: 0,
      instructionsList: [
        {
          title: '选择数据集',
          describe: '选择已有数据集版本进行标注，支持文本对话、文生图类型。',
          img: require('@/assets/img/labelImg1.svg')
        },
        {
          title: '标注数据',
          describe: '根据指导提示对标注数据，文本对话支持手动输入和自动生成。',
          img: require('@/assets/img/labelImg2.svg')
        },
        {
          title: '发布数据集',
          describe: '标注所有数据并保存发布该版本数据集，以便后续使用。',
          img: require('@/assets/img/labelImg3.svg')
        },
        {
          title: '创建训练或评估任务',
          describe: '使用数据集在大模型训练中调优模型，或在大模型管理中评估模型。',
          img: require('@/assets/img/labelImg4.svg')
        }
      ],
      myDataSetPage: {
        formFilter: {
          versionName: '',
          inputStatus: 1
        },

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

  components: {},

  computed: {
    ...mapGetters(['getMainContextHeight']),
    tableHeight() {
      return this.getMainContextHeight - this.collapseHeight - 55 + 'px'
    }
  },

  methods: {
    getwidgetData(params) {
      if (params == null) params = {}
      params = {
        ...params,
        // orderParam: [
        //   {
        //     asc: true,
        //     dateAggregateBy: '',
        //     fieldName: ''
        //   }
        // ],
        // pageParam: {
        //   pageNum: 0,
        //   pageSize: 0
        // },
        datasetVersionDtoFilter: { ...this.myDataSetPage.formFilter }
      }
      console.log(params)
      return new Promise((resolve, reject) => {
        DatasetVersion.load(this, params)
          .then((res) => {
            resolve({
              dataList: res.data.dataList,
              totalCount: res.data.totalCount
            })
          })
          .catch((e) => {
            reject(e)
          })
      })
    },
    add() {
      this.$dialog
        .show(
          '创建模版',
          editOrAdd,
          {
            area: ['100%', '100%']
          },
          { isEdit: false }
        )
        .then((res) => {
          this.refresh()
        })
        .catch((e) => {})
    },
    edit(item) {
      this.$dialog
        .show(
          '修改模版',
          editOrAdd,
          {
            area: ['100%', '100%']
          },
          { isEdit: true, item: item }
        )
        .then((res) => {
          this.refresh()
        })
        .catch((e) => {})
    },
    del(item) {
      this.$confirm('是否确认删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = { versionId: item.versionId }
        DatasetVersion.delete(this, params)
          .then((res) => {
            this.$message.success('删除成功')
            this.refresh()
          })
          .catch((e) => {
            console.log(e)
          })
      })
    },
    all(row) {
      this.$dialog
        .show(
          row.datasetName,
          versionsTableBox,
          {
            area: ['100%', '100%']
          },
          { tableData: row, refresh: this.refresh }
        )
        .then((res) => {
          this.refresh()
        })
        .catch((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()
    },
    resize(e) {
      setTimeout(() => {
        this.collapseHeight = e?.height
      }, 300)
    }
  },
  mounted() {
    this.resize()
    this.formInit()
  }
}
</script>
<style lang="scss" scoped>
@import '@/assets/style/element-variables.scss';
.instructions {
  background-color: white;
  width: 100%;
  padding: 0px 20px 20px 20px;
  height: 200px;

  .instructionsList {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    .item {
      display: flex;
      align-items: center;
    }
  }
  .title {
    color: $--color-text-primary;
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 8px;
  }
  .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 {
  background-color: white;
  width: 100%;
  padding: 20px;
  overflow: auto;
  .add {
    margin-bottom: 20px;
  }
}
div /deep/ .el-collapse-item__content {
  padding-bottom: 0;
}
div /deep/ .el-collapse-item__header {
  padding-left: 20px;
}
</style>
