<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch">
        <el-card shadow="hover" class="mb-[10px]">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label-width="140px" label="报表类型" prop="reoprtType">
              <el-select v-model="queryParams.reoprtType" placeholder="请选择专家费用标准类型" clearable>
                <el-option v-for="dict in invoices_report_type" :key="dict.value" :label="dict.label" :value="dict.value" />
              </el-select>
            </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">
          <template #header>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
              </el-col>
              <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
          </template>

          <el-table v-loading="loading" :data="tableRows">
            <el-table-column label="序号" type="index" width="50px"></el-table-column>
            <el-table-column label="报表编号" prop="reportCode" />
            <el-table-column label="报表名称" prop="reportName">
              <template #default="{row}">
                <el-button type="primary" link @click="goToReportDeatil(row)">{{ row.reportName }}</el-button>
              </template>
            </el-table-column>
            <el-table-column label="报表类型" prop="reportType" />
            <el-table-column label="周期" prop="typeDesc" />
            <el-table-column label="时间范围" prop="dateRange"></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/expertMoneyConfig/statistics"
const router = useRouter()
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { invoices_report_type } = toRefs<any>(proxy?.useDict('invoices_report_type'));
const showSearch = ref(true);

const page = ref({
  pageNum: 1,
  pageSize: 10,
  total: 0
});
const queryFormRef = ref();
const queryParams = ref<any>({
  reoprtType: '',
});

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

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};
const tableRows = ref([])
const loading = ref(false)
const getList = async () => {
  loading.value = true;
  let res = await getTableList({
    ...queryParams.value,
    ...page.value
  })
  
  tableRows.value = res.rows
  loading.value = false
};
const goToReportDeatil = (row) => {
  router.push({
    path:'/expertmoneyconfig/statisticsDetail',
    query:{
      id: row.id
    }
  })
}
onMounted(() => {
  getList()
})
</script>
