import { axios } from '@/utils/request'
import { stringify } from 'qs'

/**
 * user page func
 * parameter: {
 *     keyword: '',
 * }
 * @param parameter
 * @returns {*}
 */
export function getUserPage (parameter) {
  return axios({
    url: `/upms/users/page?${stringify(parameter)}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function addUser (parameter) {
  return axios({
    url: `/upms/users`,
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

export function updateUser (parameter) {
  return axios({
    url: `/upms/users/${parameter.userId}`,
    method: 'PUT',
    data: parameter
  })
}

export function updateUserInfo (parameter) {
  return axios({
    url: `/upms/users/change-info`,
    method: 'PUT',
    data: parameter
  })
}

export function fetchUser (parameter) {
  return axios({
    url: `/upms/users/${parameter.userId}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function fetchWorkUser (parameter) {
  return axios({
    url: `/upms/users/work/${parameter.userId}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function queryUser (parameter) {
  return axios({
    url: `/upms/users?${stringify(parameter)}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function queryDeptChildrenRoleUser (parameter) {
  return axios({
    url: `/upms/users/deptChildrenRole?${stringify(parameter)}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function queryProjectRole (parameter) {
  return axios({
    url: `/upms/users/projectRole?${stringify(parameter)}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function resetUserPwd (parameter) {
  return axios({
    url: `/upms/users/reset-pwd/${parameter.userId}`,
    method: 'PUT'
  })
}

export function changeUserPwd (parameter) {
  return axios({
    url: `/upms/users/change-pwd`,
    method: 'PUT',
    data: parameter
  })
}

export function changeMobile (parameter) {
  return axios({
    url: `/upms/users/change-mobile`,
    method: 'PUT',
    data: parameter
  })
}

export function updateUserStatus (parameter) {
  return axios({
    url: `/upms/users/${parameter.userId}/status/${parameter.status}`,
    method: 'PUT'
  })
}

export function updateUserWorkFlag (parameter) {
  return axios({
    url: `/upms/users/work/${parameter.userId}/${parameter.workFlag}`,
    method: 'PUT',
    data: parameter
  })
}

export function deleteUsers (parameter) {
  return axios({
    url: `/upms/users`,
    method: 'DELETE',
    data: parameter
  })
}

export function updateAvatar (parameter) {
  return axios({
    url: `/upms/users/avatar`,
    method: 'PUT',
    data: parameter
  })
}

/**
 * 根据部门查询当前部门指定父级  再查询指定父级下的指定部门人员
 * @param parameter
 * @returns {AxiosPromise}
 */
export function queryUsersByParentDeptNatureAll (parameter) {
  return axios({
    url: `/upms/users/dept/${parameter.nature}?${stringify(parameter)}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * 根据部门查询当前部门指定父级  再查询指定父级下的指定部门人员
 * @param parameter
 * @returns {AxiosPromise}
 */
export function usersByUserParentDeptNatureAll (parameter) {
  return axios({
    url: `/upms/users/user/dept/${parameter.nature}?${stringify(parameter)}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * add func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function importUser (deptId, parameter) {
  return axios({
    url: '/upms/users/import/' + deptId,
    method: 'POST',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    data: parameter
  })
}
