/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2022-12-21 11:13:51
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2023-08-11 11:03:45
 * @FilePath: /BudgetManaSystem/src/pages/budgetMana/monthlyInfoCheck/service.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */




import { request } from '@@/plugin-request';
import axios from 'axios';




//获取树结构单元数据

export type getTreeDataRespType = {
    code: number,
    name: string,
    map: boolean,
    parentCode: string,
    unitType?: string,
    child: getTreeDataRespType[]
}

export const getTreeData = (computeDate: string, type: string) => {

    return request<getTreeDataRespType[]>('/performance/secondSetting/getSecondDataUnitList', {
        method: 'GET',
        params: { computeDate, type }
    })
}



//获取人员数据核定

export type GetSecondaryDistriComputeParams = {
    computeDate: string; //核算年月
    unitCode: string; //核算单元代码
    current: number;
    pageSize: number;
}

export const getSecondaryDistriComputeTableData = (params: GetSecondaryDistriComputeParams) => {

    return request('/performance/secondSetting/getSecondDataList', {
        method: 'GET',
        params: { ...params }
    })

}

//保存编辑后结果

export const save = (data: any) => {
    return request('/performance/secondSetting/saveSecondData', {
        method: 'POST',
        data
    })

}


//获取当前提交状态
export const getCurrentCommitStatusReq = (params: {
    computeDate: string,
    unitCode: string
}) => {

    return request('/performance/secondSetting/getSubmitStatus', {
        method: 'GET',
        params: params
    })

}



//提交请求

export type CommitRequestParamsType = {
    computeDate: string,
    unitCode: string,
    submit: string
}
export const commitRequest = (data: CommitRequestParamsType) => {

    return request('/performance/secondSetting/secondSubmit', {
        method: 'POST',
        params: data
    })

}



//获取数据

export const getDataByBtn = (computeDate: string, unitCode: string) => {

    return request('/performance/secondSetting/getAutoSecondData', {
        method: 'GET',
        params: { computeDate, unitCode }
    })

}

//导出excel模板
export const downloadTemplateReq = (computeDate: string, unitCode: string) => {

    let path = '/gateway/performance/secondSetting/exportSecondData';
    const userData = localStorage.getItem('userData');
    const { token = '' } = JSON.parse(userData as any);

    axios({
        method: 'get',
        url: path,
        responseType: 'blob',
        headers: { token },
        params: { computeDate, unitCode }
    })
        .then(function (response) {
            //console.log({ 'chunk': response });
            const filename = decodeURI(response.headers["content-disposition"]);
            const objectUrl = URL.createObjectURL(
                new Blob([response.data], {
                    type: 'application/vnd.ms-excel',
                })
            )
            const link = document.createElement('a')
            // 设置导出的文件名称
            link.download = `${filename}` + '.xls'
            link.style.display = 'none'
            link.href = objectUrl
            link.click()
            document.body.appendChild(link)

        });



}


//导入数据

export const importExcelData = (data: any) => {
    return request('/performance/secondSetting/importSecondData', {
        method: 'POST',
        data: data
    })
}

//根据项目code获取评级列表

export const getPingjiListByCode = (secondItemCode:string) => {
    return request<any[]>('/performance/secondSetting/getItemLevel', {
        method: 'GET',
        params: { secondItemCode }
    });
}

//保存工作量
export const saveWorkLang = (data:{computeDate:string,unitCode:string,empNo:string,code:string,value:number}) => {
    return request('/performance/secondSetting/saveEmpWorkload', {
        method: 'POST',
        params:{...data}
    });
}



