<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="never">
          <template #header>
            <el-row :gutter="10" class="mb8">
              <right-toolbar v-model:showSearch="showSearch" :search="false" @queryTable="getList"></right-toolbar>
            </el-row>
          </template>

          <el-table v-loading="loading" :data="extractLogList">
            <el-table-column
              :label="label"
              :align="align || 'center'"
              prop="expertName"
              :min-width="minWidth || '100px'"
              v-for="{ label, prop, align, minWidth } in headers"
              :key="prop"
            >
              <template #default="{ row }">
                <span v-if="prop == 'personSum'" class="grade-num" @click="goToDetail(row)">
                  {{ row.personSum || '0' }}
                </span>
                <span v-else-if="prop == 'gradeInterval'"> {{ row.creditSectionLe }} - {{ row.creditSectionGe }} </span>
                <span v-else>{{ row[prop] || '-' }}</span>
              </template>
            </el-table-column>
          </el-table>

          <pagination v-show="page.total > 0" :total="page.total" v-model:page="page.pageNum" v-model:limit="page.pageSize" @pagination="getList" />
        </el-card>
      </div>
    </transition>
  </div>
</template>

<script setup lang="ts">
import { getLevelList } from '@/api/credit/rule';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const extractLogList = ref<any[]>([]);
const loading = ref(true);
const showSearch = ref(true);

interface Header {
  label: string;
  prop: string;
  align?: 'center' | 'left' | 'right';
  minWidth?: string | number;
}
const headers = ref<Header[]>([
  {
    label: '信用等级名称',
    prop: 'creditName'
  },
  {
    label: '对应信用分区间',
    prop: 'gradeInterval'
  },
  {
    label: '信用等级包含人数',
    prop: 'personSum'
  }
]);

const page = ref({
  pageNum: 1,
  pageSize: 10,
  total: 0
});

/** 查询expert列表 */
const getList = async () => {
  loading.value = true;
  const res = await getLevelList(page.value);
  extractLogList.value = res.data;
  loading.value = false;
};
const goToDetail = (row:any) => {
  proxy?.$router.push({
    path: '/credit/list',
    query: { credtieGe: row.creditSectionLe, crediteLe: row.creditSectionGe }
  });
};
onActivated(() => {
  getList();
});
onMounted(() => {
  getList();
});
</script>
<style lang="scss" scoped>
.grade-num {
  color: var(--el-color-primary);
  cursor: pointer;
}
</style>
