import { defineStore } from "pinia";
export const useUserStore = defineStore("user", {
  state: () => ({
    userInfo: null,
    authToken: "",
    // 判断当前用户是不是投管部角色用户
    isTgbu: false,
    // 判断是否是项目填报角色
    isXmtb: false,
  }),
  actions: {
    setUseInfo(data) {
      this.userInfo = data;
      this.authToken = data.token;

      this.isTgbu = data.departs.some(
        (recoed) => recoed.parentIds?.includes("41") || recoed.id == "41",
      );
      this.isXmtb = data.roles.some((record) =>
        record.key?.includes("company_dep"),
      );
      console.log("this.isXmtb", this.isXmtb);
      console.log("this.isTgbu", this.isTgbu);
      sessionStorage.setItem("authToken", data.token);
      sessionStorage.setItem("userInfo", JSON.stringify(data));
    },
    clearUserInfo() {
      this.userInfo = null;
      this.authToken = "";
      sessionStorage.removeItem("authToken");
      sessionStorage.removeItem("userInfo");
    },
  },
});
