/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许，不可做商业用途！
*
* 版权所有，侵权必究！
*/
import request from '@/utils/request'
import axios from 'axios'

export function getBatchPreSignUrl (fileNames) {
  return request({
    url: '/mall4cloud_biz/ua/oss/get_batch_pre_sign_url',
    method: 'get',
    params: fileNames
  })
}

export function pageFileGroup (param) {
  return request({
    url: '/mall4cloud_biz/mp/attach_file_group/list',
    method: 'get',
    params: param
  })
}

export function getFileGroup (param) {
  return request({
    url: '/mall4cloud_biz/mp/attach_file_group',
    method: 'get',
    params: param
  })
}

export function saveFileGroup (data) {
  return request({
    url: '/mall4cloud_biz/mp/attach_file_group',
    method: 'post',
    data
  })
}

export function updateFileGroup (data) {
  return request({
    url: '/mall4cloud_biz/mp/attach_file_group',
    method: 'put',
    data
  })
}

export function deleteFileGroup (param) {
  return request({
    url: '/mall4cloud_biz/mp/attach_file_group',
    method: 'delete',
    params: param
  })
}

// 上传文件
/**
 * minIo上传文件
 * @param {String} url  请求的url
 * @param {File} data 图片文件
 * @param {UploadRequestOptions} 可选参数options
 * @returns {*}
 */
export function aswImgUpdate (url, data, options) {
  return axios.put(url, data, {
    onUploadProgress: (progressEvent) => {
      // <el-upload/> 配置上传文件进度
      if (options) {
        const complete = (((progressEvent.loaded / progressEvent.total) * 100) | 0)
        options.onProgress({ percent: complete })
      }
    }
  })
}
