import request from '@/config/axios'
// 生产报工单 VO
export interface ProduceReportVO {
  id: number // ID
  processInstanceId: string // 流程实例编号
  reportCode: string // 编号
  userId: number // 用户ID
  orgId: number // 工序ID
  orgType: string // 工序
  reportTime: string // 计件时段
  totalTime: number // 总时长
  reportStatus: number // 报工状态
  remark: string // 备注
  groupType: number // 班别
  reportType: string // 报工类型
  reportDate: Date // 报工日期
}

// 生产报工单 API
export const ProduceReportApi = {
  // 查询生产报工单分页
  getProduceReportPage: async (params: any) => {
    return await request.get({ url: `/mes/produce-report/page`, params })
  },
// 查询生产报工单分页
  getDailyReportPage: async (params: any) => {
    return await request.get({ url: `/mes/produce-report/pageDailyReport`, params })
  },
  // 查询生产报工单详情
  getProduceReport: async (id: number) => {
    return await request.get({ url: `/mes/produce-report/get?id=` + id })
  },

  // 新增生产报工单
  createProduceReport: async (data: ProduceReportVO) => {
    return await request.post({ url: `/mes/produce-report/create`, data })
  },

  // 修改生产报工单
  updateProduceReport: async (data: ProduceReportVO) => {
    return await request.put({ url: `/mes/produce-report/update`, data })
  },

  // 删除生产报工单
  deleteProduceReport: async (id: number) => {
    return await request.delete({ url: `/mes/produce-report/delete?id=` + id })
  },
// 更改报工单状态
  updateStatus: async (id: number, status:number) => {
    return await request.get({ url: `/mes/produce-report/updateStatus?id=` + id +'&status='+status})
  },
  // 导出生产报工单 Excel
  exportProduceReport: async (params) => {
    return await request.download({ url: `/mes/produce-report/export-excel`, params })
  },

// ==================== 子表（生产报工明细） ====================

  // 获得生产报工明细列表
  getProduceReportDetailListByReportId: async (reportId) => {
    return await request.get({ url: `/mes/produce-report/produce-report-detail/list-by-report-id?reportId=` + reportId })
  }
}

// 生产报工明细 VO
export interface ProduceReportDetailVO {
  id: number // ID
  reportId: number // 报工单id
  planId: number // 生产计划ID
  productId: number // 产品ID
  userId: number // 用户ID
  orgId: number // 组织ID
  qualityRate: number // 成品率
  wasteReason: string // 备注
  totalTime: number // 总时长
  packageNumber: number // 打包数量
  remark: string // 备注
  isEnable: boolean // 是否启用
  qualityNumber: number // 成品数量
  wasteNumber: number // 废品数量
  totalNumber: number // 总数量
  reportDate: Date // 报工日期
  reportTime: number // 计件时间
  reportStatus: number // 报工状态
  groupType: number //班别
  reportType: string
  orgType: string
  reportDateString: string
}

// 生产报工明细 API
export const ProduceReportDetailApi = {
  // 查询生产报工明细分页
  getProduceReportDetailPage: async (params: any) => {
    return await request.get({ url: `/mes/produce-report-detail/page`, params })
  },
  // 查询生产报工明细分页
  getProduceReportDetailPageCenter: async (params: any) => {
    return await request.get({ url: `/mes/produce-report-detail/pageCenter`, params })
  },
  // 查询生产报工明细详情
  getProduceReportDetail: async (id: number) => {
    return await request.get({ url: `/mes/produce-report-detail/get?id=` + id })
  },

  // 新增生产报工明细
  createProduceReportDetail: async (data: ProduceReportDetailVO) => {
    return await request.post({ url: `/mes/produce-report-detail/create`, data })
  },

  // 修改生产报工明细
  updateProduceReportDetail: async (data: ProduceReportDetailVO) => {
    return await request.put({ url: `/mes/produce-report-detail/update`, data })
  },

  // 删除生产报工明细
  deleteProduceReportDetail: async (id: number) => {
    return await request.delete({ url: `/mes/produce-report-detail/delete?id=` + id })
  },

  // 导出生产报工明细 Excel
  exportProduceReportDetail: async (params) => {
    return await request.download({ url: `/mes/produce-report-detail/export-excel`, params })
  },
  // 更改报工单状态
  updateStatus: async (id: number, status:number) => {
    return await request.get({ url: `/mes/produce-report-detail/updateStatus?id=` + id +'&status='+status})
  },
}
