<!--模型广场 -->
<template>
  <div style="position: relative">
    <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="模型名称" prop="formFilter.modelName" label-width="70px">
            <el-input class="filter-item" v-model="myDataSetPage.formFilter.modelName" :clearable="true" placeholder="模型名称" />
          </el-form-item>
        </filter-box>
      </el-form>

      <card :dataList='myDataSetPage.tableData.impl.dataList' :refresh="refresh" @particulars="particulars" @sft="sft" @assess="assess" @deploy="deploy"></card>
      <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 { MyModel } from '@/api/gptController.js';

import card from './card/index';
import particulars from './particulars/index';
export default {
  data () {
    return {
      myDataSetPage: {
        formFilter: {
   
          'modelName': '',
          'isBaseModel': 1
        },

        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,
        // orderParam: [
        //   {
        //     asc: true,
        //     dateAggregateBy: '',
        //     fieldName: ''
        //   }
        // ],
        // pageParam: {
        //   pageNum: 0,
        //   pageSize: 0
        // },
        modelManageDtoFilter: { ...this.myDataSetPage.formFilter }
      }

      return new Promise((resolve, reject) => {
        MyModel.list(this, params).then(res => {
          resolve({
            dataList: res.data.dataList,
            totalCount: res.data.totalCount
          });
        }).catch(e => {
          reject(e);
        });
      });
    },

    sft (item) { // sft

    },
    assess (item) { // 评估

    },
    deploy (item) { // 部署

    },
    particulars (item) {
      this.$dialog.show('详情', particulars, {
        area: ['100%', '100%']
      }, { tableItem: item }).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();
    }

  },

  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;
  }
}
</style>
