import request from '@/utils/request'
import { download } from '@/utils/request'

// 查询划款管理列表
export function listCollection(query) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/list',
    method: 'get',
    params: query
  })
}

// 查询划款管理列表
export function listContract(query) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/getWaitForCollection',
    method: 'get',
    params: query
  })
}

export function exportCllection(query) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  download(
    "business/collection/export",
    {
      ...query,
    },
    `收款管理导出_${new Date().getTime()}.xlsx`
  )
}

// 查询账户
export function listAccount(query) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/listAccount',
    method: 'get',
    params: query
  })
}

export function getCollectionByContract(query) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/getCollectionByContract',
    method: 'get',
    params: query
  })
}
export function listCompany(query) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/listCompany',
    method: 'get',
    params: query
  })
}

export function setCollectionStatus(data) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/setCollectionStatus',
    method: 'put',
    data: data
  })
}

// 删除收款
export function delCollection(id) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/del/' + id,
    method: 'Delete'
  })
}

export function setCollectionZero(id) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/setCollectionZero/' + id,
    method: 'get'
  })
}



export function getCreditTermByCompId(query) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/getCreditTermByCompId',
    method: 'get',
    params: query
  })
}

// 查询划款管理详细
export function getCollection(id) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/' + id,
    method: 'get'
  })
}

// 新增划款管理
export function addCollection(data) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection',
    method: 'post',
    data: data
  })
}

export function saveCollection(data) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/save',
    method: 'post',
    data: data
  })

}

// 修改划款管理
export function updateCollection(data) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection',
    method: 'put',
    data: data
  })
}


export function exportCollection(query) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  download(
    "business/collection/export",
    {
      ...query,
    },
    `划款导出_${new Date().getTime()}.xlsx`
  )
}
export function verifyCollection(data) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/verified',
    method: 'post',
    data: data
  })
}

export function exportLoopTemplate() {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  download(
    "business/collection/exportLoop",
    {
    },
    `循环合同收款模板_${new Date().getTime()}.xlsx`
  )
}

export function exportOnceTemplate() {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  download(
    "business/collection/exportOnce",
    {
    },
    `单次合同收款模板_${new Date().getTime()}.xlsx`
  )
}

// 文件上传
export function importLoop(file) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: `/business/collection/importLoop`,
    method: 'post',
    data: file,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
// 文件上传
export function importOnce(file) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: `/business/collection/importOnce`,
    method: 'post',
    data: file,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}


// 查询collection 所有收款
export function getCollectionDetail(id) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: `/business/collection/detail/` + id,
    method: 'get'
  })
}


export function statistics(query) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/statistics',
    method: 'get',
    params: query
  })
}


export function listTask() {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/listTask',
    method: 'post',
  })
}

export function exportStatistics(query) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  download(
    "/business/collection/exportStatistics",
    {
      ...query,
    },
    `收款统计报表导出_${new Date().getTime()}.xlsx`
  )
}


export function getByContract(data) {
  request.defaults.baseURL = '/ezhizao-yzbh-financial'
  return request({
    url: '/business/collection/getByContract',
    method: 'post',
    data: data
  })
}
