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 documentsReturn = (data) => {
  return request({
    url: `/pu/order/documentsReturn`,
    method: "put",
    data,
  });
}

// 采购订单退回
const close = (data) => {
  return request({
    url: `/pu/order/close`,
    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,
  });

  // return new Promise(resolve => {


  //   // 当前 Promise 的状态由传入的 Promise 去决定
  //   // axios.get(`${process.env.NODE_ENV == "development" ? '/sy-derom' : ''}/apiproxy/service/ssoRegServlet?userCode=${userCode}&busiCenter=001`)
  //   let url =`${process.env.VUE_APP_BASE_API}/pu/order/paymentRequest`;
    
  //   axios.get(url)
  //   .then(res =>{
  //     if(res.status == 200){
  //       resolve(res.data)
  //     }
  //   })
  // })
  
}

export default {
  list,
  details,
  create,
  submit,
  edit,
  revision,
  remove,
  getPrice,
  documentsReturn,
  close,
  toNc,
  payRequest,

}