/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2023-03-03 16:31:27
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2024-12-11 10:17:02
 * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/pubDicTypeMana/service.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */



import { request } from 'umi';

//获取table列表数据

export const getTableDataReq = (params?:any) => {
  return request<any>('/medical/qualificationManage/listByDoctor', {
    method: 'GET',
    params:{...params}
  });
};

//获取科室列表

export const getDepartmentDataReq = (params?:any) => {
  return request<any>('/medical/qualificationManage/listAllDepartment', {
    method: 'GET',
    params:{...params}
  });
};





//编辑表格数据

export type EditTableDataType = {
 
}

export const editData = (data:EditTableDataType) => {
  return request('/medical/qualificationManage/adjust', {
    method: 'POST',
    data
  });
};
//重新授权
export const reAuthData = (data:EditTableDataType) => {
  return request('/medical/qualificationManage/reAuthorize', {
    method: 'POST',
    data
  });
};


// 根据医生获取授权申请列表（抽屉-授权详情表格）
export const getApplyListByDoctorReq = (params?: any) => {
  // 说明：后端接口期望入参包含 userId
  return request<any>('/medical/qualificationManage/listQualificationApplyByDoctor', {
    method: 'GET',
    params: { ...params },
  });
};

// 获取医生基础信息与附件（抽屉-资质信息附件）
export const getDoctorInfoReq = (params?: any) => {
  // 说明：后端接口期望入参包含 userId
  return request<any>('/medical/qualificationManage/getDoctorInfo', {
    method: 'GET',
    params: { ...params },
  });
};

// ---- 字典获取（一次拉全量 + 内存缓存） ----
let __ALL_DICT_CACHE__: any[] | null = null;
let __ALL_DICT_PROMISE__: Promise<any[] | null> | null = null;

export const getAllDictData = async (): Promise<any[]> => {
  if (__ALL_DICT_CACHE__) return __ALL_DICT_CACHE__;
  if (__ALL_DICT_PROMISE__) return (await __ALL_DICT_PROMISE__) || [];
  __ALL_DICT_PROMISE__ = request<any>('/centerSys/sysdictdata/getDictData', { method: 'GET' })
    .then((resp) => {
      const list = Array.isArray(resp?.data) ? resp.data : (Array.isArray(resp) ? resp : []);
      __ALL_DICT_CACHE__ = list || [];
      __ALL_DICT_PROMISE__ = null;
      return __ALL_DICT_CACHE__;
    })
    .catch((e) => {
      __ALL_DICT_PROMISE__ = null;
      throw e;
    });

  return (await __ALL_DICT_PROMISE__) || [];
};

// 基于全量缓存筛选具体字典
export const getDictDataByType = async (dictType: string) => {
  const list = await getAllDictData();
  const target = (list || []).find((item: any) => item.code === dictType);
  return target?.dataVoList || [];
};

// 编辑医生资质基础信息
// 字段：id, qualificationCertificateNo, practiceCate, practiceCertificateNo, practiceSubject, doctorLevel
export const updateDoctorQualInfo = (data: any) => {
  return request<any>('/centerSys/user/editUser', {
    method: 'POST',
    data,
  });
};















