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


// 质检项表 类型定义
export interface QcItem {
  id?: number

  name?:  string

  spec?:  string

  plans?:  string

  description?:  string

  status?: number

  createby?: number

  createTime?:  string

  updateTime?:  string

}

// 质检项表 API
export const qcItemApi = {
  // 分页查询
  page(params: { page: number; pageSize: number; id?: number; name?:  string }) {
    return request({ url: '/biz/qcItem/page', method: 'get', params })
  },

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

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

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

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

  // 导出
  export(params?: { ids?:  string[]; id?: number; name?:  string }) {
    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
    if (params?.name !== undefined && params?.name !== null) p.name = params.name
    return request({ url: `/biz/qcItem/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/qcItem/import`,
      method: 'post',
      data: formData,
      headers: { 'Content-Type': 'multipart/form-data' }
    })
  },

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

  //上传文件
  uploadFile(file:File) {
    const formData = new FormData()
    formData.append("file",file)
    return request({
      url:"/sys/file/upload",
      method:"post",
      data:formData
    })
  },


  //查询文件列表
  getPlansFiles(data:{plans:string}) {
    return request({
      url:"/biz/qcItem/getPlanFiles",
      method:"post",
      data:data
    })
  },

  //创建关联
  createQcProcessRelate(data:any) {
    return request({
      url:"/biz/qcItem/createQcProcessRelate",
      method:"post",
      data
    })
  },


  //显示质检项关联列表
  list(params:any) {
      return request({
        url:"/biz/qcItem/list",
        method:"get",
        params
      })
  }
}