<template>
  <div class="login-layout mt-[100px] m-auto sm:w-screen-xl w-full">
    <div class="mt-[100px] m-auto flex sm:flex-row flex-col sm:p-0 p-3">
      <el-card shadow="hover" class="sm:w-[250px] sm:flex sm:mb-0 mb-5 justify-center w-full">
        <div class="flex justify-center pb-4 flex-col justify-center items-center">
          <el-avatar :src="userInfo?.avatar" :size="70" />
          <text class="text-gray-400 py-1 text-sm">更换头像</text>
        </div>
        <!-- 用户菜单 -->
        <UserMenu :activeIndex="activeIndex" />
      </el-card>
      <el-card shadow="hover" class="flash bg-white hover:shadow w-full sm:ml-6 ml-0">
        <template #header>订单列表</template>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="date" label="下单日期" width="180" />
          <el-table-column prop="name" label="产品名称" width="180" />
          <el-table-column prop="address" label="订单信息" />
        </el-table>
      </el-card>
    </div>
  </div>
</template>
<script setup lang="ts">
import {useConfigInfo, useToken, useWebsite} from "~/composables/configState";
import useFormData from '@/utils/use-form-data';
import type { User } from '@/api/system/user/model';
import { ref } from 'vue'
import {getCaptcha} from "~/api/passport/login";
import {useServerRequest} from "~/composables/useServerRequest";
import type {ApiResult} from "~/api";
import type {Website} from "~/api/cms/website/model";
import type {CaptchaResult, LoginResult} from "~/api/passport/login/model";
import {getPath, navigateTo} from "#imports";
import UserMenu from "~/components/UserMenu.vue";

// 配置信息
const runtimeConfig = useRuntimeConfig();
const route = useRoute();
const website = useWebsite()
const config = useConfigInfo();
const token = useToken();
const userInfo = ref<User>();
const activeIndex = ref('');

// 配置信息
const { form, assignFields } = useFormData<User>({
  userId: undefined,
  nickname: '',
  username: '',
  phone: '',
  mobile: '',
  sex: '',
  sexName: '',
  email: '',
  password: '',
  code: '',
  smsCode: '',
  comments: '',
  remember: true,
  isAdmin: true
});

const tableData = ref<any[]>();

useHead({
  title: `用户中心 - ${config.value?.siteName}`,
  meta: [{ name: website.value.keywords, content: website.value.comments }]
});

const onSubmit = async () => {
  const {data: modify } = await useServerRequest<ApiResult<User>>('/auth/user',{
    baseURL: runtimeConfig.public.apiServer,
    method: 'put',
    body: form
  })
  if(modify.value?.code == 0){
    ElMessage.success('修改成功')
  }
}

const reload = async () => {
  const {data: response} = await useServerRequest<ApiResult<User>>('/auth/user',{baseURL: runtimeConfig.public.apiServer})
  if(response.value?.data){
    userInfo.value = response.value?.data;
    assignFields(response.value?.data);
  }
}

watch(
    () => route.path,
    (path) => {
      activeIndex.value = path;
      console.log(path,'=>Path')
      reload();
    },
    { immediate: true }
);
</script>
<style lang="less">
body{
  background: url("https://oss.wsdns.cn/20240328/797a8e323bba4fc6827abf9d8b98ba45.png");
  background-size: 100%;
}
</style>
