// import { get, post } from '@/services/index';
import qs from 'qs';
import { CITY_SERVICE, get, post, PUBLISH_SERVICE } from '@/services/index';

export const getUserTree = (selectOU, node) =>
  get(`${PUBLISH_SERVICE}/UserCenter/GetOUTree`, {
    selectOU,
    node,
  });

// export const getOneOUUserListNew = OUID =>
//   get(`${CITY_SERVICE}/OMS.svc/U_GetOneOUUserListNew`, {
//     _version: 9999,
//     _dc: new Date().getTime(),
//     OUID,
//   });

export const getOneOUUserListNew = (OUID, size, index, keywords) =>
  get(`${PUBLISH_SERVICE}/UserCenter/GroupUserList`, {
    groupId: OUID,
    pageSize: size,
    pageIndex: index,
    key: keywords,
  });

/**
 * 查询用户
 * @param {*} key
 */
// export const getUserByKey = key =>
//   get(`${CITY_SERVICE}/OMS.svc/U_GetUserByKey`, {
//     _version: 9999,
//     _dc: new Date().getTime(),
//     key,
//   });

export const GetUserByKeyNew = params => get(`${PUBLISH_SERVICE}/UserCenter/GetUserByKey`, params);

/**
 * 添加用户
 * @param {*} param0
 */
export const addUser = ({ GroupId, OUID, loginName, userName, password, phone, email }) =>
  post(`${PUBLISH_SERVICE}/UserCenter/AddUser`, {
    _version: 9999,
    _dc: Date.now(),
    OUID,
    loginName,
    userName,
    password,
    phone,
    email,
    GroupId,
  });

export const addOrg = (orgID, OUName, description, comment) =>
  get(`${PUBLISH_SERVICE}/UserCenter/AddOU`, {
    pid: orgID,
    OUName,
    description,
    comment,
  });

export const editOrgInfo = (orgID, OUName, description, comment) =>
  get(`${PUBLISH_SERVICE}/UserCenter/EditOneOUInfo`, {
    ouid: orgID,
    ouName: OUName,
    description,
    comment,
  });

export const deleteOrg = orgID =>
  get(`${PUBLISH_SERVICE}/UserCenter/DeleteOU`, {
    OUID: orgID,
  });

export const getUserRelationList = userID =>
  get(`${PUBLISH_SERVICE}/UserCenter/GetUserRelationList`, {
    userID: `${userID}`,
  });

export const addToOrg = (userID, orgID, newOrgID) =>
  get(`${PUBLISH_SERVICE}/UserCenter/JumpToAnotherOU`, {
    userID,
    oldOUID: orgID,
    newOUID: newOrgID,
  });
// 批量更改机构
export const addToOrgs = (userIDs, orgIDs, newOrgID) =>
  get(`${PUBLISH_SERVICE}/UserCenter/ModifyUserRole`, {
    userIds: userIDs,
    oldGroupIds: orgIDs,
    newGroupId: newOrgID,
  });

export const updateUserPassword = params =>
  post(`${PUBLISH_SERVICE}/UserCenter/UpdateUserPassword`, params);

// 批量获取用户角色和机构
export const loadAllUserRole = params =>
  post(`${PUBLISH_SERVICE}/UserCenter/LoadAllUserRole`, params);

export const editUser = (userID, loginName, userName, phone, email) =>
  get(`${PUBLISH_SERVICE}/UserCenter/EditUser`, {
    userID,
    loginName,
    userName,
    phone,
    email,
  });

export const setUserState = (OUID, state) =>
  get(`${PUBLISH_SERVICE}/UserCenter/UserStateOU`, {
    OUID,
    state,
  });

// 批量删除用户
export const multiDeleteUsers = userIDs =>
  get(`${PUBLISH_SERVICE}/UserCenter/DeleteUsers`, {
    userIds: userIDs,
  });

export const setUserRelation = (userID, roleList = [], stationList) =>
  post(
    `${CITY_SERVICE}/OMS.svc/U_SetUserRelationList?_version=9999`,
    qs.stringify({
      userID,
      roleList: roleList.length ? `${roleList.join(',')},` : '',
      stationList: stationList.length ? `${stationList.join(',')},` : '',
      headList: '',
      mobileMapList: '',
      currentSolution: '熊猫智慧水务平台',
    }),
    {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
    },
  );
export const SetUserRelationList = (userID, roleList = [], stationList) =>
  post(`${PUBLISH_SERVICE}/UserCenter/SetUserRelationList`, {
    userID,
    roleList: roleList.length ? `${roleList.join(',')},` : '',
    stationList: stationList.length ? `${stationList.join(',')},` : '',
    headList: '',
    mobileMapList: '',
    currentSolution: '熊猫智慧水务平台',
  });

export const setUserRelations = (userIDs, roleList, stationList) =>
  get(`${PUBLISH_SERVICE}/UserCenter/SetUserRoleMap`, {
    userIds: userIDs,
    roleIds: roleList || '',
    stationList: stationList || '',
  });

export const setOrgArea = params => get(`${PUBLISH_SERVICE}/UserCenter/SetOrgUserArea`, params);
export const getOrgArea = params => get(`${PUBLISH_SERVICE}/UserCenter/GetOrgUserArea`, params);
export const GetMapSetByGroupID = params =>
  get(`${PUBLISH_SERVICE}/Maplayer/GetMapSetByGroupID`, params);
export const GetOUTreeNew = params => get(`${PUBLISH_SERVICE}/UserCenter/GetOUTree`, params);

export const GetUserRelationListNew = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/GetUserRelationList`, params);

export const AddUserNew = params => post(`${PUBLISH_SERVICE}/UserCenter/AddUser`, params);

export const AddOUNew = params => get(`${PUBLISH_SERVICE}/UserCenter/AddOUNew`, params);

// export const EditOneOUInfoNew = params =>
// get(`${PUBLISH_SERVICE}/UserCenter/EditOneOUInfo`, params)

export const JumpToAnotherOUNew = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/JumpToAnotherOU`, params);

export const EditUserNew = params => get(`${PUBLISH_SERVICE}/UserCenter/EditUser`, params);

export const UserStateOUNew = params => get(`${PUBLISH_SERVICE}/UserCenter/UserStateOU`, params);

export const DeleteUserNew = params => get(`${PUBLISH_SERVICE}/UserCenter/DeleteUser`, params);

export const SetUserRelationListNew = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/SetUserRelationList`, params);
// 菜单拖拽
export const DragGroup = params => post(`${PUBLISH_SERVICE}/UserCenter/DragGroup`, params);
// 获取所有站点
export const GetAllSite = params => get(`${PUBLISH_SERVICE}/UserCenter/GetAllSite`, params);
// 设置为主管
export const SetGroupManager = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/SetGroupManager`, params);
// 设置接收短信
export const ChangeSMSState = params => get(`${PUBLISH_SERVICE}/UserCenter/ChangeSMSState`, params);
// 获取用户密码验证规则
export const GetPasswordRegularization = params =>
  get(`${PUBLISH_SERVICE}/UserCenter/GetPasswordRegularization`, params);

export const SysConfiguration = params =>
  get(`/PandaCore/GCK/Common/SysConfiguration?moduleName=登录加密`, params);
// export const DeleteOUNew = params =>
// get(`${PUBLISH_SERVICE}/UserCenter/DeleteOU`, params)
