/*
 * @Author: 倚楼听风雨 18408246387@163.com
 * @Date: 2023-01-09 16:01:45
 * @LastEditors: 倚楼听风雨 18408246387@163.com
 * @LastEditTime: 2023-03-14 15:53:20
 * @FilePath: \log-server-web\src\api\rentComputer.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import service from "@/utils/request";

export const listRentComputerShopList = (data) => {
  return service({
    url: "/rentComputerShop/getRentComputerShopList",
    method: "post",
    data,
  });
};

export const getRentComputerShopNum = (data) => {
  return service({
    url: "/rentComputerShop/getRentComputerShopNum",
    method: "post",
    data,
  });
};
export const getRentComputerShopById = (data) => {
  return service({
    url: "/rentComputerShop/getRentComputerShopById",
    method: "post",
    data,
  });
};
export const addRentComputerShop = (data) => {
  return service({
    url: "/rentComputerShop/addRentComputerShop",
    method: "post",
    data,
  });
};
export const editRentComputerShop = (data) => {
  return service({
    url: "/rentComputerShop/editRentComputerShop",
    method: "put",
    data,
  });
};
export const deleteRentComputerShopById = (data) => {
  return service({
    url: "/rentComputerShop/deleteRentComputerShopById",
    method: "delete",
    data,
  });
};
export const deleteRentComputerShopByIds = (data) => {
  return service({
    url: "/rentComputerShop/deleteRentComputerShopByIds",
    method: "delete",
    data,
  });
};

//RentSetMeal============================================================================
export const listRentSetMealList = (data) => {
  return service({
    url: "/rentSetMeal/getRentSetMealList",
    method: "post",
    data,
  });
};
export const getRentSetMealNum = (data) => {
  return service({
    url: "/rentSetMeal/getRentSetMealNum",
    method: "post",
    data,
  });
};
export const getRentSetMealById = (data) => {
  return service({
    url: "/rentSetMeal/getRentSetMealById",
    method: "post",
    data,
  });
};
export const addRentSetMeal = (data) => {
  return service({
    url: "/rentSetMeal/addRentSetMeal",
    method: "post",
    data,
  });
};
export const editRentSetMeal = (data) => {
  return service({
    url: "/rentSetMeal/editRentSetMeal",
    method: "put",
    data,
  });
};
export const deleteRentSetMealById = (data) => {
  return service({
    url: "/rentSetMeal/deleteRentSetMealById",
    method: "delete",
    data,
  });
};
export const deleteRentSetMealByIds = (data) => {
  return service({
    url: "/rentSetMeal/deleteRentSetMealByIds",
    method: "delete",
    data,
  });
};
//RentSetMeal============================================================================
//RentComputer============================================================================
export const getRentComputerList = (data) => {
  return service({
    url: "/rentComputer/getRentComputerList",
    method: "post",
    data,
  });
};
export const getRentComputerNum = (data) => {
  return service({
    url: "/rentComputer/getRentComputerNum",
    method: "post",
    data,
  });
};
export const addRentComputer = (data) => {
  return service({
    url: "/rentComputer/addRentComputer",
    method: "post",
    data,
  });
};
export const getRentComputerById = (data) => {
  return service({
    url: "/rentComputer/getRentComputerById",
    method: "post",
    data,
  });
};
export const editRentComputer = (data) => {
  return service({
    url: "/rentComputer/editRentComputer",
    method: "put",
    data,
  });
};
export const deleteRentComputerById = (data) => {
  return service({
    url: "/rentComputer/deleteRentComputerById",
    method: "delete",
    data,
  });
};
export const deleteRentComputerByIds = (data) => {
  return service({
    url: "/rentComputer/deleteRentComputerByIds",
    method: "delete",
    data,
  });
};
export const uploadExcel = (data) => {
  return service({
    url: "/rentComputer/importExcel",
    method: "post",
    data,
  });
};
export const renewRentComputer = (data) => {
  return service({
    url: "/rentComputer/renewRentComputer",
    method: "post",
    data,
  });
};
export const replaceNumRentComputer = (data) => {
  return service({
    url: "/rentComputer/replaceNumRentComputer",
    method: "post",
    data,
  });
};
export const rentingOutRentComputer = (data) => {
  return service({
    url: "/rentComputer/rentingOutRentComputer",
    method: "post",
    data,
  });
};
export const offShelfRentComputer = (data) => {
  return service({
    url: "/rentComputer/offShelfRentComputer",
    method: "post",
    data,
  });
};
//RentComputer============================================================================
//RentComputerLedger============================================================================
export const getRentComputerLedgerList = (data) => {
  return service({
    url: "/rentComputer/getRentComputerLedgerList",
    method: "post",
    data,
  });
};
export const getRentComputerLedgerNum = (data) => {
  return service({
    url: "/rentComputer/getRentComputerLedgerNum",
    method: "post",
    data,
  });
};
export const exportRentLedgerListExcel = (tableData, fileName) => {
  service({
    url: "/rentComputer/exportRentLedgerListExcel",
    method: "post",
    data: {
      fileName: fileName,
      infoList: tableData,
    },
    responseType: "blob",
  }).then((res) => {
    handleFileError(res, fileName);
  });
};

const handleFileError = (res, fileName) => {
  if (typeof res.data !== "undefined") {
    if (res.data.type === "application/json") {
      const reader = new FileReader();
      reader.onload = function () {
        const message = JSON.parse(reader.result).msg;
        ElMessage({
          showClose: true,
          message: message,
          type: "error",
        });
      };
      reader.readAsText(new Blob([res.data]));
    }
  } else {
    var downloadUrl = window.URL.createObjectURL(new Blob([res]));
    var a = document.createElement("a");
    a.style.display = "none";
    a.href = downloadUrl;
    a.download = fileName;
    var event = new MouseEvent("click");
    a.dispatchEvent(event);
  }
};
//RentComputerLedger============================================================================
