import request from '@/utils/request'

// 查询采购交易列表
export function listTransaction(query) {
  return request({
    url: '/ccdi/purchaseTransaction/list',
    method: 'get',
    params: query
  })
}

// 查询采购交易详情
export function getTransaction(purchaseId) {
  return request({
    url: '/ccdi/purchaseTransaction/' + purchaseId,
    method: 'get'
  })
}

// 新增采购交易
export function addTransaction(data) {
  return request({
    url: '/ccdi/purchaseTransaction',
    method: 'post',
    data: data
  })
}

// 修改采购交易
export function updateTransaction(data) {
  return request({
    url: '/ccdi/purchaseTransaction',
    method: 'put',
    data: data
  })
}

// 删除采购交易
export function delTransaction(purchaseIds) {
  return request({
    url: '/ccdi/purchaseTransaction/' + purchaseIds,
    method: 'delete'
  })
}

// 下载导入模板
export function importTemplate() {
  return request({
    url: '/ccdi/purchaseTransaction/importTemplate',
    method: 'post'
  })
}

// 导入采购交易
export function importData(file, updateSupport) {
  const formData = new FormData()
  formData.append('file', file)
  formData.append('updateSupport', updateSupport)
  return request({
    url: '/ccdi/purchaseTransaction/importData',
    method: 'post',
    data: formData
  })
}

// 查询导入状态
export function getImportStatus(taskId) {
  return request({
    url: '/ccdi/purchaseTransaction/importStatus/' + taskId,
    method: 'get'
  })
}

// 查询导入失败记录
export function getImportFailures(taskId, pageNum, pageSize) {
  return request({
    url: '/ccdi/purchaseTransaction/importFailures/' + taskId,
    method: 'get',
    params: { pageNum, pageSize }
  })
}
