

import { request } from 'umi';



// 获取条文表格数据
export const getTreeFileTableData = (
  query: { id: string | number; keyword?: string | number,pageSize?: number},
  mode?: boolean,
) => {
  if (!mode) {
    // 条文
    return request('/api/pfm/reviewArticle/list', {
      method: 'GET',
      params: { ...query },
    });
  } if(mode){
    // 台账
    return request('/api/pfm/recordUpload/list', {
      method: 'GET',
      params: { ...query },
    });
  }
};

// 获取单位列表

export type GetDepartmentListType = {
  current: number;
  list: {
    hiId: number;
    id: number;
    name: string;
    sysEmployeeVOList: {
      code: string;
      hiId: number;
      id: number;
      name: string;
    }[];
  }[];
  pageSize: number;
  totalCount: number;
  totalPage: number;
};

export const getDepartmentList = async (query?: {
  responsibilityDepartmentId?: number;
  responsibilityUserId?: number;
}) => {
  return request<Promise<GetDepartmentListType>>('/api/pfm/sysdepartment/getSysDepartmentList', {
    method: 'GET',
    params: { ...query },
  });
};

// 条文设置

export const settingArticle = async (data: API.settingArticlePostDataType) => {
  return request('/api/pfm/reviewArticle/setArticle', {
    method: 'POST',
    data: { ...data },
  });
};

// 条文批量设置

export const batchSettingArticle = async (data: API.batchSettingArticleType) => {
  return request('/api/pfm/reviewArticle/setTargetEvaluation', {
    method: 'POST',
    data: { ...data },
  });
};

// 获取自评记录

export const getSelfEvaluation = async (ruleId: string | number) => {
  return request('/api/pfm/pfmarticlehistory/getSelfEvaluation', {
    method: 'GET',
    params: { ruleId },
  });
};

// 获取制度下的子节点

export const getRuleChildrens = async (id: number) => {
  return request('/api/pfm/publicResource/getPublicCateChildren', {
    method: 'GET',
    params: { id },
  });
};

// 上传台账

export const uploadFilePost = async (uploadData:FormData) => {
  return request('/api/pfmdatadirectoryfile/addDataDirectoryFile', {
    method: 'POST',
    data: uploadData,
  });
};

//根据资料目录Id获取对应的台账记录
export type ledgerRecordList = {
  id:number;
  fileName:string;
  fileUrl:string;
  createTime:string;
  directoryId:number;
}
export const getLedgerRecords = async (params:{
  id:number;
}) => {
  return request<{list:ledgerRecordList[]}>('/api/pfmdatadirectoryfile/getDataDirectoryFile', {
    method: 'GET',
    params:{...params,current:1,
      pageSize:50}
  });
};


//删除资料目录对应的台账

export const delLedgerRecords = async (id:number) => {
  return request('/api/pfmdatadirectoryfile/deleteDataDirectoryFile', {
    method: 'POST',
    params:{fileId:id},
  });
};



// 自评

export const selfEvolutionCommit = async (data: API.SelfEvolutionCommitType) => {
  return request('/api/pfm/recordUpload/setSelfEvaluationResult', {
    method: 'POST',
    data,
  });
};


// 获取可选台账类型
export const getUploadLedgerSelectableType = async () => {
  return request('/api/pfm/sysgeneralconfig/getAccountConfigByType', {
    method: 'GET',
  });
};

// 获取当前医院目标和自评结果
export const getCurrentHospSelfScore = async () => {
  return request('/api/pfm/reviewArticle/getTargetAndSelf', {
    method: 'GET',
  });
};

// 根据执行情况等级获取对应的表格数据
export const getCurrentLevelTable = async (params: {
    level: string,// 等级
    numStr: string, // 四码
    version: string,
    current?: number,// 当前页码
    pageSize?: number,
}) => {
    return request('/api/pfm/pfmdatadirectory/getPfmDataDirectoryByLevel', {
      method: 'GET',
      params
    });
};

// 台账上传时获取四码对应的资料目录表格数据

export const getTaizhangDirectoryTable = async (params: {
    numStr: string, // 四码
    version: string,
    current?: number,// 当前页码
    pageSize?: number,
}) => {
    return request<{
        totalCount: number,
        pageSize: number,
        totalPage: number,
        current: number,
        list: API.TaizhangDirectoryTableItem[]
    }>('/api/pfm/pfmdatadirectory/getPfmDataDirectory', {
      method: 'GET',
      params,
    });
};




// 根据指定level值获取对应的执行情况说明，用于台账上传界面

export const getTaizhangImplementation = async (params: {
   numStr: string, // 四码
   version: string,
   level: string,// 等级
}) => {

   return request<API.TaizhangImplementationItem[]>('/api/pfmimplementation/getImplementationByLevel', {
     method: 'GET',
     params,
   });
};

// 台账界面提交执行情况说明
export const commitTaizhangImplementation = async (params: {
    hospId: string, // 医院标识
    id: number,
    numStr: string,
    selfEvaluation: string,
    version: string,
    implementationDtoList: API.ImplementationDtoListItem[]
}) => {
   return request('/api/pfm/recordUpload/addAccountData', {
     method: 'POST',
     data:params,
     responseSpecifyFeedback:{
        isShow:true,
        successMessage:'执行情况说明保存成功'
     }
   });
};


// 台账界面提交资料目录编辑/新增/删除数据
export const commitTaizhangDataDirectoryTableList = async (params: API.TaizhangDataDirectoryCommitListItem[]) => {
   return request('/api/pfm/pfmdatadirectory/addPfmDataDirectory', {
     method: 'POST',
     data:params,
     responseSpecifyFeedback:{
      isShow:true,
      successMessage:'资料目录保存成功'
   }
   });
};




