import {axios} from '@/utils/request'
import {SERVICES_FILE_MANAGEMENT, upcloud_base_common, upcloud_base_wh_inbound, SERVICE_DATA_API_BASE} from "@/config/serviceSettings";

import qs from 'qs'

const baseUrl = SERVICES_FILE_MANAGEMENT

// 上传文件-返回路径
export const uploadFileForPath = data => {
  return axios.post(baseUrl + '/file/upload-file', data)
}
// 删除文件
export const delFile = data => {
  return axios.post(baseUrl + '/file/delete', qs.stringify(data), {
    headers: {
      'content-type': 'application/x-www-form-urlencoded'
    }
  })
}
// 下载文件-单个
export const downloadFileForOne = params => {
  return axios.get(baseUrl + '/file/download', {
    params,
    contentType: "application/octet-stream",
    responseType: 'blob',
  })
}
// 打包下载文件-directoryId
export const downloadFileForAll = data => {
  return axios.post(baseUrl + '/file/downloadall', qs.stringify(data), {
    headers: {
      'content-type': 'application/x-www-form-urlencoded'
    }
  })
}
// 文件上传 -> 写入业务系统
export const uploadFilePipe = async (form = {}, formData) => {
  const uploadRes = await uploadFileForPath(formData)
  if (!uploadRes.success) {
    return Promise.reject(uploadRes)
  }
  const {data: {fileName: originFileName, id: fileId, path: fileUrl} = {}} = uploadRes
  const params = {...form, originFileName, fileId, fileUrl}
  return fileSaveToBiz(params)
}

// 文件&业务系统关联
export const fileSaveToBiz = data => {
  return axios.post(upcloud_base_wh_inbound + '/rqcLinePass/rqcPassUploadPic', data)
}
// 图片管理列表查询
export const fileGetFormBiz = params => {
  // var params = {}
  // params.bizId = this.resData.bizId
  // params.bizType = this.resData.bizType
  // params.pageNum = 1
  // params.pageSize = 10
  return axios.get(upcloud_base_common + '/bizFile/page', {params})
}

export const fileDelToBiz = data => {
  return axios.post(upcloud_base_common + '/bizFile/del', data)
}

export const fileEnum = {
  // 商品图片
  item: '11SPTP',
  // 商品证件
  item_certificate: '21SPZZ',
  // 供应商样章
  vendor_sample_chapter: '12GYSYZ',
  // 供应商随货同行单模板
  vendor_withItems_template: '13GYSSHTXDMB',
  // 供应商证件
  vendor_certificate: '22GYSZZ',
  // 物流商证件
  carrier_certificate: '23WLSZZ',
  // 货主证件
  consignor_certificate: '24HZZZ',
  // 客户证件
  customer_certificate: '25KHZZ',
  // 设备证件
  device_certificate: '26SBZZ',
  // 打印模板
  print_template: '14DYMB',
  // 直调入库审核图片
  transferStockIn_img: '31ZDSHTP',
  // 质量公告附件
  notice_file: '32GGFJ',
  // 停售申请单附件
  sellStopBill_file: '33TSSQFJ',
  // 损益单附件
  gainsLosses_file: '34SYFJ',
  // 质量复查单附件
  qualityReview_file: '35ZLFCFJ',
  // 销毁单附件
  destroyRequest_file: '36XHFJ',
  // 验证管理附件
  recVT_file: '37YZGLFJ',
  // 药检报告单附件
  drugTestReport_file: '38YJBGDFJ',
  // 随货同行单附件
  withItems_file: '39SHTXDFJ',
  // 发票管理附件
  invoice_file: '40FPFJ',
  // 出库回签管理附件
  recipientSlip_file: '41CKHQFJ',
  // 合同管理
  contract_file: '42CKHQFJ',
  // 投诉单附件
  complaints_file: '43TSDFJ'
}