/**
 * 设备台账-设备基本信息管理接口
 */
import request from '@/api/index'
const prefix = 'equipment/info'

// 设备列表 -分页 -（全部状态）
export function getInfoListPage(params: any, statusName: string) {
  if (statusName === '全部') {
    return request({
      url: `${prefix}/listPage?limit=${params.limit}&offset=${params.offset}&sort=${params.sort || ''}&orderBy=${params.orderBy || ''}`,
      method: 'post',
      data: params,
    })
  }
  else if (statusName === '已审批') {
    return request({
      url: `/equipment/approval/approvedListPage?limit=${params.limit}&offset=${params.offset}&sort=${params.sort || ''}&orderBy=${params.orderBy || ''}`,
      method: 'post',
      data: params,
    })
  }
  else if (statusName === '待审批') {
    return request({
      url: `/equipment/approval/toApprovalListPage?limit=${params.limit}&offset=${params.offset}&sort=${params.sort || ''}&orderBy=${params.orderBy || ''}`,
      method: 'post',
      data: params,
    })
  }
  else {
    return request({
      url: `/equipment/approval/listPage?limit=${params.limit}&offset=${params.offset}&sort=${params.sort || ''}&orderBy=${params.orderBy || ''}`,
      method: 'post',
      data: params,
    })
  }
}
// 设备列表聚合
export function getInfoListTogether(params: object) {
  return request({
    url: `${prefix}/groupByName`,
    method: 'post',
    data: params,
  })
}
// 获取设备列表
export function getInfoList(params: object) {
  return request({
    url: `${prefix}/list`,
    method: 'post',
    data: params,
  })
}
// 导入
export function importDevice(data: object, deviceType: string) {
  return request({
    url: `/equipment/info/import?equipmentType=${deviceType}`,
    method: 'post',
    data,
  })
}
// 获取设备详情
export function getInfoDetail(params: object) {
  return request({
    url: '/equipment/info/detail',
    method: 'get',
    params,
  })
}
// 获取设备审批状态基本信息
export function getApprovalDetail(params: object) {
  return request({
    url: 'equipment/approval/detail',
    method: 'get',
    params,
  })
}
// 保存编辑
export function editInfo(data: object) {
  return request({
    url: '/equipment/approval/saveOrUpdate',
    method: 'post',
    data,
  })
}
// 导出
export function exportDevice(data: object) {
  return request({
    url: '/equipment/info/export',
    method: 'post',
    data,
    responseType: 'blob',
  })
}
// 提交
export function submitInfo(data: object) {
  return request({
    url: '/equipment/approval/submit',
    method: 'post',
    data,
  })
}
// 删除记录
export function deleteInfo(data: object) {
  return request({
    url: `/equipment/approval/delete?id=${data.id}`,
    method: 'post',
  })
}
// 删除设备
// export function deleteDevice(data: object) {
//   return request({
//     url: '/equipment/approval/delete',
//     method: 'post',
//     data,
//   })
// }
// 取消
export function cancelInfo(data: object) {
  return request({
    url: '/equipment/approval/cancel',
    method: 'post',
    data,
  })
}
// 审批操作
export function handlerApproval(type: string, data: { processId?: string; taskId?: string; comments: string }) {
  return request({
    url: `/equipment/approval/${type}`,
    method: 'post',
    data,
  })
}
// 审批记录
export function getApprovalRecord(id: string) {
  return request({
    url: `/equipment/approval/equipmentLog?equipmentId=${id}`,
    method: 'get',
  })
}
// 设备流转日志

export function getTurnoverLogRecord(id: string) {
  return request({
    url: `/equipment/turnoverLog/list?equipmentId=${id}`,
    method: 'get',
  })
}
// 设备状态变更记录
export function getStatusLogRecord(id: string) {
  return request({
    url: `/equipment/statusLog/list?equipmentId=${id}`,
    method: 'get',
  })
}
// 绑定参试任务
export function bindTaskHandler(data: object) {
  return request({
    url: '/equipment/bindTask',
    method: 'post',
    data,
  })
}
