<script setup lang="ts" >
import {setting} from "../setting/setting.vue";
import {orderDateils} from "../orderDetaiols.vue"
import { ref } from 'vue';
import { onShow } from "@dcloudio/uni-app";
import {apiImageUrl} from '../../API/api'
	onShow(()=>{
		getLoginUser()
	})
	const user = ref({
		userAvatar:'',
		userName:'',
		message:''
	})
	const getLoginUser = () => {
		uni.request({
			url:apiImageUrl+'/api/user/current',
			method:'GET',
			header:{ 
				'cookie': uni.getStorageSync("cookie")
			}, 
			 data:{},
			success: (res) => {	
				console.log(res.data.message)//控制台在登录时返回ok未登录时返回”未登录“
				user.value.message=res.data.message
				if(user.value.message==='ok')
				{
					user.value.userName=res.data.data.username
					user.value.userAvatar = res.data.data.avatarUrl
				}
				
				
				console.log(res)
				console.log("我的获取当前登录信息");
			},
			fail() {
				console.log('出错啦');
			}
			
		})
	}
//复制账号
/* const textToCopy = ref('1220920124');
const copyText = async () => {
  try {
    // 设置剪贴板的内容
    await uni.setClipboardData({
      data: textToCopy.value,
      success: () => {
        uni.showToast({
          title: '复制成功',
          icon: 'success',
          duration: 2000
        });
      },
      fail: (err) => {
        uni.showToast({
          title: '复制失败',
          icon: 'none',
          duration: 2000
        });
      }
    });
  } catch (error) {
    console.error('复制失败:', error);
    uni.showToast({
      title: '复制失败',
      icon: 'none',
      duration: 2000
    });
  }
}; */

</script>

<template>
  <scroll-view class="viewport" scroll-y enable-back-to-top>

    <view class="profile">
    
      <view class="overview" v-if="user.message==='ok'">
        <navigator hover-class="none">
          <image
            class="avatar"
            mode="aspectFill"
            :src="user.userAvatar"
          ></image>
        </navigator>
        <view class="meta">
          <view class="nickname"> {{user.userName}} </view>
        
        </view>
      </view>
     
      <view class="overview" v-else>
        <navigator hover-class="none">
          <image
            class="avatar gray"
            mode="aspectFill"
            src="http://39.101.78.35/images/user_avatar/0/LbLTxpMf-image.png"
          ></image>
        </navigator>
        <view class="meta">
          <navigator hover-class="none" class="nickname">
            未登录
          </navigator>
        </view>
      </view>
    </view>
  </scroll-view>
  <orderDateils></orderDateils>
  <setting></setting>
</template>

<style lang="scss">
page {
  height: 100%;
  overflow: hidden;
  background-color: #4095e5;
}


.profile {
	padding-top: 30rpx;
  position: relative;
  .overview {
    display: flex;
    height: 130rpx;
    padding: 0 36rpx;
    color: #fff;
  }
  .avatar {
    width: 120rpx;
    height: 120rpx;
    border-radius: 50%;
    background-color: #eee;
  }

  .gray {
    filter: grayscale(100%);
  }

  .meta {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    line-height: 30rpx;
    padding: 16rpx 0;
    margin-left: 20rpx;
  }

  .nickname {
    max-width: 350rpx;
    margin-bottom: 16rpx;
    font-size: 30rpx;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
	color: #000;
  }
  .SchoolCard {
	  width: 155px;
	  height: 23px;
  }

  .extra {
	display: float;
  }

  .tips {
	float: left;
	padding: 3px 5px 3px 5px;
    font-size: 22rpx;
	color: #000;
	background-color: #fff;
	border: 1px solid #000;
	border-radius: 14px;
  }
  .copy {
	  float: right;
	  line-height: 23px;
	  color: #000;
	  font-size: 13px;
	  text-decoration: underline;
  }
  .update {
    padding: 3rpx 10rpx 1rpx;
    color: rgba(255, 255, 255, 0.8);
    border: 1rpx solid rgba(255, 255, 255, 0.8);
    margin-right: 10rpx;
    border-radius: 30rpx;
  }
}


</style>