import request from "@/utils/request";

export function LIST(params) {
  return request({
    url: "/pu/contract/list",
    method: "GET",
    params: params,
  });
}

export function ADD(data) {
  return request({
    url: "/pu/contract/add",
    method: "POST",
    data: data,
  });
}

export function EXPORT(data) {
  return request({
    url: "/pu/contract/export",
    method: "POST",
    data: data,
  });
}

export function IMPORT(params) {
  return request({
    url: "/pu/contract/importData",
    method: "GET",
    params: params,
  });
}

export function EDIT(data) {
  return request({
    url: "/pu/contract/edit",
    method: "PUT",
    data: data,
  });
}

export function REMOVE(data) {
  return request({
    url: `/pu/contract/${data}`,
    method: "DELETE",
  });
}

export function ITEM(data) {
  return request({
    url: `/pu/contract/${data}`,
    method: "GET",
  });
}

export function CODE() {
  return request({
    url: "/pu/contract/generateNo",
    method: "GET",
  });
}

const switchUrl = (prop) => {
  if (prop === "contractItemList") return "/pu/contract/item";
  if (prop === "contractClauseList") return "/pu/contract/clause";
  if (prop === "contractExpenseList") return "/pu/contract/expense";
  if (prop === "contractAgreementList") return "/pu/contract/agreement";
  if (prop === "contractApplyOrgList") return "/pu/contract/org";
};

export function TABLELIST(params, name) {
  return request({
    url: `${switchUrl(name)}/list`,
    method: "GET",
    params: params,
  });
}

export function TABLEADD(data, name) {
  return request({
    url: `${switchUrl(name)}/add`,
    method: "POST",
    data: data,
  });
}

export function TABLEEDIT(data, name) {
  return request({
    url: `${switchUrl(name)}`,
    method: "PUT",
    data: data,
  });
}

export function TABLEROMOVE(data, name) {
  return request({
    url: `${switchUrl(name)}/${data}`,
    method: "DELETE",
  });
}
