import request from '@/utils/request'

// 创建工单
export function createWorkorderInfos(data) {
  return request({
    url: '/server/workorder-infos/create',
    method: 'post',
    data: data
  })
}

// 更新工单
export function updateWorkorderInfos(data) {
  return request({
    url: '/server/workorder-infos/update',
    method: 'post',
    data: data
  })
}

// 关闭工单
export function closeWorkorderInfos(id) {
  return request({
    url: '/server/workorder-infos/close?id=' + id,
    method: 'post'
  })
}

// 删除工单
export function deleteWorkorderInfos(id) {
  return request({
    url: '/server/workorder-infos/delete?id=' + id,
    method: 'post'
  })
}

// 获得工单
export function getWorkorderInfos(id) {
  return request({
    url: '/server/workorder-infos/get?id=' + id,
    method: 'get'
  })
}

// 获得工单分页
export function getWorkorderInfosPage(params) {
  return request({
    url: '/server/workorder-infos/page',
    method: 'get',
    params
  })
}
// 导出工单 Excel
export function exportWorkorderInfosExcel(params) {
  return request({
    url: '/server/workorder-infos/export-excel',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// 获取所属用户
export function getUserList() {
  return request({
    url: '/server/workorder-infos/belonging-user',
    method: 'get',
  })
}

// 工单获取所属用户
export function getWorkorderUserList() {
  return request({
    url: '/server/workorder-infos/workorder-belonging-user',
    method: 'get',
  })
}

// 上传工单附件
export function uploadWorkorderFile(file) {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/server/workorder-infos/upload',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: formData
  })
}

// 查询审批记录
export function getApproveList(id) {
  return request({
    url: '/server/workorder-log/list?workorderId=' + id,
    method: 'get'
  })
}
// 审核工单
export function checkWorkorderInfos(data) {
  return request({
    url: '/server/workorder-infos/check',
    method: 'post',
    data: data
  })
}
// 驳回对象列表
export function rejectList(id) {
  return request({
    url: '/server/workorder-log/reject-list?workorderId=' + id,
    method: 'get'
  })
}

//首页卡片数据
export function getHomeCardData() {
  return request({
    url: '/server/workorder-infos/card',
    method: 'get'
  })
}
//首页部门统计
export function getHomeDepartmentStats() {
  return request({
    url: '/server/workorder-infos/dept-workorder',
    method: 'get'
  })
}

//首页待处理工单
export function getHomePendingWorkorder(params) {
  return request({
    url: '/server/workorder-infos/pending-workorder',
    method: 'get',
    params: params
  })
}
