import { openDownFile } from "@/api/index.js";
import router from "../router/index.ts";
import { showFailToast, showDialog } from "vant";

//获取附件图标
export function getAttachImg(imgName) {
  if (imgName == "doc" || imgName == "docx" || imgName == "wps") {
    return "doc.png";
  } else if (imgName == "xls" || imgName == "xlsx" || imgName == "et") {
    return "xls.png";
  } else if (imgName == "ppt" || imgName == "pptx" || imgName == "dps") {
    return "ppt.png";
  } else if (imgName == "rar" || imgName == "zip") {
    return "rar.png";
  } else if (imgName == "pdf") {
    return "pdf.png";
  } else if (
    imgName == "jpg" ||
    imgName == "png" ||
    imgName == "psd" ||
    imgName == "bmp" ||
    imgName == "gif"
  ) {
    return "jpg.png";
  } else {
    return "txt.png";
  }
}

export async function showAttachJs(attach, detail) {
  console.log("=====333===", attach, detail);
  let appId = "biz_sx_secure";
  let data = {
    local_token: "2nINKLii",
    sessionId: "",
    reqType: "get",
    fileId: attach.id,
    fileUrl: attach.url,
    waterUser: encodeURIComponent(
      localStorage.getItem(process.env.VUE_APP_USERNAME)
    ),
  };
  let returnStr = "";
  await openDownFile(appId, data).then((res) => {
    console.log("openDownFileres===", res);
    if (res.code == 200) {
      console.log("res = res.data==", res.data);
      returnStr = res.data;
    } else {
      showFailToast(res.msg);
    }
  });
  console.log("res==", returnStr);
  if (returnStr) {
    console.log("return==");
    return returnStr;
  }
}

export async function getAttachLink(apiname, data) {
  console.log("=====2222===");
  let linkRes = "";
  await openDownFile(apiname, data).then((res) => {
    console.log(res);
    if (res.code == 200) {
      linkRes = res.data;
    } else {
      showFailToast(res.msg);
    }
  });
  return linkRes;
}
