<template>
  <div class="xl:w-screen-xl m-auto py-4 mt-12 px-4 sm:px-0 sm:mt-2">
    <el-page-header :icon="ArrowLeft" @back="goBack">
      <template #content>
        <span class="text-large font-600"> 我的订单 </span>
      </template>
      <div class="login-layout m-auto mt-10 sm:w-screen-xl w-full">
        <div class="m-auto flex sm:flex-row flex-col sm:px-0">
          <div class=" bg-white rounded-lg w-full">
            <div class="flash bg-white rounded-lg px-8 py-4 w-auto">
              <Order :form="form" />
            </div>
          </div>
        </div>
      </div>
    </el-page-header>
  </div>
</template>
<script setup lang="ts">
import { ArrowLeft,View,Search } from '@element-plus/icons-vue'
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 {useServerRequest} from "~/composables/useServerRequest";
import type {ApiResult} from "~/api";
import UserMenu from "./components/UserMenu.vue";
import Order from './components/Order.vue';

// 配置信息
const runtimeConfig = useRuntimeConfig();
const route = useRoute();
const router = useRouter();
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
});

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

useHead({
  title: `用户中心 - ${config.value?.siteName}`
});

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 token = localStorage.getItem('token');
  if (!token || token == '') {
    navigateTo('/passport/login');
    return false;
  }
  // const {data: response} = await useServerRequest<ApiResult<Order>>('/system/order',{baseURL: runtimeConfig.public.apiServer})
  // if(response.value?.data){
  //   console.log(response.value,'order')
  //   // userInfo.value = response.value?.data;
  //   // assignFields(response.value?.data);
  // }
}

const goBack = () => {
  router.back(); // 返回上一页
}

watch(
    () => route.path,
    (path) => {
      activeIndex.value = path;
      reload();
    },
    { immediate: true }
);
</script>
