import request from '../../utils/request'
import apis from '../../config/api'

export default {
  namespaced: true,
  state: {},
  actions: {
    uploadImg (_, payload) {
      return new Promise((resolve, reject) => {
        // const api = lodash.get(apis, 'file.upload')
        const fm = new FormData()
        fm.append('file', payload)
        request({
          ...apis.file.upload,
          data: fm,
        }).then((data) => {
          resolve(data)
        }).catch(({ message }) => {
          if (typeof message === 'string') {
            reject(message)
          }
        })
      })
    },
  }
}