/**
 * 计量计划接口
 */
import request from '@/api/index'

// 计量计划列表-（不同状态）
export function getListPage(params: any, statusName: string) {
  if (statusName === '全部') {
    return request({
      url: `/plan/allPage?limit=${params.limit}&offset=${params.offset}`,
      method: 'post',
      data: {
        ...params,
      },
    })
  }
  else if (statusName === '已审批') {
    return request({
      url: `/plan/approval/approvedListPage?limit=${params.limit}&offset=${params.offset}`,
      method: 'post',
      data: {
        ...params,
      },
    })
  }
  else if (statusName === '待审批') {
    return request({
      url: `/plan/approval/toApprovalListPage?limit=${params.limit}&offset=${params.offset}`,
      method: 'post',
      data: {
        ...params,
      },
    })
  }
  else {
    return request({
      url: `/plan/approval/listPage?limit=${params.limit}&offset=${params.offset}`,
      method: 'post',
      data: {
        ...params,
      },
    })
  }
}
// 导出计划列表
export function exportPlan(data: object) {
  return request({
    url: '/plan/allExport',
    method: 'post',
    data,
    responseType: 'blob',
  })
}
// 保存
export function editPlan(data: object) {
  return request({
    url: '/plan/approval/saveOrUpdate',
    method: 'post',
    data,
  })
}
// 提交
export function submitPlan(data: object) {
  return request({
    url: '/plan/approval/submit',
    method: 'post',
    data,
  })
}
// 详情
export function detailPlan(id: string) {
  return request({
    url: `/plan/detail?id=${id}`,
  })
}
// 删除
export function delPlan(id: string) {
  return request({
    url: `/plan/approval/delete?id=${id}`,
    method: 'post',
    // data: {
    //   id,
    // },
  })
}
// 取消
export function cancelPlan(data: object) {
  return request({
    url: '/plan/approval/cancel',
    method: 'post',
    data,
  })
}
// 审批操作
export function handlerApproval(type: string, data: { processId?: string; taskId?: string; comments: string }) {
  return request({
    url: `/plan/approval/${type}`,
    method: 'post',
    data,
  })
}
// 获取聚合数据
export function getInfoListTogether(id: string) {
  return request({
    url: '/plan/equipmentAggr',
    params: {
      planId: id,
    },
  })
}
// 获取展开数据
export function getInfoList(id: string, name: string) {
  return request({
    url: '/plan/relationList',
    params: {
      planId: id,
      equipmentName: name,
    },
  })
}
// 发送送检通知

export function sendNotify(id: string) {
  return request({
    url: `/planNotify/notify?planId=${id}`,
    method: 'post',
  })
}
