import request from "@/utils/request";
import axios from "axios";

// 采购订单修订列表
const list = (data, page) => {
  return request({
    url: `/pu/order/list`,
    method: "post",
    data,
    params: page,
  });
}


// 采购订单详情
const details = (id, params) => {
  return request({
    url: `/pu/order/${id}`,
    method: "get",
    params,
  });
}

// 采购订单修订创建
const create = (data) => {
  return request({
    url: `/pu/order`,
    method: "post",
    data,
  });
}

// 采购订单提交
const submit = (data) => {
  return request({
    url: `/pu/order/submit`,
    method: "post",
    data,
  });
}

// 采购订单编辑
const edit = (data) => {
  return request({
    url: `/pu/order`,
    method: "put",
    data,
  });
}

// 采购订单修订
const revision = (data) => {
  return request({
    url: `/pu/order/revision`,
    method: "put",
    data,
  });
}

// 采购订单删除
const remove = (data) => {
  return request({
    url: `/pu/order/${data}`,
    method: "delete",
  });
}

// 采购订单-询价
const getPrice = (data) => {
  return request({
    url: `/pu/order/getPrice`,
    method: "post",
    data,
  });
}

// 采购订单-计算金额
const calculateOrderAmount = (data) => {
  return request({
    url: `/pu/order/calculateOrderAmount`,
    method: "post",
    data,
  });
}


// 采购订单退回
const documentsReturn = (data) => {
  return request({
    url: `/pu/order/documentsReturn`,
    method: "put",
    data,
  });
}

// 采购订单整单关闭
const close = (data) => {
  return request({
    url: `/pu/order/close`,
    method: "post",
    data,
  });
}
// 采购订单行关闭
const itemClose = (data) => {
  return request({
    url: `/pu/order/item/close`,
    method: "post",
    data,
  });
}
// 采购订单行打开
const itemOpen = (data) => {
  return request({
    url: `/pu/order/item/open`,
    method: "post",
    data,
  });
}

// 采购订单发送NC
const toNc = (data) => {
  return request({
    url: `/pu/order/toNc`,
    method: "post",
    data,
  });
}
// 付款协议  https://sy.derom.com/apiproxy/service/ssoRegServlet?userCode=000156&busiCenter=001
const payRequest = () => {

  return request({
    url: `/pu/order/paymentRequest`,
    method: "get",
    // params,
  });
}

const REFER = (data, params) => {
  return request({
    url: "/refer/query",
    method: "POST",
    data: data,
    params: params,
  });
}
// 获取入库数据
const putInStorage = (data) => {
  return request({
    url: "/pu/order/putInStorage",
    method: "POST",
    data: data,
  });
}
// 获取退货订单
const returnedGoods = (data) => {
  return request({
    url: "/pu/order/returnedGoods",
    method: "POST",
    data: data,
  });
}

const toOA = (userName, fdId) => {
  return request({
    url: `/oaflow/redirectToOa/${userName}/${fdId}`,
    method: 'get',
  })
}



// 采购订单修订导出
const orderExport = (data) => {
  return request({
    url: `/pu/order/export`,
    method: "POST",
    data: data,
  })
}

// 行导入
const orderImport = (data) => {
  return request({
    url: "/pu/order/import",
    method: "POST",
    data: data,
  });
}
// 模板下载
const downloadFailData = (data) => {
  return request({
    url: "/pu/order/downloadFailData",
    method: "POST",
    data: data,
  });
}

//收回
export function oaBack(data) {
  return request({
    url: `/oaflow/rollback`,
    method: "POST",
    data: data,
  });
}

// 转派
export function modifyBuyer(data) {
  return request({
    url: "/pu/order/modifyBuyer",
    method: "PUT",
    data: data,
  });
}
// 物料批量粘贴 /pu/order/item/copy/
export function materialCopy(data) {
  return request({
    url: "/pu/order/item/copy",
    method: "POST",
    data,
  });
}
// 反审
export function counterApprove(data) {
  return request({
    url: "/pu/order/counterApprove",
    method: "POST",
    data,
  });
}
// 合单
export function merge(data) {
  return request({
    url: "/pu/order/merge",
    method: "POST",
    data,
  });
}


export default {
  list,
  details,
  create,
  submit,
  edit,
  revision,
  remove,
  getPrice,
  calculateOrderAmount,
  documentsReturn,
  close,
  toNc,
  payRequest,
  REFER,
  putInStorage,
  returnedGoods,
  toOA,
  orderExport,
  orderImport,
  downloadFailData,
  oaBack,
  modifyBuyer,
  itemClose,
  itemOpen,
  materialCopy,
  counterApprove,
  merge,
}