import request from '@/config/axios'

export interface MaterialVO {
  id: number
  name: string
  code: string
  materialGroupId: number
  materialGroupName: string
  model: string
  unit: string
  sort: number
  sapCode: string
  status: number
  remark: string
  unitPrice: number
  quantity: number
  syncTime: Date
  createTime: Date
}

// 查询物料管理列表 分页
export const getMaterialPage = (params: PageParam) => {
  return request.get({ url: '/rq/iot-material/page', params })
}

// 查询物料管理列表 分页
export const listByBomId = (params: any) => {
  return request.get({ url: '/rq/iot-material/list-by-bom-id', params })
}

// 查询物料详情
export const getMaterial = (id: number) => {
  return request.get({ url: '/rq/iot-material/get?id=' + id })
}

// 新增物料
export const createMaterial = (data: MaterialVO) => {
  return request.post({ url: '/rq/iot-material/create', data })
}

// 修改物料
export const updateMaterial = (data: MaterialVO) => {
  return request.put({ url: '/rq/iot-material/update', data })
}

// 删除物料
export const deleteMaterial = (id: number) => {
  return request.delete({ url: '/rq/iot-material/delete?id=' + id })
}

// 导出物料
export const exportMaterial = (params) => {
  return request.download({ url: '/rq/iot-material/export', params })
}

// 下载物料导入模板
export const importMaterialTemplate = () => {
  return request.download({ url: '/rq/iot-material/get-import-template' })
}

// 物料状态修改
export const updateMaterialStatus = (id: number, status: number) => {
  const data = {
    id,
    status
  }
  return request.put({ url: '/rq/iot-material/update-status', data: data })
}

// 获取物料精简信息列表
export const getSimpleMaterialList = (): Promise<MaterialVO[]> => {
  return request.get({ url: '/rq/iot-material/simple-list' })
}
