// 科技人物
import router from "@/router/index";
import { getPersonSummaryInfo } from "@/api/common/index";
// 跳转人物详情
export const goToCharacterPage = async (id, tabName) => {
  window.sessionStorage.setItem('curTabName', tabName)
  const personTypeList = JSON.parse(window.sessionStorage.getItem("personTypeList"));
  let type
  let personTypeName
  const params = {
    personId: id
  }
  const param1 = {
    personId: item.id
  }
  const jsonStr1 = JSON.stringify(param1);
  const base64_1 = btoa(encodeURIComponent(jsonStr1));

  const param2 = {
    personId: item.id
  }
  const jsonStr2 = JSON.stringify(param2);
  const base64_2 = btoa(encodeURIComponent(jsonStr2));

  // 先获取人物全局信息
  try {
    const res = await getPersonSummaryInfo(params)
    if (res.code === 200 && res.data) {
      const arr = personTypeList.filter(item => {
        return item.typeId === res.data.personType;
      })
      if (arr && arr.length) {
        personTypeName = arr[0].typeName;
        if (personTypeName === "科技企业领袖") {
          type = 1;
        } else if (personTypeName === "国会议员") {
          type = 2;
        } else if (personTypeName === "智库研究人员") {
          type = 3;
        } else {
          personTypeName = "其他类型";
          const route = router.resolve({
            path: "/characterPage",
            query: {
              data: base64_1
            }
          });
          window.open(route.href, "_blank");
          return;
        }
        const route = router.resolve({
          path: "/characterPage",
          query: {
            data: base64_2
          }
        });
        window.open(route.href, "_blank");
      } else {
        personTypeName = "";
        const route = router.resolve({
          path: "/characterPage",
          query: {
            data: base64_1
          }
        });
        window.open(route.href, "_blank");
        return;
      }
    } else {
      const route = router.resolve({
        path: "/characterPage",
        query: {
          data: base64_1
        }
      });
      window.open(route.href, "_blank");
      return;
    }
  } catch (error) {
    const route = router.resolve({
      path: "/characterPage",
      query: {
        data: base64_1
      }
    });
    window.open(route.href, "_blank");
    return;
  }
}
