<template>
  <div>
    <n-drawer v-model:show="showModal" :width="dialogWidth">
      <n-drawer-content title="前台用户表详情" closable>
        <n-spin :show="loading" description="请稍候...">
          <n-descriptions label-placement="left" class="py-2" :column="1">
            <n-descriptions-item>
              <template #label>
                手机号
              </template>
              {{ formValue.phone }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                昵称
              </template>
              {{ formValue.nickname }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                邮箱
              </template>
              {{ formValue.email }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                头像URL
              </template>
              <n-image style="margin-left: 10px; height: 100px; width: 100px" :src="formValue.avatar"/>
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                个人简介
              </template>
              <span v-html="formValue.introduce"></span>
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                真实姓名
              </template>
              {{ formValue.realname }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                性别
              </template>
              {{ formValue.gender }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                生日
              </template>
              {{ formValue.birthday }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                学校
              </template>
              {{ formValue.school }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                学历
              </template>
              {{ formValue.grade }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                专业
              </template>
              {{ formValue.major }}
            </n-descriptions-item>
            <n-descriptions-item label="用户状态">
              <n-tag :type="dict.getType('sys_normal_disable', formValue.status)" size="small" class="min-left-space">
                {{ dict.getLabel('sys_normal_disable', formValue.status) }}
              </n-tag>
            </n-descriptions-item>
          </n-descriptions>
        </n-spin>
      </n-drawer-content>
    </n-drawer>
  </div>
</template>

<script lang="ts" setup>
  import { computed, ref } from 'vue';
  import { useMessage } from 'naive-ui';
  import { View } from '@/api/users';
  import { State, newState } from './model';
  import { adaModalWidth } from '@/utils/hotgo';
  import { getFileExt } from '@/utils/urlUtils';
  import { useDictStore } from '@/store/modules/dict';

  const message = useMessage();
  const dict = useDictStore();
  const loading = ref(false);
  const showModal = ref(false);
  const formValue = ref(newState(null));
  const dialogWidth = computed(() => {
    return adaModalWidth(580);
  });
  const fileAvatarCSS = computed(() => {
    return {
      '--n-merged-size': `var(--n-avatar-size-override, 80px)`,
      '--n-font-size': `18px`,
    };
  });

  // 下载
  function download(url: string) {
    window.open(url);
  }

  // 打开模态框
  function openModal(state: State) {
    showModal.value = true;
    loading.value = true;
    View({ id: state.id })
      .then((res) => {
        formValue.value = res;
      })
      .finally(() => {
        loading.value = false;
      });
  }

  defineExpose({
    openModal,
  });
</script>

<style lang="less" scoped></style>