import request from '@/utils/request'

// 查询维保工单列表
export function listGxtOrder(query) {
  return request({
    url: '/gxt/order/list',
    method: 'get',
    params: query
  })
}

// 查询维保工单详细
export function getGxtOrder(id) {
  return request({
    url: '/gxt/order/' + id,
    method: 'get'
  })
}

// 新增维保工单
export function addGxtOrder(data) {
  return request({
    url: '/gxt/order',
    method: 'post',
    data: data
  })
}

// 修改维保工单
export function updateGxtOrder(data) {
  return request({
    url: '/gxt/order',
    method: 'put',
    data: data
  })
}

// 删除维保工单
export function delGxtOrder(id) {
  return request({
    url: '/gxt/order/' + id,
    method: 'delete'
  })
}

// 派单给班组组长
export function assignToTeamLeader(id, teamLeaderId, teamLeaderName) {
  return request({
    url: '/gxt/order/assignToTeamLeader/' + id,
    method: 'put',
    params: {
      teamLeaderId: teamLeaderId,
      teamLeaderName: teamLeaderName
    }
  })
}

// 班组组长接单
export function acceptByTeamLeader(id) {
  return request({
    url: '/gxt/order/acceptByTeamLeader/' + id,
    method: 'put'
  })
}

// 班组组长派单给工作组成员
export function assignToWorkGroupMember(id, workGroupMemberId, workGroupMemberName) {
  return request({
    url: '/gxt/order/assignToWorkGroupMember/' + id,
    method: 'put',
    params: {
      workGroupMemberId: workGroupMemberId,
      workGroupMemberName: workGroupMemberName
    }
  })
}

// 工作组成员接单
export function acceptByWorkGroupMember(id) {
  return request({
    url: '/gxt/order/acceptByWorkGroupMember/' + id,
    method: 'put'
  })
}

// 挂起工单
export function suspendWorkOrder(id, gxtWorkOrder) {
  return request({
    url: '/gxt/order/suspend/' + id,
    method: 'post',
    data: gxtWorkOrder
  })
}

// 重启工单
export function restartWorkOrder(id) {
  return request({
    url: '/gxt/order/restart/' + id,
    method: 'put'
  })
}

// // 完成工单
// export function completeWorkOrder(id) {
//   return request({
//     url: '/gxt/order/complete/' + id,
//     method: 'put'
//   })
// }

// 查询工单流转记录
export function getWorkOrderFlow(orderId) {
  return request({
    url: '/gxt/order/flow/' + orderId,
    method: 'get'
  })
}

// 接单（支持一次性选择处理人员和工作班成员）
export function acceptOrder(id, gxtWorkOrder) {
  return request({
    url: '/gxt/order/accept/' + id,
    method: 'post',
    data: gxtWorkOrder
  })
}

// 开始处理工单
export function startWorkOrder(id, gxtWorkOrder) {
  return request({
    url: '/gxt/order/start/' + id,
    method: 'post',
    data: gxtWorkOrder
  })
}

// 暂停工单
export function pauseWorkOrder(id, gxtWorkOrder) {
  return request({
    url: '/gxt/order/pause/' + id,
    method: 'post',
    data: gxtWorkOrder
  })
}

// 继续处理工单
export function resumeWorkOrder(id, gxtWorkOrder) {
  return request({
    url: '/gxt/order/resume/' + id,
    method: 'post',
    data: gxtWorkOrder
  })
}

// 审批挂起申请
export function approveWorkOrder(id, gxtWorkOrder) {
  return request({
    url: '/gxt/order/approve/' + id,
    method: 'post',
    data: gxtWorkOrder
  })
}

// 结数工单
export function completeWorkOrder(id, gxtWorkOrder) {
  return request({
    url: '/gxt/order/complete/' + id,
    method: 'post',
    data: gxtWorkOrder
  })
}

// 上传工单附件
export function uploadAttachments(orderId, formData) {
  return request({
    url: '/gxt/order/uploadAttachments?orderId=' + orderId,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 导出维保工单数据
export function exportGxtOrder(query) {
  return request({
    url: '/gxt/order/export',
    method: 'post',
    params: query
  })
}

// 导入维保工单数据
export function importGxtOrder(data) {
  return request({
    url: '/gxt/order/importData',
    method: 'post',
    data: data
  })
}

// 导入工单人员数据
export function importGxtWorkOrderPersonFromExcel(data) {
  return request({
    url: '/gxt/workOrderPerson/importData',
    method: 'post',
    data: data
  })
}

// 导入工单人员数据(根据MIS编号)
export function importGxtWorkOrderPerson(data) {
  return request({
    url: '/gxt/workOrderPerson/import',
    method: 'post',
    data: data
  })
}

// 下载维保工单导入模板
export function importTemplate() {
  return request({
    url: '/gxt/order/importTemplate',
    method: 'post'
  })
}

// 查询首页工单统计列表
export function getHomePageOrderListData(query) {
  return request({
    url: '/gxt/order/getHomePageOrderListData',
    method: 'get',
    params: query
  })
}

// 作废维保工单
export function invalidateGxtOrder(data) {
  return request({
    url: '/gxt/order/invalidate',
    method: 'post',
    data: data
  })
}

// 获取导出字段
export function getExportFields() {
  return request({
    url: '/gxt/order/exportFields',
    method: 'get'
  })
}

export function shutdownOrder(data) {
  return request({
    url: '/gxt/order/shutdown',
    method: 'put',
    data: data
  })
}
