import request from '@/utils/request.js';
import dayjs from 'dayjs';


// 添加医共体
export function addDoctorBody(data) {
    return request({
        url: '/basis/medicalorganizationMgr/Add',
        method: 'post',
        data
    })
};

// 获取医共体列表
export function getDoctorBody(data) {
    return request({
        url: '/basis/medicalorganizationMgr/listPain?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
};

// 修改医共体
export function editDoctorBody(data) {
    return request({
        url: '/basis/medicalorganizationMgr/update',
        method: 'post',
        data
    })
};

// 删除医共体
export function deleteDoctorBody(data) {
    return request({
        url: '/basis/medicalorganizationMgr/BatchDelete?ids=' + data.ids,
        method: 'post',
        data
    })
};

// 获取医共体详细信息
export function getDoctorBDetail(data) {
    return request({
        url: `/basis/medicalorganizationMgr/${data}`,
        method: 'get'
    })
};

// 获取 医共体选择器
export function getDoctorBodySelect(data) {
    return request({
        url: '/basis/medicalorganizationMgr/customerQuery',
        method: 'post',
        data
    })
};

// 新增医疗机构
export function addMedinsituions(data) {
    return request({
        url: '/basis/medicalinstitutionsMgr/Add',
        method: 'post',
        data
    })
};

// 获取当前医疗机构选择器
export function getMedSelect(data) {
    return request({
        url: '/basis/medicalinstitutionsMgr/customerQuery?organizationId=' + data.organizationId,
        method: 'post',
        data
    })
};

// 获取医疗机构列表
export function getMedlist(data) {
    return request({
        url: '/basis/medicalinstitutionsMgr/listPain?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
};

// 获取医疗机构详细信息
export function getMedDetail(data) {
    return request({
        url: `/basis/medicalinstitutionsMgr/${data}`,
        method: 'get'
    })
};

// 编辑医疗机构信息
export function editMedData(data) {
    return request({
        url: '/basis/medicalinstitutionsMgr/update',
        method: 'post',
        data
    })
};

// 医疗机构删除
export function deleteMed(data) {
    return request({
        url: '/basis/medicalinstitutionsMgr/BatchDelete?ids=' + data.ids,
        method: 'post',
        data
    })
};

// 获取科室选择器 列表
export function getDepartSelect(data) {
    return request({
        url: '/basis/hospitaldepartmentsMgr/customerQuery?institutionId=' + data.institutionId,
        method: 'post',
        data
    })
};

// 获取医生选择器 列表
export function getDoctorSelect(data) {
    return request({
        url: '/portal/userMgr/listPain',
        method: 'post',
        data,
        params: {page: 1, limit: 999}
    })
}

// 获取科室列表
export function getDepartList(data) {
    return request({
        url: '/basis/hospitaldepartmentsMgr/listPain?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
};

// 添加科室 
export function addDepart(data) {
    return request({
        url: '/basis/hospitaldepartmentsMgr/Add',
        method: 'post',
        data
    })
};

// 获取科室详情数据
export function getDepartDetail(data) {
    return request({
        url: `/basis/hospitaldepartmentsMgr/${data}`,
        method: 'get'
    })
};

// 科室数据修改
export function editDepart(data) {
    return request({
        url: '/basis/hospitaldepartmentsMgr/update',
        method: 'post',
        data
    })
};

// 删除科室数据
export function deleteDepart(data) {
    return request({
        url: '/basis/hospitaldepartmentsMgr/BatchDelete?ids=' + data.ids,
        method: 'post'
    })
};


// 获取角色列表
export function getRoleList(data) {
    return request({
        url: '/admin/right_RoleMgr/listPain?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
};

// 添加 角色数据
export function addRoleData(data) {
    return request({
        url: '/admin/right_RoleMgr/Add',
        method: 'post',
        data
    })
};

// 获取角色详情信息
export function getRoleDetail(data) {
    return request({
        url: `/admin/right_RoleMgr/${data}`,
        method: 'get'
    })
};

// 修改角色信息

export function editRoleData(data) {
    return request({
        url: '/admin/right_RoleMgr/update',
        method: 'post',
        data
    })
};

// 删除角色信息
export function deleteRoleData(data) {
    return request({
        url: "/admin/right_RoleMgr/BatchDelete?ids=" + data.ids,
        method: 'post'
    })
};


// 获取角色管理权限菜单
export function getPermissionsMenu(data) {
    return request({
        url: '/admin/right_RoleMgr/GetRoleRight?RoleID=' + data.RoleID,
        method: 'post',
        data
    })
};


// 获取菜单权限
export function getMenuPermiss(data) {
    return request({
        url: '/Admin/getMenu',
        method: 'post',
        data
    })
};

// 为角色设置权限
export function setPermToRole(data) {
    return request({
        url: '/admin/right_RoleMgr/SetRoleRight?roleID=' + data.roleID,
        method: 'post',
        data
    })
};

// 获取角色选择器信息
export function getRoleSelect(data) {
    return request({
        url: '/admin/right_RoleMgr/optionselect',
        method: 'get',
        data
    })
};

// 获取用户列表
export function getUserList(data) {
    return request({
        url: '/portal/userMgr/listPain?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
};

// 新增用户信息
export function addUserMsg(data) {
    return request({
        url: '/portal/userMgr/Add',
        data,
        method: 'post'
    })
};

// 获取用户详细信息
export function getUserDetail(data, pid) {
    return request({
        url: `/portal/userMgr/${data}`,
        method: 'get',
        params: { pid }
    })
};

// 修改用户信息
export function editUserMsg(data) {
    return request({
        url: '/portal/userMgr/update',
        method: 'post',
        data
    })
};

// 删除用户管理信息
export function deleteUserMsg(data) {
    return request({
        url: '/portal/userMgr/BatchDelete?ids=' + data.ids,
        method: 'post',
        data
    })
};

// 用户管理重置密码
export function resetPasInUser(data) {
    return request({
        url: '/portal/userMgr/UpdatePassWord',
        method: 'post',
        data
    })
};

//获取 公共代码 信息
export function getCodeMsg(data) {
    return request({
        url: '/basis/parameterconfigMgr/getPlatformCode',
        method: 'post',
        data
    })
};

// 提交 公共代码 信息
export function addCodeMsg(data) {
    return request({
        url: '/basis/parameterconfigMgr/Add',
        method: 'post',
        data
    })
};

// 获取医共体 参数信息
export function getDoctorBodyPar(params) {
    return request({
        url: '/portal/configMgr/ConfigByOrganizationid',
        method: 'get',
        params
    })
};

// 保存医共体参数信息
export function saveDBParams(data) {
    return request({
        url: '/portal/configMgr/Add',
        method: 'post',
        data
    })
};

// 修改密码
export function changePas(data) {
    return request({
        url: '/portal/userMgr/setPassWord',
        method: 'post',
        data
    })
};


// 获取医共体权限按钮
export function getDoctorBR(data) {
    return request({
        url: '/basis/medicalorganizationMgr/GetButtonRight',
        method: 'post',
        data
    })
};

// 获取医疗机构权限按钮 
export function getMedBR(data) {
    return request({
        url: '/basis/medicalinstitutionsMgr/GetButtonRight',
        method: 'post',
        data
    })
};

//获取科室权限按钮
export function getDepartBR(data) {
    return request({
        url: '/basis/hospitaldepartmentsMgr/GetButtonRight',
        method: 'post',
        data
    })
};

// 获取用户管理权限按钮 
export function getUserBR(data) {
    return request({
        url: '/portal/userMgr/GetButtonRight',
        method: 'post',
        data
    })
};

// 获取角色管理权限
export function getRoleBR(data) {
    return request({
        url: '/admin/right_RoleMgr/GetButtonRight',
        method: 'post',
        data
    })
};

// 身份证号焦点校验
export function checkIdCard(data) {
    return request({
        url: '/basis/patientMgr/idCardCheck?card=' + data,
        method: 'post'
    })
};


// 跟据建明和医共体 查询数据
export function getDataByKey(data) {
    return request({
        url: '/portal/configMgr/configKey',
        method: 'get',
        params: data
    }).then(res => {
       switch (data.key) {
           case 'defaultHomePage': return res.ResultInfo || '/index/todaypatients';
           case 'transitionPr': return {
               enabled: !res.ResultInfo || res.ResultInfo === '0',
           }
           case 'showPrintHTML': return {
               enabled: res.ResultInfo === '0',
           }
           default: return res;
       }
    });
};

// 获取医保规则列表
export function getInsuranceList(data) {
    return request({
        url: '/basis/medicalInsuranceRegulationMgr/listPain',
        method: 'post',
        data
    })
}

// 修改医保规则列表
export function editInsurance(data) {
    return request({
        url: '/basis/medicalInsuranceRegulationMgr/update',
        method: 'post',
        data
    })
}

export function getLogFile() {
    return request({
        url: '/system/version/recordList',
        method: 'post',
    }).then(res => res.Data.map(item => {
        const time = dayjs((item.showTime || item.updateTime || item.createTime || ''));
        return {
            id: item.id,
            content: item.content,
            title: time.format('YYYY/MM/DD HH:mm:ss'),
            time: time.valueOf()
        };
    }).sort((a, b) => b.time - a.time));
}

export function setLogFile(data) {
    return request({
        url: '/system/version/saveOrUpdate',
        method: 'post',
        data: {
            id: data.id === -1 ? null : data.id,
            showTime: data.time.replace(' ', 'T'),
            content: data.content,
        }
    })
}