/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2022-12-21 11:13:51
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2024-03-29 15:19:57
 * @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;
//     child: getTreeDataRespType[]
// }

// export const getTreeData = (computeDate: string) => {

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



//获取固定工资表格数据

export type SalaryInfoTableDataRequestParamsType = {
    computeDate: string; //核算年月
    deptName?: string;
}

export type SalaryInfoTableDataItemType = {
    unitType: number,
    unitCode: number,
    unitName: string,
    deptCode: string,
    deptName: string,
    empNo: string,
    empName: string,
    salaryType: string,
    salaryTypeName: string,
    salary: number
}

export type SalaryInfoTableDataType = {
    current: number,
    list: SalaryInfoTableDataItemType[],
    pageSize: number,
    totalCount: number,
    totalPage: number,

}

export const getSalaryInfoTableData = (params: SalaryInfoTableDataRequestParamsType) => {

    return request<SalaryInfoTableDataType>('/performance/kpi/getSalary', {
        method: 'GET',
        params: params
    })

}

//获取单元成本数据

export type UnitCostTableDataRequestParamsType = {
    unitCode:string,
    itemName?:string
}



export const getUnitCostTableData = (params: UnitCostTableDataRequestParamsType) => {

    return request('/performance/kpi/getUnitCostList', {
        method: 'GET',
        params: params
    })

}

//编辑单元成本
export const editUnitCostTableData = (data:{id:number,amount:number}) => {

    return request('/performance/kpi/editUnitCost', {
        method: 'POST',
        params:data
    })

}

//获取按钮生成单元成本数据
export const generateUnitCostTableData = (compute_date:string,unit_code:string) => {

    return request('/performance/kpi/generateUnitCost', {
        method: 'POST',
        data:{
            parameter:{
                compute_date,
                unit_code
            }
        }
    })

}



//获取非考核项目表格数据


export type NoCheckTableDataRequestParamsType = {
    computeDate: string; //核算年月
    deptName?: string;
}

export type NoCheckTableDataItemType = {
    unitType: string,
    unitTypeName: string,
    unitCode: string,
    unitName: string,
    deptCode: number,
    deptName: string,
    assessmentCode: string,
    assessmentName: string,
    distributionType: number,
    targetValue: string,
    targetValueName: string,
    describe: string
}

export type NoCheckTableDataRespType = {
    current: number,
    list: NoCheckTableDataItemType[],
    pageSize: number,
    totalCount: number,
    totalPage: number,

}

export const getNoCheckTableData = (params: NoCheckTableDataRequestParamsType) => {

    return request<NoCheckTableDataRespType>('/performance/kpi/getNonAssessmentList', {
        method: 'GET',
        params: params
    })

}

// //获取核算单元

// export type CheckUnitTreeDataRespType = {
//     code:string,
//     name:string,
//     child:CheckUnitTreeDataRespType[]
// }

// export const getCheckUnitTreeData = (computeDate:string) => {

//     return request<CheckUnitTreeDataRespType[]>('/performance/kpi/getAssessmentList', {
//         method: 'GET',
//         params:{computeDate}
//     })

// }


//生成查核项目数据

export type GenerateCheckProjectTableData = {
    computeDate: string,
    unitCode?: string
}

export const generateCheckProjectTableData = (data: GenerateCheckProjectTableData) => {

    return request('/performance/kpi/generateAssessmentData', {
        method: 'POST',
        params: data
    })

}


//获取考核项目

export type CheckProjectTableDataReqType = {
    computeDate: string,
    unitCode: number,
    itemType?: string,
    itemName?: string
}


export const getCheckProjectTableData = (params: CheckProjectTableDataReqType) => {

    return request('/performance/kpi/getAssessmentList', {
        method: 'GET',
        params: params
    })

}

//获取管理指标表头及表数据

export type ManaIndexTableDataParamsType = {
    computeDate: string,
    unitName?: string,
    groupId?: string,
}

export const getManaIndexTableData = (params: ManaIndexTableDataParamsType) => {

    return request('/performance/kpi/manager/list', {
        method: 'GET',
        params: params
    })

}

export type delTableDataRequestParam = {
    computeDate: string,
    id: string,
    index: number
}

export const delTableDataRequest = (params: delTableDataRequestParam) => {
    const { computeDate, id, index } = params;
    if (index == 1) {
        return request('/performance/kpi/deleteSalary', {
            method: 'POST',
            params: { computeDate, id }
        })
    }
    if (index == 2) {
        return request('/performance/kpi/deleteNonAssessment', {
            method: 'POST',
            params: { computeDate, id }
        })
    }

    if (index == 3) {
        return request('/performance/kpi/deleteAssessmentData', {
            method: 'POST',
            params: { computeDate, id }
        })
    }


}

//编辑金额

export type editTableSalaryRequestBodyType = {
    computeDate: string,
    unitCode: string,
    deptCode: string,
    salaryType: string,
    salary: number,
    userId: string,
    id: number
}

export const editTableSalaryRequest = (data: editTableSalaryRequestBodyType) => {

    return request('/performance/kpi/editSalary', {
        method: 'POST',
        data: { ...data }
    })

}


//操作按钮获取数据

export const btnActGetData = (params: CheckProjectTableDataReqType) => {

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

}

//获取科室

export const getDepLists = (unitCode:string) => {

    return request('/performance/unit/getUnitDeptMap?pageSize=500&current=1', {
        method: 'GET',
        params:{unitCode:unitCode}
    })

}

//获取核算单元

