<script setup lang="ts">
import Panel from "@/components/common/Panel.vue";
import {post} from "@/utils/request.ts";
import {onMounted, ref, defineModel} from "vue";
import {formatDate} from "@/utils/dateUtils.ts";
import {loadConfig} from "@/utils/config.ts";
import {API} from "@/assets/config/API.ts";

const decryptedText = ref<any>({})
const ciphertext = ref<any>('')
const list = ref<any>([])
const init = async () => {
  ciphertext.value = await post(API.Common.Auth.Get);
  decryptedText.value = await post(API.Common.Auth.Check);
  list.value = await post(API.Common.Config.List)
  list.value.forEach((item: any) => {
    if (item.k != "logoUrl") return
    loadConfig().then((res: any) => {
      imageUrl.value = res.base_url + API.Common.File.GetImage + '/' + item.val
    })
  })
}
onMounted(async () => {
  await init()
})
const userMessage = defineModel<any>()
const imageUrl = ref<any>()
</script>

<template>
  <Panel title="药房基本信息" class="info">
    <div class="info-content">
      <img class="image" :src="imageUrl? imageUrl:userMessage.logo" alt="app">
      <div class="app_info-content-text">
        <div class="app_info-title">{{ userMessage.name }}</div>
        <div>软件版本：{{ userMessage.version }}</div>
        <div style="margin: 10px 0">授权到期：{{ formatDate(decryptedText.expiryDate) }}</div>
        <div>版本类型：{{ decryptedText.rule == 1 ? "禁用医保" : decryptedText.rule == 2 ? "全部开放" : "暂无" }}</div>
      </div>
    </div>
  </Panel>
</template>

<style scoped lang="scss">
.info {
  height: 208px;

  .info-content {
    width: 100%;
    display: flex;
    padding-left: 24px;

    .image {
      width: 88px;
      height: 88px;
      margin-right: 24px;
    }

    .app_info-content-text {
      flex: 1;
      min-width: 0;
      font-weight: 500;
      font-size: 16px;
      color: #333333;
      font-style: normal;

      .app_info-title {
        max-width: 220px;
        font-weight: bold;
        font-size: 20px;
        margin-bottom: 20px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }
}
</style>