<!--知识图谱管理-->
<template>
  <div style="position: relative" v-rightClick="'#aaa'">
    <div class="topBox">
      <div class="title">知识图谱管理</div>
      <div class="instructions"></div>
    </div>
    <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-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="知识图谱名称" prop="formFilter.kgName" label-width="120px">
            <el-input class="filter-item" v-model="myDataSetPage.formFilter.kgName" :clearable="true" placeholder="知识图谱名称" />
          </el-form-item>
        </filter-box>
      </el-form>
      <div class="cardBox">
        <card v-for="item in myDataSetPage.tableData.impl.dataList" :item="item" :key="item.knowledgeId" :refresh="refresh"></card>
        <div class="box-card-2" v-for="item in 3" :key="item"></div>
      </div>
      <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 { KnowledgeGraph } from '@/api/gptController.js'
import editOrAdd from './dialog/editOrAdd'
import card from './card/index'

export default {
  data() {
    return {
      myDataSetPage: {
        formFilter: {
          kgName: ''
        },

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

  components: { card },

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

  methods: {
    getwidgetData(params) {
      if (params == null) params = {}
      params = {
        ...params,
        kGManageDtoFilter: { ...this.myDataSetPage.formFilter }
      }

      return new Promise((resolve, reject) => {
        KnowledgeGraph.list(this, params)
          .then((res) => {
            resolve({
              dataList: res.data.dataList,
              totalCount: res.data.totalCount
            })
          })
          .catch((e) => {
            reject(e)
          })
      })
    },
    add() {
      this.$dialog
        .show(
          '创建知识图谱',
          editOrAdd,
          {
            area: ['50%', '70%']
          },
          { isEdit: false }
        )
        .then((res) => {
          this.refresh()
        })
        .catch((e) => {
          this.refresh()
        })
    },

    del(item) {
      this.$confirm('是否确认删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = { kgId: item.kgId }
        KnowledgeGraph.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 {
  background-color: white;
  width: 100%;
  padding: 20px;
  overflow: auto;

  .add {
    margin-bottom: 20px;
  }
}

.cardBox {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;

  align-content: flex-start;
  justify-content: space-between;
}

.box-card-2 {
  width: calc(100% / 4 - 20px);
  min-width: 300px;
  flex-shrink: 0;
  height: 0;
}
</style>
