/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2023-05-15 13:20:27
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2023-09-22 13:39:03
 * @FilePath: /BudgetManaSystem/src/pages/setting/projectSetting/checkUnitProjectSet/service.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2022-12-21 11:13:51
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2023-06-28 18:19:21
 * @FilePath: /BudgetManaSystem/src/pages/budgetMana/monthlyInfoCheck/service.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */




import { getRedirReportData } from '@/pages/reportCheck/report/service';
import { request } from '@@/plugin-request';
import { defaultActionRender } from '@ant-design/pro-utils/es/useEditableArray';
import { cond, invertBy } from 'lodash';
import { editReportTbaleData } from '../../reportSet/reportSetting/service';




//获取树结构单元数据

export type getTreeDataRespType = {
    code: number;
    name: string;
    child: getTreeDataRespType[]
}

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

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

//获取所有核算单元用于复制选择

export const getAllCheckUnit = () => {

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


//获取所有查核项目用于添加
export const getAllCheckUnitProjectData = () => {
    return request('/performance/item/getAllItemList', {
        method: 'GET',
    })
}




//获取收费项目表格数据

export type getBillingItemTableDataParamsType = {
    unitCode: string,
    name?: string,
    pageSize?: number,
    current?: number
}

export type BillingItemType = {
    "id": number, //主键
    "hospId": number, //医院id
    "itemPointCode": string, //收费项目代码
    "itemName": string, //收费项目名称
    "orderPointValue": number, //点值
    "executePointValue": number, //执行点值
    "unitCode": string, //核算单元代码
    "coreFlag": number, //是否synt
    "coreFlagName": string, //是否核心项目名称
    "itemType": string //是否核心项目 0 否 1 是 2不计
}

export type BillingItemTableDataType = {
    current: number,
    list: BillingItemType[],
    pageSize: number,
    totalCount: number,
    totalPage: number,
}

export const getBillingItemTableData = (params: getBillingItemTableDataParamsType) => {

    return request<BillingItemTableDataType>('/performance/item/getUnitItemList', {
        method: 'GET',
        params: { ...params }
    })

}


//收费项目保存添加
export const addBillingItemData = (data: {
    unitCode: string,
    item: any[]
}) => {

    return request('/performance/item/addUnitItemList', {
        method: 'POST',
        data: { ...data }
    })

}

//收费项目编辑保存
export const editBillingItemData = (data: {
    "id": number, //主键
    "unitCode": string, //核算单元代码
    "orderPointValue": string, //点值
    "coreFlag": number //是否 核心 1是0否
}) => {

    return request('/performance/item/editUnitItemList', {
        method: 'POST',
        data: { ...data }
    })

}



//获取指标表格数据

export type getIndicTableDataParamsType = {
    current?: number,
    pageSize?: number,
    unitCode: string,
    name?: string,
}

export type IndicTableItemDataType = {
    "id": number, //主键
    "hospId": number, //医院id
    "indicatorCode": string, //指标代码
    "indicatorName": string, //指标名称
    "orderPointValue": number, //点值
    "executePointValue": number, //执行点值
    "unitCode": string, //核算单元代码
    "indicatorType": number, //类型
    "indicatorTypeName": string, //类型名称
    "indicatorDefinition": string //定义
}



export const getIndicTableData = (params: getIndicTableDataParamsType) => {

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

}

//指标项目添加
export const addIndicItemData = (data: {
    unitCode: string,
    indicatorValues: any[]
}) => {

    return request('/performance/item/addUnitIndicatorList', {
        method: 'POST',
        data: { ...data }
    })

}


//指标项目编辑保存

export const editIndicItemData = (data: {
    "id":number, //主键
    "unitCode":string, //核算单元代码
    "indicatorCode":string, //指标代码
    "indicatorName":string, //指标名称
    "orderPointValue":string, //点值
    "executePointValue": number //执行点值
}) => {

    return request('/performance/item/editUnitIndicatorList', {
        method: 'POST',
        data: { ...data }
    })

}



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

export type getNonCheckTableDataParamsType = {
    current?: number,
    pageSize?: number,
    unitCode: string,
    name?: string,
}

export type NonCheckTableItemDataType = {
    "id": number, //主键
    "hospId": number, //医院id
    "indicatorCode": string, //指标代码
    "indicatorName": string, //指标名称
    "orderPointValue": number, //点值
    "executePointValue": number, //执行点值
    "unitCode": string, //核算单元代码
    "indicatorType": number, //类型
    "indicatorTypeName": string, //类型名称
    "indicatorDefinition": string //定义
}



export const getNonCheckTableData = (params: getNonCheckTableDataParamsType) => {

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

}


//非考核项目添加
export const addNonCheckItemData = (data: {
    unitCode: string,
    assessments: any[]
}) => {

    return request('/performance/item/addUnitNonAssessmentList', {
        method: 'POST',
        data: { ...data }
    })

}




//删除项目
export const delRequest = (params:any,tabKey:string) => {

    if(tabKey == '1'){
        return request('/performance/item/deleteUnitItemList', {
            method: 'POST',
            params: params
        })
    }
    if(tabKey == '2'){
        return request('/performance/item/deleteUnitIndicatorList', {
            method: 'POST',
            params: params
        })
    }
    if(tabKey == '3'){
        return request('/performance/item/deleteUnitNonAssessmentList', {
            method: 'POST',
            params: params
        })
    }
    if(tabKey == '4'){
        return request('/performance/item/deleteUnitCostList', {
            method: 'POST',
            params: params
        })
    }
}




//保存项目复制

export const saveCopyRequest = (data: any,tabKey:string) => {

    if(tabKey == '1'){
        return request('/performance/item/copyUnitItemList', {
            method: 'POST',
            data: data
        })
    }
    if(tabKey == '2'){
        return request('/performance/item/copyUnitIndicatorList', {
            method: 'POST',
            data: data
        })
    }
    if(tabKey == '3'){
        return request('/performance/item/copyUnitNonAssessmentList', {
            method: 'POST',
            data: data
        })
    }
    if(tabKey == '4'){
        return request('/performance/item/copyUnitCostList', {
            method: 'POST',
            data: data
        })
    }

}


//单个项目复制
export const copySimpleRequest = async (data: any,tabKey:string) => {
    if(tabKey == '1'){
        return request('/performance/item/copyUnitItem', {
            method: 'POST',
            data: data
        })
    }
    if(tabKey == '2'){
        return request('/performance/item/copyUnitIndicator', {
            method: 'POST',
            data: data
        })
    }
}

//获取成本项目表格数据

export type getCostItemsTableDataParamsType = {
    current?: number,
    pageSize?: number,
    unitCode: string,
    name?: string,
}

export type CostItemsTableItemDataType = {

}



export const getCostItemsTableData = (params: getCostItemsTableDataParamsType) => {

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

}


//成本项目添加
export const addCostItemData = (data: {
    unitCode: string,
    itemList: any[]
}) => {

    return request('/performance/item/addUnitCostList', {
        method: 'POST',
        data: { ...data }
    })

}

//成本项目编辑
export const editCostItemData = (data: {
    id:number,
    ctrlFlag:string
}) => {

    return request('/performance/item/editUnitCostList', {
        method: 'POST',
        params: { ...data }
    })

}
