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

// 让步接收申请表 类型定义
export interface ConcessionApply {
  id?: number

  qcId?: number

  concessionQty?: number

  applyRemark?:  string

  applyContent?:  string

  applyFile?:  string

  applyUserId?: number

  deptId?: number

  instanceId?:  string

  approveStatus?: string

  createTime?:  string

  updateTime?:  string

}


export interface DetailModel {

  businessId:string,
  title:string,
  deptName:string,
  approveResult:string,
  approveRecord:[]
}

// 让步接收申请表 API
export const concessionApplyApi = {
  // 分页查询
  page(params: { page: number; pageSize: number; id?: number }) {
    return request({ url: '/biz/concessionApply/page', method: 'get', params })
  },

  // 获取详情
  detail(id:  string) {
    return request({ url: `/biz/concessionApply/${id}`, method: 'get' })
  },

  // 新增
  create(data: ConcessionApply) {
    return request({ url: '/biz/concessionApply', method: 'post', data })
  },

  // 修改
  update(data: ConcessionApply) {
    return request({ url: '/biz/concessionApply', method: 'put', data })
  },

  // 删除
  delete(ids:  number[]) {
    return request({ url: `/biz/concessionApply/${ids.join(',')}`, method: 'delete' })
  },

  // 导出
  export(params?: { ids?:  string[]; id?: number }) {
    const p: Record<string, any> = {}
    if (params?.ids?.length) p.ids = params.ids.join(',')
    if (params?.id !== undefined && params?.id !== null) p.id = params.id
    return request({ url: `/biz/concessionApply/export`, method: 'get', params: p, responseType: 'blob' })
  },

  // 导入
  importData(file: File) {
    const formData = new FormData()
    formData.append('file', file)
    return request<{ success: number; fail: number; errors: string[] }>({
      url: `/biz/concessionApply/import`,
      method: 'post',
      data: formData,
      headers: { 'Content-Type': 'multipart/form-data' }
    })
  },

  // 下载导入模板
  downloadTemplate() {
    return request({ url: `/biz/concessionApply/template`, method: 'get', responseType: 'blob' })
  },

  //撤回审批申请
  approveCancel(params?:{id?:number}){
    return request({url:`/biz/concessionApply/approveCancel`,method:'get',params})
  }

}