/*
 * @Author: your name
 * @Date: 2021-09-07 09:29:27
 * @LastEditTime: 2021-12-30 17:19:47
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /MedicalWisdomCheckSys/src/pages/GradeHospitalAccreditation/accreditationDetail/service.ts
 */

import { request } from 'umi';



interface MineTreeData {
    list: {
        id: number,
        numStr: string,
        name: string,
        parentId: number,
        allParentIds: number,
        ruleLevel: number,
        ruleLevelNum: string,
        version: string,
        hospId: string,
    }[]
}


// 获取树结构
export const getTreeList  = async (isShowMineOnly: boolean,keyword?: string|number)=>{

    if(isShowMineOnly){
        const resp = await request<MineTreeData>('/api/pfm/reviewArticle/getAllByMy', {
            method: 'GET',
            params: {keyword},
          });
          const {list=[]} = resp;
          const data =  list.map(item=>({
            code:item.numStr,
            id:item.id,
            isLeaf:true,
            levelNum:4,
            title:item.name,
            version:item.version
          }));

          return {list:data}
        
    }

    return request('/api/pfm/reviewRules/getAllTree', {
        method: 'GET',
        params:{keyword}
    });

}

// 新增细则


export const addDetailRule = (data: API.AddDetailRule)=>{

    return request('/api/pfm/reviewRules/add', {
        method: 'POST',
        data
    });

}

// 删除细则

export const delDetailRule = (id: string|number)=>{

    return request('/api/pfm/reviewRules/delete', {
        method: 'POST',
        params:{id}
    });

}

// 编辑细则

export const editDetailRule = (data: API.EditDetailRule)=>{

    return request('/api/pfm/reviewRules/edit', {
        method: 'POST',
        data
    });

}


// 查询叶子对应的详细细则

export const getDetailRuleList = (id: string|number)=>{

    return request('/api/pfm/reviewRules/getDetails', {
        method: 'GET',
        params:{id}
    });

}

// 查询叶子对应的资料目录表格数据
export const getMaterialList = (params: API.GetMaterialListApiParams)=>{

    return request<Promise<API.GetMaterialListApiResult>>('/api/pfm/pfmdatadirectory/getPfmDataDirectory', {
        method: 'GET',
        params
    });

}

// 查询叶子对应的所有目录数据
export const getMaterialDirList = (params: {
    numStr: string,  // 四码
    version: string // 版本
})=>{

    return request<string[]>('/api/pfm/pfmdatadirectory/getDirectoryList', {
        method: 'GET',
        params
    });

}

// 查询叶子对应的资料目录所有档次
export const getMaterialListGrades = (params: {numStr: string,version: string})=>{
    return request<Promise<{grade: string,detail: string}[]>>('/api/pfm/pfmdatadirectory/getGradeList', {
        method: 'GET',
        params
    });
}

// 添加叶子对应的资料目录
export const addMaterialDirList = (data: {
    numStr: string, // 四码
    version: string,
    directory: string,
    grade: string,
    note?: string,
    profileName: string,
    ruleId: string, // 四码Id
})=>{
    return request<Promise<{data: any}>>('/api/pfm/pfmdatadirectory/addPfmDataDirectory', {
        method: 'POST',
        data
    });
}

// 删除叶子对应的资料目录
export const delMaterialDirList = (data: number[])=>{
    return request<Promise<{data: any}>>('/api/pfm/pfmdatadirectory/deletePfmDataDirectoryById', {
        method: 'POST',
        data
    });
}

// 修改叶子对应的资料目录
export const editMaterialDirList = (data: {
    directory: string,
    grade: string,
    id: number,
    note: string,
    profileName: string
})=>{
    return request<Promise<{data: any}>>('/api/pfm/pfmdatadirectory/updatePfmDataDirectory', {
        method: 'POST',
        data
    });
}



