
let NAV_MENU_STATUS = false;
let requestApi;

if (window.location.protocol === "file:") {
  // 本地打开 index.html（file://），默认指向本地开发服务
  requestApi = "http://192.168.2.22:8086/api/v1";
} else {
  // 部署到服务器时自动适配
  requestApi = `${window.location.protocol}//${window.location.host}/api/v1`;
}

let kwdValue = new URLSearchParams(window.location.search).get('kwd');
let invitCode = new URLSearchParams(window.location.search).get('code');
if (kwdValue) {
  localStorage.setItem("keyword", kwdValue);
}
if(invitCode){
  localStorage.setItem("invitCode", invitCode);
}
// const $POST_P = async (u, d) => $.post(_payApi + u, { ...d,session: localStorage.getItem("session") || "" });
// const requestApi = `${window.location.protocol}//${window.location.host}`;
const loading = async (v) =>{
    if (typeof v == "undefined" || v) {
     if ($(".lo_loading").length) {
      return;
     }
     var child = $('<div class="lo_loading"><div class="load"></div></div>');
     $(document.body).append(child);
     return;
    }
    $(".lo_loading").remove();
   }
  

const nav_init = async () => {
  if ($(document).scrollTop() > 44) {
    $(".nav_header").addClass("active");
  }
  $(document).on("scroll", function () {
    if ($(document).scrollTop() > 44) {
      $(".nav_header").addClass("active");
    } else {
      $(".nav_header").removeClass("active");
    }
  });

  $('.m-menu-list-main>.m-menu-list-item').on('click', function () {
    
  });
  $(".m-menu-list-main>.m-menu-list-item").click((e) => {
    const DOM = $(e.currentTarget).parent()[0];
    if ($(DOM).hasClass("active")) return $(DOM).removeClass("active");
    $(DOM).addClass("active").siblings(".m-menu-list-main").removeClass("active");
  });

  $('.mobile_menu').on('click',function(){
    $('.header_container>.m-menu-list').show();
  })

  $('.m-menu-list-hesder>img').on('click',function(){
    $('.header_container>.m-menu-list').hide();
  })


  $('.m-menu-list-hesder img, .nav-small-screen .bg').on('click',function(){
      $('.nav-small-screen').removeClass('active');
      $('.nav-small-screen>.bg').fadeOut();
    
  })

  $('.faq-list>div:nth-of-type(1)').on('click',function(e){
    e.stopPropagation();
    $(this).siblings().slideToggle(200);
    $(this).parents(".faq-list").toggleClass("on");
    $(this).parents(".faq-list").siblings().find("div:nth-of-type(2)").slideUp(200);
    $(this).parents(".faq-list").siblings().removeClass("on");
  })


};
$(function () {
  nav_init();
  
});

const messageData = {
  handle: null,
  delayTime: 3000,
  obj: []
 }
 const messageFn= async (v) => {
  clearTimeout(messageData.handle);
  // Clean box
  var removeObj = setTimeout(function () {
   $(".lo_message").removeClass("on");
  }, 0);
 
  var newTime = "lo_" + new Date().getTime();
  var message = $('<div class="lo_message ' + newTime + '"><span>' + v + "</span></div>");
  $(document.body).append(message);
 
  var addObj = setTimeout(function () {
   $("." + newTime).addClass("on");
  }, 2);
 
  messageData.handle = setTimeout(function () {
   $(".lo_message").remove();
  }, messageData.delayTime);
}
