<template>
    <div class="main">
        <el-card class="box-card">
            <template #header>
                <div class="card-header">
                    <span>调用记录</span>
                </div>
            </template>
            <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="68px">
                <el-form-item label="Key" prop="secretKey">
                    <el-input
                    v-model="queryParams.secretKey"
                    placeholder="请输入Key"
                    clearable
                    @keyup.enter="handleQuery"
                    />
                </el-form-item>
                <el-form-item label="模型" prop="model">
                    <el-input
                    v-model="queryParams.model"
                    placeholder="请输入模型"
                    clearable
                    @keyup.enter="handleQuery"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                    <el-button icon="Refresh" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
            <el-table v-loading="loading" :data="usageRecordList" @selection-change="handleSelectionChange">
                <el-table-column label="调用时间" align="center" prop="createTime" />
                <el-table-column label="调用ID" align="center" prop="secretKey" />
                <el-table-column label="模型" align="center" prop="model" />
                <el-table-column label="prompt" align="center" prop="promptTokens" />
                <el-table-column label="completion" align="center" prop="completionTokens" />
                <el-table-column label="total" align="center" prop="totalTokens" />
                <el-table-column label="费用" align="center" prop="fee" />
            </el-table>
            
            <pagination
            v-show="total>0"
            :total="total"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            @pagination="getList"
            />
        </el-card>
    </div>
 </template>
 
 <script setup name="usage">
import { currentUserListUsageRecord } from "@/api/cert/usageRecord";
import { getUserProfile } from "@/api/system/user";

const { proxy } = getCurrentInstance();

const usageRecordList = ref([]);
const loading = ref(true);
const total = ref(0);

const data = reactive({
  queryParams: {
    pageNum: 1,
    userId: null,
    pageSize: 10,
    secretKey: null,
    model: null,
    msgId: null
  },
});

const { queryParams } = toRefs(data);

/** 查询使用记录列表 */
function getList() {
  loading.value = true;
  currentUserListUsageRecord(queryParams.value).then(response => {
    usageRecordList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

getList()
</script>
 
 <style scoped lang="scss">
 .main {
    padding: 20px;
 }
 </style>
 
 