import request from '@/config/axios'

// 采购订单相关类型定义
export interface PurchaseOrderVO {
  id?: number // 主键ID, integer(int64)
  documentNumber: string // 单据编码, string
  purchaseOrderType: string // 采购订单类型, string
  documentType: string // 单据类型, string
  isPrinted: string // 是否已打印, string
  printedBy?: string // 打印人, string
  printedTime?: string // 打印时间, string(date-time)
  updatedTime?: string // 订单更新时间, string(date-time)
  isProcessed: string // 是否已处理, string
  processedBy?: string // 处理人, string
  processedTime?: string // 处理时间, string(date-time)
  companyCode: string // 公司代码, string
  purchasingOrganization: string // 采购组织, string
  purchasingGroup: string // 采购组, string
  supplier: string // 供应商, string
  supplierDescription: string // 供应商描述, string
  createdBy?: string // 创建人, string
  createdTime?: string // 创建时间, string(date-time)
  deleted?: boolean // 是否删除, boolean
}

// 分页查询参数
export interface PurchaseOrderPageParam {
  pageNo?: number
  pageSize?: number
  purchaseOrderNumber?: string // 采购订单号
  salesOrderNumber?: string // 销售订单号
  styleNumber?: string // 款号
  createTimeRange?: [string, string] // 订单创建时间范围
  updateTimeRange?: [string, string] // 订单更新时间范围
}
// 采购订单头表相关接口
// 更新采购订单头表
export const updatePurchaseOrderHeader = (data: any) => {
  return request.put({ url: '/print/purchase/order-header/update', data })
}

// 获得采购订单头表分页
export const getPurchaseOrderHeaderPage = (data: any) => {
  return request.post({ url: '/print/purchase/order-header/page', data })
}

// 获得采购订单明细分页
export const getPurchaseOrderDetailsPage = (data: any) => {
  return request.post({ url: '/print/purchase/order-header/detailsPage', data })
}

// 创建采购订单头表
export const createPurchaseOrderHeader = (data: any) => {
  return request.post({ url: '/print/purchase/order-header/create', data })
}

// 获得采购订单明细列表
export const getPurchaseOrderDetailListByHeaderId = (headerId: number) => {
  return request.get({ url: `/print/purchase/order-header/order-detail/list-by-header-id?headerId=${headerId}` })
}

// 获得采购订单头表
export const getPurchaseOrderHeader = (id: number) => {
  return request.get({ url: `/print/purchase/order-header/get?id=${id}` })
}

// 采购订单模板下载
export const purchaseDownloadTemplate = () => {
  return request.downloadPost({ url: '/print/purchase/order-header/downloadTemplate' })
}
// 采购订单导入
export const purchaseImport = (data: any) => {
  return request.upload({ url: '/print/purchase/order-header/import', data })
}
export const purchaseImportToB = (data: any) => {
  return request.upload({ url: '/print/purchase/order-header/material-importToB', data })
}
// 删除采购订单头表
export const deletePurchaseOrderHeader = (id: number) => {
  return request.delete({ url: `/print/purchase/order-header/delete?id=${id}` })
}

// 批量删除采购订单头表
export const deletePurchaseOrderHeaderList = (ids: number[]) => {
  return request.delete({
    url: '/print/purchase/order-header/delete-list',
    params: { ids: ids.join(',') }
  })
}
// 逐行生成条码
export const createPurchaseOrderTagDetail = (data: any) => {
  return request.post({ url: '/print/purchase/order-tag-details/create', data })
}

// 标签明细分页
export const getPurchaseOrderTagDetailPage = (data: any) => {
  return request.post({ url: `/print/purchase/order-tag-details/page`, data })
}
// 标签生成记录
export const getPurchaseOrderTagRecordPage = (data: any) => {
  return request.post({ url: `/print/purchase/order-tag-records/page`, data })
}
// 订单变更记录
export const getPurchaseOrderChangeRecordPage = (data: any) => {
  return request.post({ url: `/print/purchase/order-change-records/page`, data })
}
// 更新采购订单标签明细
export const updatePurchaseOrderTagDetail = (data: any) => {
  return request.post({ url: '/print/purchase/order-tag-details/update', data })
}
// 标签明细确认完成
export const updatePurchaseOrderTagDetailCompleteStatus = (params: any) => {
  return request.get({ url: '/print/purchase/order-header/updateCompleteStatus', params })
}
// 标签明细删除
export const deletePurchaseOrderTagDetailList = (ids: number[]) => {
  return request.delete({
    url: '/print/purchase/order-tag-details/delete-list',
    params: { ids: ids.join(',') }
  })
}
// 处理采购订单标签明细
export const updatePurchaseOrderChangeRecord = (data: any) => {
  return request.post({ url: '/print/purchase/order-change-records/update', data })
}
// 根据模板编码查设计json
export const getTagTemplateConfigList = (data: any) => {
  return request.post({ url: '/print/tag-template-config/getConfigList', data })
}
export const getCapacityTotalByOrderNo = (data: any) => {
  return request.post({ url: '/print/purchase/order-detail/getCapacityTotal', data })
}
export const capacityTotalPage = (data: any) => {
  return request.post({ url: '/print/purchase/order-detail/capacityTotalPage', data })
}
export const exportCapacityTotal = (data: any) => {
  return request.downloadPost({ url: '/print/purchase/order-detail/exportCapacityTotal', data })
}