import request from '@/utils/request'

export function getOrganizeInfo(query) {
  return request({
    url: '/user/organizeInfo',
    method: 'get',
    params: query
  })
}

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)
    }
  })
}
