<template>
  <div class="header-top">
    <div class="title">
      {{ title }}
        <div class="edit">编辑</div>
    </div>
    <div class="oper-btns">
      <el-button style="padding: 5px 10px" type="primary" @click="handlemtk">媒体库</el-button>
      <el-button style="padding: 5px 10px" type="primary" @click="handleSee">预览案件</el-button>
    </div>
    <!-- <div class="oper-btns" v-if="user.info">
      <div class="user-menu">
        <img :src="user.info.avatar ? user.info.avatar : defAvatar" />
        <el-dropdown>
          <div style="outline: none">
            <span class="oper-down">{{ user.info.nickName }}</span>
            <el-icon><ArrowDown /></el-icon>
          </div>
          <template v-slot:dropdown>
            <el-dropdown-menu class="menu-items-user">
              <el-dropdown-item @click="updatePwdHandler">修改密码</el-dropdown-item>
              <el-dropdown-item @click="logout"
                ><span style="color: #fa5555">退出登录</span></el-dropdown-item
              >
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div> -->
  </div>
</template>
<script lang="ts" setup>
import { openErrorMsg } from "@/request";
import { user, logout as logoutRaw } from "@/store/user";
import defAvatar from "@/assets/image/top_my.png";
import { getCaseInfo } from "@/store/case";
import { refreshRole, roleId } from "@/store/role";
import { RouteName, router } from "@/router";
import { confirm } from "@/helper/message";
import { updatePwd } from "@/view/system/quisk";
import { computed, ref, watch } from "vue";
import { addCaseScenes } from "@/view/originalPhoto/quisk";

refreshRole();
const caseId = computed(() => {
  const caseId = router.currentRoute.value.params.caseId;
  if (caseId) {
    return Number(caseId);
  }
});
const title = ref('')
const getInfo = async () => {
  const res = await getCaseInfo(caseId.value);
  console.log('getInfo', res)
  title.value = res?.caseTitle || "";
};
getInfo();
watch(() => caseId.value, () => {
    getInfo();
})
const loginoutRaw = async () => {
  await logoutRaw();
  roleId.value = "";
  router.replace({ name: RouteName.login });
};
const handlemtk = () => {
  window.open("/#/mediaLibrary/index");
};
const handleSee = () => {
  window.open(`/code/index.html?caseId=${caseId.value}#/show`);
};
const logout = async () => {
  if (await confirm("确定要退出登录吗？")) {
    loginoutRaw();
  }
};
const updatePwdHandler = async () => {
  if (await updatePwd({})) {
    openErrorMsg("密码修改成功，请重新登录。");
    loginoutRaw();
  }
};
</script>

<style lang="scss" scoped>
@import "./style.scss";
</style>
