<template>
    <div>
        <TableCommon :type="type" :query-data="queryData" :current-day-data="getDayData" :current-month-data="getMonthData"
            :current-all-data="getAllData" :get-personal-visits="getPersonalVisitsData" />
    </div>
</template>

<script setup lang="ts">

import { getList, getMonthVisits, getPersonalVisits, getTodayVisits, getTotalVisits } from '@/api/datamanagement/dataplatform';
import TableCommon from './TableCommon.vue';
import { ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus'
const type = ref('积分')



// 查询数据列表
function queryData(pageNumber: number, pageSize: number) {
    return getList(pageNumber, pageSize).then((res) => {

        console.log('table-querydata:', res)
        return res;
    }).catch(error => {
        ElMessageBox.alert(error, '异常', {
            confirmButtonText: 'OK',
            callback: () => {
                ElMessage({
                    type: 'info',
                    message: `查询数据失败`,
                })
            },
        })
        return Promise.reject()
    });

}


// 查询今日访问次数
function getDayData(userId: number) {
    return getTodayVisits(userId).then((res) => {

        console.log('table-getdaydata:', res)
        return res;
    }).catch(error => {
        ElMessageBox.alert(error, '异常', {
            confirmButtonText: 'OK',
            callback: () => {
                ElMessage({
                    type: 'info',
                    message: `查询数据失败`,
                })
            },
        })
        return Promise.reject();
    });

}

// 查询本月访问次数
function getMonthData(userId: number) {
    console.log('table-getmonthdata:', userId)
    return getMonthVisits(userId).then((res) => {
        console.log('table-getmonthdata:', res)
        return res;
    }).catch(error => {
        ElMessageBox.alert(error, '异常', {
            confirmButtonText: 'OK',
            callback: () => {
                ElMessage({
                    type: 'info',
                    message: `查询数据失败`,
                })
            },
        });
        return Promise.reject();
    });
}

// 查询累计访问次数
function getAllData(userId: number) {
    return getTotalVisits(userId).then((res) => {

        console.log('table-getalldata:', res)
        return res;
    }).catch(error => {
        ElMessageBox.alert(error, '异常', {
            confirmButtonText: 'OK',
            callback: () => {
                ElMessage({
                    type: 'info',
                    message: `查询数据失败`,
                })
            },
        })
        return Promise.reject();
    });

}



// 查询个人访问次数-
function getPersonalVisitsData(deptId: number, nickName: string, pageNumber: number, pageSize: number, staffNo: string) {
    console.log('table-getPersonalVisitsData-deptid', deptId);
    console.log('table-getPersonalVisitsData-nama', nickName);
    console.log('table-getPersonalVisitsData', pageNumber, pageSize);
    console.log('table-getPersonalVisitsData-staffno', staffNo);
    return getPersonalVisits(pageNumber, pageSize, staffNo, deptId, nickName).then((res) => {
        console.log('table-getPersonalVisitsData:', res)
        return res;
    }).catch(error => {
        ElMessageBox.alert(error, '异常', {
            confirmButtonText: 'OK',
            callback: () => {
                ElMessage({
                    type: 'info',
                    message: `查询数据失败`,
                })
            },
        })
        return Promise.reject();
    });
}

</script>

<style scoped></style>