const toast = {
    // 全局成功提示
    success: function (message = "Success message", time = 2000) {
      const child = document.createElement("div");
      child.id = "child";
      document.body.appendChild(child);
      child.style.position = "fixed";
      child.style.top = "20%";
      child.style.left = "50%";
      child.style.transform = "translate(-50%, -50%)";
  
      document.getElementById("child").innerHTML = `<div
            style="background-color: #f0f9eb; padding: 20px; border-radius: 10px; border: 1px solid #ccc;"
          >
            <span style="vertical-align: middle; color: #93c26d"
              >${message}</span
            >
          </div>`;
      setTimeout(function () {
        child.parentNode.removeChild(child);
      }, time);
    },
  
    // 全局失败提示
    errer: function (message = "Failure message", time = 2000) {
      const child = document.createElement("div");
      child.id = "child";
      document.body.appendChild(child);
      child.style.position = "fixed";
      child.style.top = "20%";
      child.style.left = "50%";
      child.style.transform = "translate(-50%, -50%)";
  
      document.getElementById("child").innerHTML = `<div
            style="background-color: #fef0f0; padding: 20px; border-radius: 10px; border: 1px solid #ccc;"
          >
            <span style="vertical-align: middle; color: #f56c6c"
              >${message}</span
            >
          </div>`;
      setTimeout(function () {
        child.parentNode.removeChild(child);
      }, time);
    },
  };
  
  // 对话框
  // text  显示文字内容
  // okFn  点击ok执行的回调方法
  // 回调要是匿名函数直接传就行。要是具名函数不带参数写函数名就行。
  // 要是具名函数带参数改成下面这样传
  // function ceshi(参数) {
  //   return (参数) => {
  //     这里写具体的函数实现
  //   }
  // }
  // 例子： dialog('hahahahah', ceshi('参数'), false)
  // isCancel  是否显示关闭按钮
  // okBtnCont  成功按钮的文字
  // cancelBtnCont   取消按钮的文字
  const dialog = function (
    text = "文字内容",
    okFn = function () {},
    isCancel = true,
    okBtnCont = "OK",
    cancelBtnCont = "Cancel",
    okBtnContColor = '#FF8E5E',
    cancelBtnContColor = '#ff8e5e',
    hintBlock = 'inline-block',
    newWidth = '',
  
  ) {
    if (document.getElementById("child1")) return;
    // console.log('child1');
    const child1 = document.createElement("div");
    child1.id = "child1";
    document.body.appendChild(child1);
    child1.style.position = "fixed";
    child1.style.top = "0";
    child1.style.left = "0";
    child1.style.zIndex = "999999";
    child1.style.width = "100%";
    child1.style.height = "100%";
    document.getElementById("child1").innerHTML = `
          <div style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);">
            <div class="commonPopDiv">
              <div class="popText"><div style=" width: 24px; height: 24px; display: ${hintBlock};border-radius: 50%; border: 2px solid #FF946C; color: #FF946C; text-align: center; line-height: 22px; font-size: 16px; margin-right: 10px;">!</div>${text}</div>
              <div class="btnDiv btnDivMar">
                <button class="btn blueBtn" id="dialogOk" style="margin:0 10px!important; width: ${newWidth};background: ${okBtnContColor}">${okBtnCont}</button>&nbsp;
                <button class="btn orangeBtn" id="dialogCancel" style="background: ${cancelBtnContColor}">${cancelBtnCont}</button>
              </div>
            </div>
          </div>
        `;
  
    const dialogOk = document.getElementById("dialogOk");
    const dialogCancel = document.getElementById("dialogCancel");
  
    if (!isCancel) {
      dialogCancel.parentNode.removeChild(dialogCancel);
    }
  
    dialogOk.onclick = function () {
      child1.parentNode.removeChild(child1);
      okFn();
    };
  
    dialogCancel.onclick = function () {
      child1.parentNode.removeChild(child1);
    };
  };
  
  // 查看图片大图
  const viewImages = function (url) {
    const viewImages = document.createElement("div");
    const bodyDom = document.getElementsByTagName("body");
    bodyDom[0].style.overflow = "hidden";
    viewImages.id = "viewImg";
    document.body.appendChild(viewImages);
    viewImages.style.position = "fixed";
    viewImages.style.top = "0";
    viewImages.style.left = "0";
    viewImages.style.width = "100%";
    viewImages.style.height = "100%";
    viewImages.style.backgroundColor = "rgba(0, 0, 0, 0.5)";
    viewImages.style.zIndex = "999999";
    document.getElementById("viewImg").innerHTML = `
            <img src="${url}" style="width: 800px; top: 50%; left: 50%; position: absolute; transform: translate(-50%, -50%)"></img>
        `;
  
    viewImages.onclick = function () {
      viewImages.parentNode.removeChild(viewImages);
      bodyDom[0].style.overflow = "auto";
    };
  };
  
  // 添加购物车小红点移到购物车图标的方法, type为true的时候飞到购物车，为false的时候飞到询价车
  function moveRedRot(event, type = true) {
    var e = event || window.event;
    const x = e.clientX;
    const y = e.clientY;
    if (!x) return
    const commonCart = document.querySelector(".common_Cart");
    const common_RFQs1 = document.querySelector(".common_RFQs1");
    const redRot = document.createElement("div");
    redRot.id = type ? "redRot" : 'redRfq';
    redRot.style.position = "fixed";
    redRot.style.width = "20px";
    redRot.style.height = "20px";
    redRot.style.borderRadius = "50%";
    redRot.style.backgroundColor = "red";
    redRot.style.top = y + "px";
    redRot.style.left = x + "px";
    redRot.style.zIndex = "999999999999999999";
  
    var styleStr = `
                  #redRot{
                    animation-name: moveRedRotAnimation;
                    animation-duration: 0.6s;
                  }
                  #redRfq{
                    animation-name: moveRedRotAnimationRfq;
                    animation-duration: 0.6s;
                  }
  
                  @keyframes moveRedRotAnimation {
                    100% {
                      left:${
                        commonCart.getBoundingClientRect().x
                      }px;
                      top: ${
                        commonCart.getBoundingClientRect().y
                      }px;
                    }
                  }
  
                  @keyframes moveRedRotAnimationRfq {
                    100% {
                      left:${
                        common_RFQs1.getBoundingClientRect().x + 15
                      }px;
                      top: ${
                        common_RFQs1.getBoundingClientRect().y + 15
                      }px;
                    }
                  }
              `;
    var style = document.createElement("style");
    style.innerHTML = styleStr;
    redRot.appendChild(style);
    document.body.appendChild(redRot);
    redRot.addEventListener("animationend", function () {
      redRot.parentNode.removeChild(redRot);
      getCartNum();
      getQuoteNum();
    });
  }