<template>
  <view class="wh-full">
    <BasicLoading
      :isShow="isShow"
      bgColor="#fff"
      isShowTitle
      textColor="#000"
      title="启动中..."
      :type="1"
    />
  </view>
</template>

<script lang="ts" setup>
import { onLoad } from "@dcloudio/uni-app";
import { useDataStore } from "@/store/modules/data";
import { useUserStore } from "@/store/modules/user";
import { checkOpenId, findJsByPhoneApi } from "@/api/system/login";

const { setGlobal } = useDataStore();
const { afterLoginAction } = useUserStore();
const { setFile, getFile } = useDataStore();
const isShow = ref(true);

function goByJs(js: any) {
	console.log(js);
  // if (js.jsType == "助教") {
  //   uni.reLaunch({
  //     url: "/pages/base/groupTeaching/zhujiao",
  //   });
  // } else {
		if (js.confirmStatus == "A") {
			uni.switchTab({
				url: "/pages/base/message/index",
			});
		} else {
			setFile({
			  ...js,
			  ...getFile,
			});
			setTimeout(() => {
			  uni.reLaunch({
			    url: "/pages/view/hr/teacherProfile/index",
			  });
			}, 1500);
		}
  // }
}
onLoad(async (data: any) => {
  if (data && data.openId) {
    setGlobal(data);
    checkOpenId({
      openId: data.openId,
      appCode: "JS",
    })
      .then(async (res: any) => {
        if (res.resultCode == 1) {
          if (res.result) {
            afterLoginAction(res.result);
						// 跳转页面
						goByJs(res.result.js)
            return;
          }
        }
        uni.reLaunch({
          url: "/pages/system/login/login",
        });
      })
      .catch((err) => {
        uni.reLaunch({
          url: "/pages/system/login/login"
        })
      });
  } else {
	  uni.reLaunch({
		  url: "/pages/system/login/login"
	  })
  }
});
</script>
