import { request } from 'umi';
import { projectObj } from '@/config/api.js';
import UserStorage from '@/config/sagacare/sagacare_user';

function getProjectId() {
  //const id = window.localStorage.getItem('localProjectId')
  const id = projectObj.projectId;
  return id;
}

function commonParams() {
  var userObj = UserStorage.getInstance();
  const user = userObj.getUser();
  var pubname = 'sgadmin';
  return `openid=${user.id}&pubname=${pubname}&projectId=${getProjectId()}&userId=${
    user.id
  }&userName=${user.name}&userPhone=${user.phone}`;
}

//新增/修改用户
export async function saveUserInfo(params, options) {
  return request(`/xiaojing/controlSpaceUser/saveUser?${commonParams()}`, {
    method: 'POST',
    from: 'sagacare',
    headers: {
      'Content-Type': 'application/json',
    },
    ...(options || {}),
    data: params,
  });
}
//查询用户信息
export async function queryUserInfo(params, options) {
  return request(`/xiaojing/controlSpaceUser/queryUser?${commonParams()}`, {
    method: 'POST',
    from: 'sagacare',
    headers: {
      'Content-Type': 'application/json',
    },
    ...(options || {}),
    data: {
      ...params,
    },
  });
}
//用户作废
export async function deleteUser(params, options) {
  return request(`/xiaojing/controlSpaceUser/deleteUser?userId=${params.userId}`, {
    method: 'GET',
    from: 'sagacare',
    headers: {
      'Content-Type': 'application/json',
    },
    ...(options || {}),
  });
}
//用户查询列表
export async function queryUserList(params, options) {
  return request(`/xiaojing/controlSpaceUser/query`, {
    method: 'POST',
    from: 'sagacare',
    headers: {
      'Content-Type': 'application/json',
    },
    ...(options || {}),
    data: params,
  });
}
//查询受控列表
export async function queryControlSpaceCompany(params, options) {
  return request(`/xiaojing/controlSpaceUser/getControlSpaceCompany?${commonParams()}`, {
    method: 'POST',
    from: 'sagacare',
    headers: {
      'Content-Type': 'application/json',
    },
    ...(options || {}),
    data: {
      ...params,
    },
  });
}
//是否oa同步
export async function queryCompanyOAById(params, options) {
  return request(`/xiaojing/texCompany/queryCompanyById?companyId=${params.companyId}`, {
    method: 'GET',
    from: 'sagacare',
    headers: {
      'Content-Type': 'application/json',
    },
    ...(options || {}),
  });
}

//获取二维码信息
export async function qrCodeInfo(params, options) {
  // /sgadmin/duoduo-service/duoduoenv-service/userNew/qrCodeInfo
  return request(`/sgadmin/duoduo-service/duoduoenv-service/userNew/qrCodeInfo`, {
    method: 'GET',
    from: 'sagacare',
    headers: {
      'Content-Type': 'application/json',
    },
    ...(options || {}),
  });
}
