<!--我的收藏-->

<template>
  <div class="myCollection">
    <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.templateName">
          <el-input class="filter-item" v-model="myDataSetPage.formFilter.templateName" :clearable="true" placeholder="模板名称" />
        </el-form-item>
        <!-- <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> -->
      </filter-box>
    </el-form>
    <div class="listBox">
<card :dataList='myDataSetPage.operationLog.impl.dataList' :refresh="refresh"></card>

      <el-row slot="pagination" type="flex" justify="end"  style="margin-top: 16px;width: 100%;">
        <el-pagination :total="myDataSetPage.operationLog.impl.totalCount" :current-page="myDataSetPage.operationLog.impl.currentPage" :page-size="myDataSetPage.operationLog.impl.pageSize" :page-sizes="[10, 20, 50, 100]" layout="total, prev, pager, next, sizes" @current-change="myDataSetPage.operationLog.impl.onCurrentPageChange" @size-change="myDataSetPage.operationLog.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 { TemplateController } from '@/api/gptController.js';
import createTemplate from '../components/dialog/createTemplate';
import card from '../components/card/index';
export default {
  data () {
    return {
      myDataSetPage: {
        formFilter: {
          interfaceAddress: '',
          pageView: 0,
          parameterFormat: '',
          scenarioType: 0,
          searchString: '',
          templateContent: '',
          templateFramework: 0,
          templateId: 0,
          templateLabel: '',
          templateName: '',
          templateSource: 0,
          variable: ''
        },

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

  components: {card},

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

  methods: {
    getwidgetData (params) {
      if (params == null) params = {};
      params = {
        ...params,
        // orderParam: [
        //   {
        //     asc: true,
        //     dateAggregateBy: '',
        //     fieldName: ''
        //   }
        // ],
        // pageParam: {
        //   pageNum: 0,
        //   pageSize: 0
        // },
        promptTemplateDtoFilter: {
          interfaceAddress: this.myDataSetPage.formFilter.interfaceAddress,
          pageView: this.myDataSetPage.formFilter.pageView,
          parameterFormat: this.myDataSetPage.formFilter.parameterFormat,
          scenarioType: this.myDataSetPage.formFilter.scenarioType,
          searchString: this.myDataSetPage.formFilter.searchString,
          templateContent: this.myDataSetPage.formFilter.templateContent,
          templateFramework: this.myDataSetPage.formFilter.templateFramework,
          templateId: this.myDataSetPage.formFilter.templateId,
          templateLabel: this.myDataSetPage.formFilter.templateLabel,
          templateName: this.myDataSetPage.formFilter.templateName,
          templateSource: this.myDataSetPage.formFilter.templateSource,
          variable: this.myDataSetPage.formFilter.variable
        }
      }
      return new Promise((resolve, reject) => {
        TemplateController.listForCollect(this, params).then(res => {
          resolve({
            dataList: res.data.dataList,
            totalCount: res.data.totalCount
          });
        }).catch(e => {
          reject(e);
        });
      });
    },
    add () {
      this.$dialog.show('创建模版', createTemplate, {
        area: ['100%', '100%']
      }, { isEdit: false }).then(res => {
        this.refresh();
      }).catch(e => { });
    },
    edit () {
      this.$dialog.show('修改模版', createTemplate, {
        area: ['100%', '100%']
      }, { isEdit: true }).then(res => {
        this.refresh();
      }).catch(e => { });
    },
    refresh (reloadData = false) {
      if (reloadData) {
        this.myDataSetPage.operationLog.impl.refreshTable(true, 1);
      } else {
        this.myDataSetPage.operationLog.impl.refreshTable();
      }
    },
    onReset () {
      this.$refs.myDataSetPage.resetFields();
      this.refresh(true);
    },
    formInit () {
      this.refresh();
    },

    handleChange () { }

  },

  mounted () {
    this.formInit()
  }
};
</script>
<style lang="scss" scoped>
@import "@/assets/style/element-variables.scss";
.myCollection {
  overflow: auto;
  height: 100%;
}
.topBox {
  background-color: white;
  width: 100%;
  // height: 130px;
  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;
  }
}
.topButtonBox {
  display: flex;
  margin-bottom: 20px;
  height: 120px;

  .icon {
    width: 56px;
    height: 56px;
    background: #eef3fe;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    img {
      width: 32px;
      height: 32px;
    }
  }
  .button {
    flex: 1;
    border: none;
    cursor: pointer;
    padding: 24px;
    display: flex;
    flex-direction: row;
    align-items: center;
    background: #ffffff;
    border-radius: 6px;
  }
  .button + .button {
    margin-left: 16px;
  }
  .button:hover {
    box-shadow: 0 2px 8px #070c141f;
  }
  .topTitle {
    padding: 0 24px 10px 24px;
    font-size: 16px;
  }
  .topContent {
    padding-left: 24px;
  }
}
.listBox {
  background-color: white;
  width: 100%;
  height: fit-content;
  padding: 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;

  align-content: flex-start;
  justify-content: space-between;
}
.tagBox {
  margin-bottom: 10px;
}
 
</style>
