<template>
  <div class="trial-myinfo">
    <el-menu
      :default-active="activeIndex"
      @select="handleSelect"
      class="el-menu-demo"
      style="width: 200px"
    >
      <el-menu-item index="1">{{
        $t("trials:trials-myinfo:menuTitle:mine")
      }}</el-menu-item>
      <el-menu-item index="2">{{
        $t("trials:trials-myinfo:menuTitle:account")
      }}</el-menu-item>
      <el-menu-item index="3">{{
        $t("trials:trials-myinfo:menuTitle:loginLog")
      }}</el-menu-item>
    </el-menu>
    <div class="contentBox">
      <mine
        :user="user"
        :userTypeOptions="userTypeOptions"
        v-if="activeIndex === '1'"
        @getUserInfo="getUserInfo"
      />
      <account
        :user="user"
        @getUserInfo="getUserInfo"
        :IsCanConnectInternet="IsCanConnectInternet"
        v-if="activeIndex === '2'"
      />
      <login-log v-if="activeIndex === '3'" :id="userId" :isMine="true" />
    </div>
  </div>
</template>

<script>
import mine from "./mine.vue";
import account from "./account.vue";
import loginLog from "@/views/trials/trials-panel/trial-summary/login-log";
import { getUserTypeList, getUser } from "@/api/admin.js";
import { getHospital } from "@/api/hospital.js";
import store from "@/store";
import { mapGetters } from "vuex";

export default {
  name: "TrialsMyinfo",
  components: { mine, account, "login-log": loginLog },
  data() {
    return {
      activeIndex: "1",

      userTypeOptions: [],
      user: {},
      IsCanConnectInternet: true, // 是否可以链接互联网
    };
  },
  computed: {
    ...mapGetters(["userId", "userName"]),
  },
  mounted() {
    this.getUserInfo();
    this.getUserTypeList();
    this.getInfo();
  },
  methods: {
    // 获取医院信息
    async getInfo() {
      try {
        let res = await getHospital();
        if (res.IsSuccess) {
          this.IsCanConnectInternet = res.Result.IsCanConnectInternet;
        }
      } catch (err) {
        console.log(err);
      }
    },
    handleSelect(index) {
      this.activeIndex = index;
    },
    getUserInfo() {
      const loading = this.$loading({
        fullscreen: false,
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.07)",
      });
      getUser(this.userId)
        .then(async (res) => {
          this.user = res.Result;
          /* eslint-disable */
          zzSessionStorage.setItem("realName", this.user.RealName);
          await store.dispatch("user/updateInfo");
          loading.close();
        })
        .catch(() => {
          loading.close();
        });
    },
    getUserTypeList() {
      getUserTypeList().then((res) => {
        if (res.IsSuccess) {
          this.userTypeOptions = res.Result;
        }
      });
    },
  },
};
</script>

<style lang="scss">
.trial-myinfo {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  .contentBox {
    width: calc(100% - 220px);
    background-color: #fff;
    padding: 0 20px;
    height: 100%;
    overflow: auto;
    // padding-bottom: 50px;
  }
  .trial-myinfo-head {
    position: absolute;
    top: 40px;
    left: 20px;
    font-size: 14px;
  }
  .trial-myinfo-left {
    overflow: auto;
    background: #fff;
    // width: calc(50% - 9px);
    // margin: 6px 0;
    height: 100%;
    // padding-bottom: 50px;
    .trial-myinfo-left-top {
      width: 70%;
      padding-top: 100px;
      position: relative;
      // margin: 0 auto;
      margin-bottom: 10px;
      .trial-myinfo-body {
        width: 160px;
        height: 160px;
        border-radius: 50%;
        background: #428bca;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-left: 30px;
        div {
          color: #fff;
          font-size: 30px;
        }
      }
    }
  }
  .saveBtn {
    position: absolute;
    right: -10px;
    top: 2px;
    transform: translateX(100%);
  }
  .trial-info-btn {
    position: absolute;
    bottom: -60px;
    left: 10px;
    min-width: 97px;
  }
  .trial-myinfo-left-bottom {
    width: 40%;
    padding-top: 100px;
    position: relative;
    // margin: 0 auto;
  }
  .trial-myinfo-right {
    overflow: auto;
    background: #fff;
    // width: calc(50% - 9px);
    // margin: 6px 0;
    height: 100%;
    .sendCode {
      position: absolute;
      right: -10px;
      top: 50%;
      transform: translate(100%, -50%);
    }
    .trial-myinfo-right-box {
      width: 40%;
      padding-top: 100px;
      position: relative;
      // margin: 0 auto;
    }
  }
}
</style>
