import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { OrderForm, OrderInfo, OrderInfoPageVO, OrderInfoQuery } from "./types";

/**
 * 获取订单分页列表
 *
 * @param queryParams
 */
export function getOrderPage(
  queryParams: object
): AxiosPromise<PageResult<OrderInfoPageVO[]>> {
  return request({
    url: "/api/v1/plan/order/page",
    method: "post",
    data: queryParams,
  });
}

/**
 * 获取用户表单详情
 *
 * @param userId
 */
export function getExpandAlias(tableType: String): AxiosPromise<any> {
  return request({
    url: "/api/v1/sys/alias/queryByType/" + tableType,
    method: "get",
  });
}
/**
 * 生成二维码数据
 *
 * @param userId
 */
export function getScanCode(tableType: String): AxiosPromise<any> {
  return request({
    url: "/api/v1/plan/order/scanCode/" + tableType,
    method: "get",
  });
}
/**
 * 生成测试数据
 *
 * @param userId
 */
export function getTestCode(): AxiosPromise<any> {
  return request({
    url: "/api/v1/plan/order/testCode",
    method: "get",
  });
}

/**
 * 扫码导入提交
 *
 *
 */
export function scanImport(data: any): AxiosPromise<any> {
  return request({
    url: "/api/v1/plan/order/scanImport",
    method: "post",
    data,
  });
}
/**
 * 添加订单
 *
 * @param data
 */
export function addOrder(data: any) {
  if (data.orderType === "2") {
  }
  return request({
    url: "/api/v1/plan/order/add",
    method: "post",
    data: data,
  });
}

/**
 * 修改订单
 *
 * @param id
 * @param data
 */
export function updateOrder(data: OrderForm) {
  return request({
    url: "/api/v1/plan/order/update",
    method: "post",
    data: data,
  });
}

/**
 * 删除订单
 *
 * @param ids
 */
export function deleteOrders(ids: string[]) {
  return request({
    url: "/api/v1/plan/order/batch-del",
    method: "post",
    data: { ids: ids },
  });
}

/**
 * 下载导入模板
 *
 * @returns
 */
export function downloadTemplateApi() {
  return request({
    url: "/api/v1/plan/order/template",
    method: "get",
    responseType: "arraybuffer",
  });
}

/**
 * 导出
 *
 * @param queryParams
 * @returns
 */
export function exportOrder(queryParams: OrderInfoQuery) {
  return request({
    url: "/api/v1/plan/order/export",
    method: "post",
    data: queryParams,
    responseType: "arraybuffer",
  });
}

/**
 * 导入
 *
 * @param file
 */
export function importOrder(importData: any) {
  return request({
    url: "/api/v1/plan/order/import",
    method: "post",
    data: importData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}

export function apsWorkOrder(params: any) {
  return request({
    url: "/api/v1/plan/aps/scheduling",
    method: "post",
    data: params,
  });
}
export function distributeWorkOrder(workOrderId: any) {
  return request({
    url: "/api/v1/plan/aps/distribute/" + workOrderId,
    method: "get",
  });
}

// 工位任务状态统计
export function getStatistics(data: Object) {
  return request({
    url: "/api/v1/plan/task/statistics",
    method: "post",
    data: data,
  });
}

export function queryApplyInfoDetails(params: any) {
  return request({
    url: "/api/v1/plan/requisition/queryInfoDetails",
    method: "post",
    data: params,
  });
}

export function saveApplyInfoDetails(params: any) {
  return request({
    url: "/api/v1/plan/requisition/add",
    method: "post",
    data: params,
  });
}

export function auditApplyInfoDetails(params: any) {
  return request({
    url: "/api/v1/plan/requisition/audit",
    method: "post",
    data: params,
  });
}

export function queryOrderList(
  queryParams: object
): AxiosPromise<PageResult<any[]>> {
  return request({
    url: "/api/v1/plan/order/list",
    method: "post",
    data: queryParams,
  });
}

export function revokeWorkOrder(workOrderId: any) {
  return request({
    url: "/api/v1/plan/aps/revoke/" + workOrderId,
    method: "get",
  });
}

export function queryWorkOrderList(params: any) {
  return request({
    url: "/api/v1/plan/workOrder/list",
    method: "post",
    data: params,
  });
}

export function lockWorkOrder(params: any) {
  return request({
    url: "/api/v1/plan/workOrder/lockWorkOrder",
    method: "post",
    data: params,
  });
}
export function prepareCheckInfo(workOrderCode: string): AxiosPromise<any> {
  return request({
    url: "/api/v1/plan/prepare/checkInfo/" + workOrderCode,
    method: "get",
  });
}

export function bomMaterial(workOrderCode: string): AxiosPromise<any> {
  return request({
    url: "/api/v1/plan/prepare/bomMaterial/" + workOrderCode,
    method: "get",
  });
}
export function refreshPrepareCheckInfo(
  workOrderCode: string
): AxiosPromise<any> {
  return request({
    url: "/api/v1/plan/prepare/refresh/" + workOrderCode,
    method: "get",
  });
}
export function zipWorkOrder(data: object): AxiosPromise<any> {
  return request({
    url: "/api/v1/workOrder/data/zip",
    method: "post",
    data: data,
  });
}

export function addShortage(data: object): AxiosPromise<any> {
  return request({
    url: "/api/v1/planShortage/add",
    method: "post",
    data: data,
  });
}

export function handleShortage(data: object): AxiosPromise<any> {
  return request({
    url: "/api/v1/planShortage/handle",
    method: "post",
    data: data,
  });
}
export function zipOrder(data: object): AxiosPromise<any> {
  return request({
    url: "/api/v1/workOrder/data/order/zip",
    method: "post",
    data: data,
  });
}

export function getShortageItem(shortageId: number): AxiosPromise<any> {
  return request({
    url: "/api/v1/planShortageItem/getShortageItem/" + shortageId,
    method: "get",
  });
}