export const getHesuanUnits = (computeDate: string) => {

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

}

//获取项目

export const getProjects = () => {

    return request('/performance/kpi/getNonAssessmentDictionary', {
        method: 'GET',
    })

}

//编辑考核项目

export type EditCheckProjectBodyType = {
    itemCode: string,
    itemName: string,
    itemType: string,
    orderPointValue: number,
    value: number,
    executePointValue: number,
    id: string,
    hospId: string,
    computeDate: string,
    unitCode: string
}
export const editCheckProject = (data: EditCheckProjectBodyType) => {

    return request('/performance/kpi/editAssessmentData', {
        method: 'POST',
        data
    })

}


//获取人员

export const getEmps = (unitCode: string) => {

    return request('/performance/kpi/getNonAssessmentUnitEmp', {
        method: 'GET',
        params: { unitCode }
    })

}

//编辑表格数据

export type editTableDataType = {
    id: number,
    computeDate: string,
    unitCode: string,
    deptCode: string,
    nonAssessmentCode: string,
    targetValue: string,
    value: string,
    description: string
}

export const editTableData = (data: editTableDataType) => {
    console.log({ data });
    return request('/performance/kpi/editNonAssessment', {
        method: 'POST',
        data: { ...data }
    })

}

//新增表格数据

export type addTableDataType = {

    computeDate: string,
    unitCode: string,
    deptCode: string,
    nonAssessmentCode: string,
    targetValue: string,
    value: string,
    description: string
}

export const addTableData = (data: addTableDataType) => {
    console.log({ data });
    return request('/performance/kpi/addNonAssessment', {
        method: 'POST',
        data: { ...data }
    })

}



//获取管理指标分组

export const getManaIndexGroup = () => {
    return request('/performance/kpi/getManagerGroup', {
        method: 'GET',
    })

}

//管理指标实际值编辑保存

export const editManaIndexTableData = (data: any) => {
    return request('/performance/kpi/editManager', {
        method: 'POST',
        data: { ...data }
    })

}


//获取收入表格数据

export type GetIncomeDataParamType = {
    computeDate: string,
    itemName: string,

}

export const getIncomeData = (params: GetIncomeDataParamType) => {
    return request('/performance/kpi/income/list', {
        method: 'GET',
        params
    })

}


//获取成本表格数据

export type GetCostDataParamType = {
    computeDate: string,
    itemName: string,

}

export const getCostData = (params: GetCostDataParamType) => {
    return request('/performance/kpi/cost/list', {
        method: 'GET',
        params
    })

}

//获取绩效数据页面审核状态

export const getPageCheckStatus = (computeDate: string) => {
    return request('/performance/kpi/getStatus', {
        method: 'GET',
        params: { computeDate }
    })

}

//获取考核项目计算状态

export const getCheckItemCalcStatus = (computeDate: string,code:string) => {
    return request('/performance/kpi/getComputeStatus', {
        method: 'GET',
        params: { computeDate,code }
    })

}

//审核绩效数据
export const checkMonthlyReq = (computeDate: string, auditType: string) => {
    return request('/performance/kpi/audit', {
        method: 'POST',
        params: { computeDate, auditType }
    })

}

//重算
export const reCalculateReq = (groupId:string,computeDate:string) => {
    return request('/performance/kpi/computeManager', {
        method: 'POST',
        params:{groupId,computeDate}
    })

}


//月度绩效相关导入



export const importMonthlyperformanceRelaFiles = (code: string, data: any) => {

    /**
     * index : tab对应的表格顺序号
     */

    if (code == 'kpi_salary') {
        return request('/performance/kpi/importSalary', {
            method: 'POST',
            data
        })
    }
    if (code == 'kpi_non_assessment') {
        return request('/performance/kpi/importNonAssessment', {
            method: 'POST',
            data
        })
    }
    if (code == 'kpi_manage_indicator') {
        return request('/performance/kpi/importManager', {
            method: 'POST',
            data
        })
    }
    if (code == 'kpi_income') {
        return request('/performance/kpi/importIncome', {
            method: 'POST',
            data
        })
    }
    if (code == 'kpi_cost') {
        return request('/performance/kpi/importCost', {
            method: 'POST',
            data
        })
    }
    if (code == 'kpi_unit_cost') {
        return request('/performance/kpi/importUnitCost', {
            method: 'POST',
            data
        })
    }


}

//下载模板

export const downloadTemplateReq = (code: string,id?:number|string) => {


    let path = '';

    if (code == 'kpi_salary') {
        path = '/gateway/performance/kpi/exportSalary'
    }
    if (code == 'kpi_non_assessment') {
        path = '/gateway/performance/kpi/exportNonAssessment'
    }
    if(code == 'kpi_manage_indicator'){
        path = `/gateway/performance/kpi/exportManager?groupId=${id}`
    }
    if(code == 'kpi_income'){
        path = `/gateway/performance/kpi/exportIncome`
    }
    if(code == 'kpi_cost'){
        path = `/gateway/performance/kpi/exportCost`
    }
    if(code == 'kpi_unit_cost'){
        path = `/gateway/performance/kpi/exportUnitCost?unitCode=${id}`
    }

    const userData = localStorage.getItem('userData');
    const { token = '' } = JSON.parse(userData as any);

    axios({
        method: 'get',
        url: path,
        responseType: 'blob',
        headers: { token },
    })
        .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 getManaIndicatorJiangchengCoefficient = () => {
    return request('/performance/parameter/getList?current=1&pageSize=500', {
        method: 'GET',
    })

}



