<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="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="120px">
            <el-form-item label="信用分事由" prop="integralReason">
              <el-input v-model="queryParams.integralReason" placeholder="请输入专家姓名" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="信用分变动时间" prop="changeTime" style="width: 330px">
              <el-date-picker
                clearable
                v-model="queryParams.changeTime"
                value-format="YYYY-MM-DD HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              />
            </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-card>

        <el-card shadow="never" class="mt-[10px]">
          <template #header>
            <el-row :gutter="10" class="mb8">
              <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
          </template>

          <el-table v-loading="loading" :data="extractLogList">
            <el-table-column label="序号" width="50px" type="index"></el-table-column>
            <el-table-column
              :label="label"
              :align="align || 'center'"
              prop="integralReason"
              :min-width="minWidth || '100px'"
              v-for="{ label, prop, align, minWidth } in headers"
              :key="prop"
            >
              <template #default="{ row }">
                <span>{{ 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 { getTableList } from '@/api/credit/detail';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;

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

const route = useRoute();
const queryFormRef = ref<ElFormInstance>();

interface Header {
  label: string;
  prop: string;
  align?: 'center' | 'left' | 'right';
  minWidth?: string | number;
}
const headers = ref<Header[]>([
  {
    label: '编号',
    prop: 'dataNumber'
  },
  {
    label: '信用分事由',
    prop: 'pointReason'
  },
  {
    label: '信用分',
    prop: 'eachScore'
  },
  {
    label: '信用分变动时间',
    prop: 'updateTime'
  }
]);
const page = ref({
  pageNum: 1,
  pageSize: 10,
  total: 0
});
const queryParams = ref<any>({
  parkName: '',
  changeTime: []
});

/** 查询expert列表 */
const getList = async () => {
  loading.value = true;
  let startTime = queryParams.value.changeTime[0] || '';
  let endTime = queryParams.value.changeTime[1] || '';
  const res = await getTableList({ ...queryParams.value, ...page.value, startTime, endTime, expertId: route.query.expertId });
  extractLogList.value = res.data;
  page.value.total = res.total;
  loading.value = false;
};

/** 搜索按钮操作 */
const handleQuery = () => {
  page.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

onActivated(() => {
  getList();
});
onMounted(() => {
  getList();
});
</script>
<style lang="scss" scoped>
.model-title {
  margin-bottom: 24px;
  font-size: 20px;
  font-weight: bold;
  margin-top: 20px;
}

.trend-main {
  height: 420px;
  background-color: #0c2139;
  border-radius: 6px;
}
</style>
