import request from '../../utils/request'
import { ElMessage, ElMessageBox } from 'element-plus'
import { downloadExcel } from '@/utils/excel'

// 查询菜单报表
export function selectReportPortal(data) {
    return request({
        url: '/highReport/selectReportPortal',
        method: 'post',
        data,
    })
}

// 查询单个菜单报表
export function selectReportPortalMenu(data) {
    return request({
        url: '/highReport/selectReportPortalMenu',
        method: 'post',
        data,
    })
}

export function exportReportPortalData(params) {
    ElMessageBox.prompt('导出文件名字', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /\S/,
        inputErrorMessage: '文件名不能为空 (∩•̀ω•́)⊃-*⋆',
    }).then(({ value }) => {
        const data = {
            param: params,
            url: '/highReport/exportReportPortalData',
            fileName: value + '.xlsx',
        }
        setTimeout(() => {
            downloadExcel(data)
        }, 500)
    }).catch((res) => {
        if (res.code === '0') {
            ElMessage({
                message: res === null ? '导出excel成功!' : res.message,
                type: 'success',
                duration: 2000,
                showClose: true,
            })
        } else {
            ElMessage({
                message: res === null ? '导出excel失败!' : res.message,
                type: 'warning',
                duration: 3000,
                showClose: true,
            })
        }
    })

}

// 查询菜单报表钻取分组数据
export function selectReportGroup(data) {
    return request({
        url: '/highReport/selectReportGroup',
        method: 'post',
        data,
    })
}
