import request from '@/utils/request'

export function getOrganizeInfo(query) {
  return request({
    url: '/user/organizeInfo',
    method: 'get',
    params: query
  })
}
// 后台用户管理
export function getUserList(query) {
  return request({
    url: '/other/user/getMallUserInfo',
    method: 'get',
    params: query
  })
}
// 修改用户上下线状态
export function updateUser(query) {
  return request({
    url: '/other/user/updateUser',
    method: 'get',
    params: query
  })
}
// 重置密码
export function repeatPassword(query) {
  return request({
    url: '/other/user/repeatPassword',
    method: 'get',
    params: query
  })
}
// 回显用户信息
export function mallUserById(id) {
  return request({
    url: '/other/user/mallUserById/' + id,
    method: 'get'
  })
}
// 保存用户信息
export function saveUser(data) {
  return request({
    url: '/other/user/saveUser',
    method: 'post',
    data
  })
}
export function updateOrganizeInfo(data) {
  return request({
    url: '/user/update',
    method: 'post',
    data
  })
}

export function changePassword(data) {
  return request({
    url: '/user/changePassword',
    method: 'post',
    data
  })
}

export function uploadFile(data) {
  console.log(data)
  return request({
    url: '/mall/uploadFile/imageUpload',
    method: 'post',
    data
  })
}

/**
 * @param  file
 * @returns output value
 */
export function getBase64(file) {
  return new Promise(function(resolve, reject) {
    const reader = new FileReader()
    let imgResult = ''
    reader.readAsDataURL(file)
    reader.onload = function() {
      imgResult = reader.result
    }
    reader.onerror = function(error) {
      reject(error)
    }
    reader.onloadend = function() {
      resolve(imgResult)
    }
  })
}
