<!-- 我的数据集 -->
<template>
  <div style="position: relative">
    <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.dimensionType">
          <el-select v-model="myDataSetPage.formFilter.dimensionType" placeholder="请选择">
            <el-option v-for="item in LabelType.getList()" :key="item.value" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="数据集名称或id" prop="formFilter.searchString" label-width="120px">
          <el-input class="filter-item" v-model="myDataSetPage.formFilter.searchString" :clearable="true" placeholder="数据集名称或id" />
        </el-form-item>
      </filter-box>
    </el-form>
    <div class="tableBox" :style="{ height: tableHeight }">
      <el-button class="add" type="primary" icon="el-icon-plus" :size="defaultFormItemSize" @click="add()">创建数据集</el-button>
      <div v-for="(item,index) in myDataSetPage.tableData.impl.dataList" :key="item.datasetId">
        
        <tableItem v-model="myDataSetPage.tableData.impl.dataList[index]" @refresh="refresh"    />
        </div>
        
        <template v-if="this.myDataSetPage.tableData.impl.dataList.length<1" >
          <div class="table-empty unified-font">
            <img src="@/assets/img/empty.png">
            <span>暂无数据</span>
          </div>
        </template>
    </div>

  </div>
</template>

<script>
import { mapGetters } from 'vuex';
/* eslint-disable-next-line */
import { DropdownWidget, TableWidget, UploadWidget, ChartWidget } from '@/utils/widget.js';
import { MyDataSet } from '@/api/gptController.js';
import editOrAdd from './dialog/editOrAdd';
import tableItem from './tableItem';
export default {
  data () {
    return {
      myDataSetPage: {
        formFilter: {
          'searchString': '',
          'dimensionType': undefined
        },

        tableData: {
          impl: new TableWidget(this.getwidgetData, true, true, false, 'datasetId', false)
        }
      }
    };
  },
  provide () {
    return {
      refresh: this.refresh
    }
  },
  components: { tableItem },

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

  },

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

      return new Promise((resolve, reject) => {
        MyDataSet.list(this, params).then(res => {
          resolve({
            dataList: res.data.dataList.map((item) => {
              return {...item, isEdit: false }
            }),
            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 }
        MyDataSet.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 scoped>
.tableBox {
  background-color: white;
  width: 100%;
  padding: 20px;
  overflow: auto;
}
.add {
  margin: 0 0 20px 0;
}
</style>
