<!-- 数据清洗 -->
<template>
  <div style="position: relative">
    <el-collapse v-model="activeName" accordion ref="collapse" v-resize="resize">
      <el-collapse-item name="1">
        <template slot="title">
          <div class="title">使用说明</div>
        </template>
        <div class="instructions">
          <div class="describe">
            数据清洗是面向post-pretrain场景下预训练泛文本数据的一站式数据处理方案，通过对数据进行异常清洗、文本过滤、文本去重和去除隐私信息，大幅提升数据质量，优化模型训练效果。
          </div>
          <div class="instructionsList">
            <div
              class="item"
              v-for="(item, index) in instructionsList"
              :key="index"
            >
              <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>
          </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="search()" @reset="onReset">
          <el-form-item label-width="0px">
            <el-button
              class="add"
              type="primary"
              icon="el-icon-plus"
              :size="defaultFormItemSize"
              @click="add()"
              >创建任务</el-button
            >
          </el-form-item>
          <el-form-item
            label="数据集名称或id"
            prop="formFilter.dataName"
            label-width="120px"
          >
            <el-input
              class="filter-item"
              v-model="myDataSetPage.formFilter.dataName"
              :clearable="true"
              placeholder="数据集名称或id"
            />
          </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="versions" title="版本"></vxe-column>
        <vxe-column field="versionsId" title="版本ID"></vxe-column>
        <vxe-column field="importState" title="导入状态"></vxe-column>
        <vxe-column field="derivedState" title="导出状态"></vxe-column>
        <vxe-column field="cleanCondition" title="清洗状态"></vxe-column>
        <vxe-column field="cleanCondition" title="增强状态"></vxe-column>
        <vxe-column field="cleanCondition" title="发布状态"></vxe-column>
        <vxe-column field="cleanCondition" title="标注类型>模板"></vxe-column>
        <vxe-column field="operation" title="操作">
          <!-- <template slot-scope="scope">
              <el-button
                type="text"
                :size="defaultFormItemSize"
                @click="dataImport(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;">
        <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 { ModelSquare } from '@/api/gptController.js';
import editOrAdd from './dialog/editOrAdd';
export default {
  data () {
    return {
      activeName: '1',
      collapseHeight: 0,
      instructionsList: [
        {
          title: '选择数据集',
          describe: '从平台数据集管理中选择要清洗前和强洗后的数据集。',
          img: require('@/assets/img/step0.png')
        },
        {
          title: '选择数据集',
          describe: '从平台数据集管理中选择要清洗前和强洗后的数据集。',
          img: require('@/assets/img/step1.png')
        },
        {
          title: '选择数据集',
          describe: '从平台数据集管理中选择要清洗前和强洗后的数据集。',
          img: require('@/assets/img/step2.png')
        },
        {
          title: '选择数据集',
          describe: '从平台数据集管理中选择要清洗前和强洗后的数据集。',
          img: require('@/assets/img/step3.png')
        },
        {
          title: '选择数据集',
          describe: '从平台数据集管理中选择要清洗前和强洗后的数据集。',
          img: require('@/assets/img/step4.png')
        }
      ],
      myDataSetPage: {
        formFilter: {
          'modelDescribe': '',
          'modelId': 0,
          'modelName': '',
          'modelType': 0,
          'versionCount': 0
        },

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

  components: {},

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

  },

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

      return new Promise((resolve, reject) => {
        ModelSquare.list(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 = { batchTaskId: item.batchTaskId }
        ModelSquare.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();
    },
    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: 250px;

  .instructionsList {
    display: flex;
    flex-direction: row;
    justify-content: space-around;

  }
  .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>
