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

// 质检结果明细表 类型定义
export interface QcResultDetail {
    id?: number

    qcId?: number

    resultType?: number

    qty?:  number

    traceCode?:  string

    defectCode?:  string

    handleAction?:  string

    actionStatus?: number

    remark?:  string

    createTime?:  string

    updateTime?:  string

    files?:any[],

    title?:string,
    images?:any[],
    attachments?:any[]

}

// 质检结果明细表 API
export const qcResultDetailApi = {
    // 分页查询
    page(params : { page: number; pageSize: number; id?: number; resultType?: number,traceCode:string,defectCode:string }) {
        return request({ url: '/biz/qcResultDetail/page', method: 'get', params })
    },

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

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

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

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

    // 导出
    export(params?: { ids?: number[]; 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/qcResultDetail/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/qcResultDetail/import`,
            method: 'post',
            data: formData,
            headers: { 'Content-Type': 'multipart/form-data' }
        })
    },

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

    selectlistByqcId(qcId:any) {
        return request({
            url:`/biz/qcResultDetail/selectlistByqcId/${qcId}`,
            method:'get'
        })
    }
}