import request from '@/utils/request'

const api = {
  staffCan: '/staff/can',
  staffDeparts: '/staff/departs',
  staffDepartsUser: '/staff/users',
  addPreDepartUser: '/staff/users/create',
  addDepartsUser: '/staff/users',
  editDepartsUser: '/staff/users/{staff_id}',
  delDepartsUser: '/staff/users/{staff_id}',
  getDepartsUser: '/staff/users',
  getDepartsOrder: '/staff/addresses',
  getDefaultUserInfo: '/staff/users/{staff_id}/edit'
}

/**
 * @returns 判断是否能查看订单与权限
 */
export function staffCan () {
  return request({
    url: api.staffCan
  })
}

/**
 * @returns 用户组织架构
 */
export function staffDeparts () {
  return request({
    url: api.staffDeparts
  })
}

/**
 * @returns 我的组织列表
 */
export function staffDepartsUser () {
  return request({
    url: api.staffDepartsUser
  })
}

/**
 * @returns 组织下用户列表
 */
export function getDepartsUser (parameter) {
  return request({
    url: api.getDepartsUser,
    method: 'get',
    params: parameter
  })
}
/**
 * @returns 组织下待指派订单列表
 */
export function getDepartsOrder (parameter) {
  return request({
    url: api.getDepartsOrder,
      method: 'get',
      params: parameter
  })
}

/**
 * @returns 我的用户新增前置获取下级身份
 */
export function addPreDepartUser (parameter) {
  return request({
    url: api.addPreDepartUser,
    params: parameter
  })
}

/**
 * @returns 组织下增加用户操作
 */
export function addDepartsUser (parameter) {
  return request({
    url: api.addDepartsUser,
    method: 'POST',
    params: parameter
  })
}

/**
 * @returns 组织下修改用户操作
 */
export function editDepartsUser (staffId, parameter) {
  return request({
    url: api.editDepartsUser.replace('{staff_id}', staffId),
    method: 'PUT',
    params: parameter
  })
}

/**
 * @returns 组织下删除用户操作
 */
export function delDepartsUser (staffId) {
  return request({
    url: api.delDepartsUser.replace('{staff_id}', staffId),
    method: 'DELETE'
  })
}

/**
 * @returns 组织下用户修改前置
 */
export function getDefaultUserInfo (staffId) {
  return request({
    url: api.getDefaultUserInfo.replace('{staff_id}', staffId)
  })
}
