import request from '@/utils/request';

// 列表
export async function updateStatusPauseRecover(data) {
  const res = await request.put(`/mes/workorder/updateStatusPauseRecover`, {
    params: data
  });
  console.log(res.data.code == 0);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function updateStatusPause(params) {
  const res = await request.put(`/mes/workorder/updateStatusPause`, {
    params: data
  });
  console.log(res.data.code == 0);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 工单终止
export async function updateStatusTerminate(params) {
  const res = await request.put(`/mes/workorder/updateStatusTerminate`, {
    params: data
  });
  console.log(res.data.code == 0);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function produceDetail(id) {
  const res = await request.get(`/pda/mes/workorder/produceDetail/${id}`, {});
  console.log(res.data.code == 0);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取资产数量
 *
 * @param data 请求参数
 * @returns 返回资产数据或 undefined
 */
export async function workorderList(data) {
  const res = await request.post('/pda/mes/workorder/list', data);

  console.log(res);
  if (res.data.code == 0) {
    return res.data.data;
  }
}

export async function workorderPage(params) {
  const res = await request.post('/pda/mes/workorder/page', params);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//   物料详情
export async function pickorderList(params) {
  const res = await request.post('/pda/mes/pickorder/list', params);
  console.log(res);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// export async function updateStatusPauseRecover(params) {
// 	const data = await putJ(
// 		Vue.prototype.apiUrl + `/mes/workorder/updateStatusPauseRecover`, params, true,
// 	);
// 	if (data.code == 0) {
// 		return data.data;
// 	}
// 	return Promise.reject(data.message);
// }

// 任务列表 pageByCurrentUser 我的任务
export async function pageByCurrentUser(data) {
  const res = await request.get('/aps/assign/pageByCurrentUser/v2', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 任务列表 pageByCurrentUserLeader 全部任务
export async function pageByCurrentUserLeader(data) {
  const res = await request.get('/aps/assign/pageByCurrentUserLeader/v2', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 根据当前用户查工作中心跟班组
export async function listWorkCenter(firstProduceTaskId) {
  const res = await request.get(
    `/aps/assign/listWorkCenterTeamsByProduceTaskId/${firstProduceTaskId}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 更新派单任务实际时间
export async function batchUpdateRealTime(data) {
  const res = await request.put(`/aps/assign/batchUpdateRealTime`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 获取派单任务项更新实际时间记录
export async function listUpdateRealTimeRecord(assigneeId) {
  const res = await request.get(
    `/aps/assign/listUpdateRealTimeRecord/${assigneeId}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 根据任务ID获取派单任务项分页列表
export async function pageAssigneeByTask(params) {
  const res = await request.get(`/aps/assign/pageAssigneeByTask`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 更新派单任务实际时间确认
export async function batchUpdateRealTimeConfirm(data) {
  const res = await request.put(`/aps/assign/batchUpdateRealTimeConfirm`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
