/**
 * 厂家管理接口
 */
import request from '@/utils/request'
// import qs from 'qs'

// 施工管理查询
export function getLogList(params) {
  return request({
    url: 'appDeviceLog/list',
    method: 'get',
    params
  })
}
// 日志列表导出
export function batchExportLog(params) {
  return request({
    url: 'appDeviceLog/listExp',
    method: 'post',
    timeout: 120000,
    params,
    responseType: 'blob' // 这一步也很关键，一定要加上 responseType 值为 blob
  })
}

// 设备安装基础信息列表导出（不包含图片）
export function batchExportDeviceAdd(params) {
  return request({
    url: 'appDeviceAdd/listExp',
    method: 'post',
    timeout: 120000000,
    params,
    responseType: 'blob' // 这一步也很关键，一定要加上 responseType 值为 blob
  })
}

// 设备安装基础信息列表导出（包含图片）
export function batchExportDeviceImage(params) {
  return request({
    url: 'appDeviceAdd//image/listExp',
    method: 'post',
    // timeout: 120000,
    params
    // responseType: 'blob' // 这一步也很关键，一定要加上 responseType 值为 blob
  })
}

// 厂家查询
export function getFactoryList(params) {
  return request({
    url: 'factory/pageList',
    method: 'get',
    params
  })
}
// 厂家下拉
export function getFactory(params) {
  return request({
    url: 'factory/getFactory',
    method: 'get',
    params
  })
}
// 添加厂家
export function addFactory(name, personName, address,
  phone, bank, taxNumber, productingDevice, equipmentQuotation, equipmentFile) {
  var param = new FormData()
  param.append('name', name)
  param.append('personName', personName)
  param.append('address', address)
  param.append('phone', phone)
  param.append('bank', bank)
  param.append('taxNumber', taxNumber)
  param.append('productingDevice', productingDevice)
  param.append('equipmentQuotation', equipmentQuotation)
  param.append('equipmentFile', equipmentFile)
  return request({
    url: 'factory/add',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}
// 修改厂家
export function updateFactory(id, name, personName, address,
  phone, bank, taxNumber, productingDevice, equipmentQuotation, equipmentFile) {
  var param = new FormData()
  param.append('id', id)
  param.append('name', name)
  param.append('personName', personName)
  param.append('address', address)
  param.append('phone', phone)
  param.append('bank', bank)
  param.append('taxNumber', taxNumber)
  param.append('productingDevice', productingDevice)
  param.append('equipmentQuotation', equipmentQuotation)
  param.append('equipmentFile', equipmentFile)
  return request({
    url: 'factory/mod',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}
// 获取在产设备列表
export function getDeviceList() {
  return request({
    url: 'deviceType/deviceType',
    method: 'get'
  })
}
// 设备报价表导入
export function batchImportDevicePrice(fileobj) {
  const param = new FormData()
  param.append('fs', fileobj)
  return request({
    url: 'factory/devicePriceImp',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}
// 设备报价表下载
export function batchExportDevicePrice(equipmentQuotation) {
  return request({
    url: 'factory/priceFileDownload',
    method: 'get',
    params: {
      equipmentQuotation: equipmentQuotation
    },
    timeout: 120000,
    responseType: 'blob' // 这一步也很关键，一定要加上 responseType 值为 blob
  })
}
// 批量导入
export function batchImportFactory(fileobj) {
  const param = new FormData()
  param.append('fs', fileobj)
  return request({
    url: 'factory/imp',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}
// 批量导出
export function batchExportFactory(params) {
  return request({
    url: 'factory/listExp',
    method: 'post',
    timeout: 120000,
    params,
    responseType: 'blob' // 这一步也很关键，一定要加上 responseType 值为 blob
  })
}
// 上次导出的列表
export function getLastExportList(data) {
  return request({
    url: `/appDeviceAdd/batch/logs?offset=${data.offset}&limit=${data.limit}`,
    method: 'get'
  })
}

// 下载压缩包
export function downloadZip(recentDir) {
  return request({
    url: '/appDeviceAdd/batchzip',
    // withCredentials: false,
    method: 'get',
    headers: { 'Content-Type': 'application/json; application/octet-stream' },
    timeout: 120000,
    responseType: 'blob', // 这一步也很关键，一定要加上 responseType 值为 blob
    params: {
      recentDir: recentDir
    }
  })
}

