<template>
  <div class="model-supplier">
    <div
      class="part-box part-box-filter part-box-flex"
      style="padding-bottom: 20px"
    >
      <div>
        <el-button
          v-if="checkPrivilege('LLM_SUPPLIER_INSERT')"
          type="success"
          @click="toAdd"
          >新增</el-button
        >
        <el-button
          v-if="checkPrivilege('LLM_ORG_CONFIG_VIEW')"
          type="primary"
          @click="orgSet"
          >机构设置</el-button
        >
      </div>

      <div>
        <el-tooltip effect="dark" content="刷新" placement="bottom">
          <el-button icon="el-icon-refresh-right" @click="getList"></el-button>
        </el-tooltip>
      </div>
    </div>
    <div class="part-box part-box-pad">
      <el-table ref="TableList" :data="dataList" v-loading="loading">
        <el-table-column prop="id" label="ID"></el-table-column>
        <el-table-column prop="name" label="名称"> </el-table-column>
        <el-table-column prop="qps" label="QPS限流"> </el-table-column>
        <el-table-column prop="createTime" label="创建时间">
          <span slot-scope="scope">{{
            scope.row.createTime | timestampFilter
          }}</span>
        </el-table-column>
        <el-table-column prop="updateTime" label="修改时间">
          <span slot-scope="scope">{{
            scope.row.updateTime | timestampFilter
          }}</span>
        </el-table-column>
        <el-table-column
          v-if="
            checkPrivilege('LLM_SUPPLIER_EDIT') ||
            checkPrivilege('LLM_MODEL_VIEW')
          "
          class-name="action-column"
          label="操作"
          width="120"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              v-if="checkPrivilege('LLM_SUPPLIER_EDIT')"
              class="btn-primary"
              type="text"
              @click="toEdit(scope.row)"
              >编辑</el-button
            >
            <el-button
              v-if="checkPrivilege('LLM_MODEL_VIEW')"
              class="btn-primary"
              type="text"
              @click="toModelManage(scope.row)"
              >模型管理</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <modify-supplier
      ref="ModifySupplier"
      :instance="curRow"
      @modified="getList"
    ></modify-supplier>
    <ModelManage ref="ModelManage" :curRow="curRow"></ModelManage>
    <OrgSet ref="OrgSet"></OrgSet>
  </div>
</template>

<script>
import { modelSupplierListQuery } from "../api";
import ModifySupplier from "./ModifySupplier.vue";
import ModelManage from "./ModelManage/index.vue";
import OrgSet from "./OrgSet/index.vue";

export default {
  name: "model-supplier",
  components: { ModifySupplier, ModelManage, OrgSet },
  data() {
    return {
      dataList: [],
      curRow: {},
      loading: false,
    };
  },
  created() {
    this.initData();
  },
  methods: {
    async getList() {
      this.loading = true;
      const data = await modelSupplierListQuery();
      this.dataList = data;
      this.loading = false;
    },
    initData() {
      this.getList();
    },
    toAdd() {
      this.curRow = {};
      this.$refs.ModifySupplier.open();
    },
    toEdit(row) {
      this.curRow = row;
      this.$refs.ModifySupplier.open();
    },
    toModelManage(row) {
      this.curRow = row;
      this.$refs.ModelManage.open();
    },
    orgSet() {
      this.$refs.OrgSet.open();
    },
  },
};
</script>

<style></style>
