/*
 * @Author: YLZH
 * @Date: 2023-06-12 12:01:19
 * @LastEditors: YLZH
 * @LastEditTime: 2023-06-15 09:57:55
 * @FilePath: \purchase\purchase_ao\src\api\directional.js
 */
import request from "../utils/request";
function splicing(url, obj) {
  let str = url;
  Object.keys(obj).forEach((item, i) => {
    if (obj[item] == "") return;
    if (typeof obj[item] !== "string" && typeof obj[item] !== "number") {
      return;
    }

    if (str.indexOf("?") == -1) {
      str += "?" + item + "=" + obj[item];
    } else {
      str += "&" + item + "=" + obj[item];
    }
  });
  return str;
}
// 互斥产品管理
// 获取列表
// url: `/spinfo/huchi/list?productName=${data.productName}&productRule=${data.productRule}&auditStatus=${data.auditStatus}&pageNum=${data.pageNum}&pageSize=${data.pageSize}&spId=${data.spId}&orderHuchiToName=${data.orderHuchiToName}&relaUnsubToName=${data.relaUnsubToName}&beginTime=${data.beginTime}&endTime=${data.endTime}`,
// 
export const getMutualExclusionList = (data) =>
  request({
    url: splicing("/spinfo/huchi/list", data),
    method: "get",
  });
// 获取详情
export const getMutualExclusionDetail = (id) =>
  request({
    url: `/spinfo/huchi/detail/${id}`,
    method: "get",
  });
// 删除数据
export const deleteMutualExclusion = (id) =>
  request({
    url: splicing("/crypto/mutualExclusion", { id }),
    method: "delete",
  });
// 添加数据
export const addMutualExclusion = (data) =>
  request({
    url: "/crypto/mutualExclusion",
    method: "post",
    data,
  });
// 修改数据
export const updateMutualExclusion = (data, id) =>
  request({
    url: `/spinfo/huchi/update/${id}`,
    method: "post",
    data,
  });
//产品管理
export const productList = (data) =>
  request({
    url: splicing("/sync/spinfo/list", data),
    method: "get",
    data,
  });
// 产品管理详情
export const productDetail = (id) =>
  request({
    url: "/sync/spinfo/detail/" + id,
    method: "get",
  });
// 新增产品管理
export const productAdd = (data) =>
  request({
    url: "/sync/spinfo/add",
    method: "post",
    data,
  });
// 产品管理修改
export const productUpdate = (data, id) =>
  request({
    url: "/sync/spinfo/update/" + id,
    method: "post",
    data,
  });

// 草稿箱列表
export const draftList = (data) =>
  request({
    url: splicing("/crypto/puk/draft/list", data),
    method: "get",
  });
// 删除草稿箱
export const deleteDraft = (id) =>
  request({
    url: splicing("/crypto/puk/draft", { id }),
    method: "delete",
  });
// 产品管理草稿箱
export const productDraft = (data) =>
  request({
    url: "/crypto/puk/draft",
    method: "post",
    data,
  });

// 互斥管理 版本列表
export const versionList = (data) =>
  request({
    url: splicing("/crypto/mutualExclusion/version/list", data),
    method: "get",
  });
// 版本详情
export const versionDetail = (id) =>
  request({
    url: splicing("/crypto/mutualExclusion/version", { id }),
    method: "get",
  });

// 查询互斥管理列表
export const getHuchiList = (data) => {
  return request({
    url: splicing("/spinfo/huchi/list", data),
    method: "get",
  });
};

// 互斥管理详情
export const getHuchiDetail = (id) =>
  request({
    url: "/spinfo/huchi/detail/" + id,
    method: "get",
  });
// 新增互斥管理
export const addHuchi = (data) =>
  request({
    url: "/spinfo/huchi/save",
    method: "post",
    data,
  });
//更新产品互斥管理
export const updateHuchi = (data, id) => {
  return request({
    url: "/spinfo/huchi/update/" + id,
    method: "post",
    data,
  });
};
// 互斥提交审核
export const huchiSubmit = (data) =>
  request({
    url: "/spinfo/huchi/sendaudit",
    method: "post",
    data,
  });

/**
 *草稿部分
 */

// 互斥管理草稿箱
export const huchiDraft = (data) =>
  request({
    url: splicing("/spinfo/huchi/listbox", data),
    method: "get",
    data,
  });
// 互斥管理新增草稿箱
export const saveVersionAdd = (data) =>
  request({ url: "/spinfo/huchi/savetobox", method: "post", data });
// 互斥管理草稿箱详情
export const getHuchiDraftDetail = (id) =>
  request({
    url: "/spinfo/huchi/detailbox/" + id,
    method: "get",
  });
// 保存到草稿箱
export const saveToDraft = (data) =>
  request({
    url: "/spinfo/huchi/savetobox",
    method: "post",
    data,
  });
// 更新草稿箱
export const updateDraft = (data, id) =>
  request({
    url: "/spinfo/huchi/updatebox/" + id,
    method: "post",
    data,
  });
// 删除草稿箱
export const deleteDraftBox = (id) =>
  request({
    url: "/spinfo/huchi/delbox/" + id,
    method: "post",
  });
//
// 查询审核模板
export const getAuditTemplate = (data) =>
  request({
    url: "/auditTemplate/page",
    method: "post",
    data: { pageNum: 1, pageSize: 999 },
  });

// 查询历史版本
export const getHistoryVersion = (data) =>
  request({
    url: "/spinfo/huchi/version",
    method: "post",
    data,
  });
