<template>
  <view class="container">
    <!-- 个人信息卡片 -->
    <view class="profile-card">
      <image class="avatar" :src="avatarUrl" mode="aspectFill" />
      <view class="profile-info">
		<view class="phone">{{ nickname }}</view>
        <view class="phone">{{ phone }}</view>
        <view class="profile-link" @click="goToProfile">个人信息 ></view>
      </view>
    </view>

    <!-- 我的学习模块 -->
    <view class="section">
      <view class="section-title">我的学习</view>
      <view class="study-row">
        <view class="study-card" v-for="item in studyList" :key="item.title" @click="goTo(item.path)">
          <image :src="item.icon" class="study-icon" />
          <view class="study-title">{{ item.title }}</view>
        </view>
      </view>
    </view>
    <view class="section list-section">
      <!-- <view class="section-title">商家店铺后台</view> -->
      <view class="menu-list-vertical">
        <view v-for="(item, idx) in menuList" :key="item.title">
          <view class="menu-item-vertical" @click="goTo(item.path)">
            <image :src="item.icon" class="menu-icon-vertical" />
            <view class="menu-title-vertical">{{ item.title }}</view>
            <text class="arrow">›</text>
          </view>
          <view v-if="idx !== menuList.length-1" class="divider"></view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      avatarUrl: '',
      phone: '',
	  nickname:'',
      studyList: [
        { title: '日历', icon: '/static/calender.png', path: '/pages/calendar/index' },
        { title: '我的下载', icon: '/static/xiazai.png', path: '/pages/search/index' },
        { title: '错题本', icon: '/static/cuotiben.png', path: '/pages/search/index' },
        { title: '超级会员', icon: '/static/supperhuiyuan.png', path: '/pages/discover/index' },
        { title: '订阅店铺', icon: '/static/dingyuedianpu.png', path: '/pages/discover/index' },
      ],
      menuList: [
		  // <!-- 商家后台模块 -->
		{ title: '商家店铺后台', icon: '/static/shangjiadianpu.png', path: '/pages/mine/Merchant' },
        { title: '回收站', icon: '/static/huishouzhan.png', path: '/pages/mine/recycle' },
        { title: '通知设置', icon: '/static/tongzhi.png', path: '/pages/mine/notify' },
        { title: '意见反馈', icon: '/static/yijianfankui.png', path: '/pages/mine/feedback' },
        { title: '在线客服', icon: '/static/kefu.png', path: '/pages/mine/service' },
        { title: '了解小鹅通', icon: '/static/liaojie.png', path: '/pages/mine/about' },
        { title: '设置', icon: '/static/shezhi.png', path: '/pages/mine/setting' },
      ]
    }
  },
  onLoad() {
    this.getUid()
  },
  methods: {
    goToProfile() {
      uni.navigateTo({ url: '/pages/mine/profile' })
    },
    goTo(path) {
      uni.navigateTo({ url: path })
    },
    async getUid() {
      // 假设 uid 存在本地缓存（如登录后存储），否则请根据实际情况获取
      try {
        const res = await uni.request({
          url: "http://localhost:9527/api/getUid",
          method: 'GET'
        })
		console.log(res)
        if (res.statusCode === 200) {
			this.nickname=res.data.data.nickname
          this.avatarUrl = res.data.data.avatarUrl
          this.phone = res.data.data.phone
        } else {
          this.avatarUrl = this.defaultAvatar
          this.phone = '获取失败'
        }
      } catch (e) {
        this.avatarUrl = this.defaultAvatar
        this.phone = '网络错误'
      }
    }
  }
}
</script>

<style lang="scss">
.container {
  min-height: 100vh;
  background: #f7f8fa;
  padding-bottom: 120rpx;
  padding-top: 80rpx;
}
.profile-card {
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 20rpx;
  margin: 0 24rpx 24rpx 24rpx;
  padding: 32rpx 24rpx;
  box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.04);
}
.avatar {
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
  margin-right: 32rpx;
  border: 2rpx solid #eee;
}
.profile-info {
  flex: 1;
}
.phone {
  font-size: 36rpx;
  font-weight: bold;
  color: #222;
}
.profile-link {
  color: #409EFF;
  font-size: 28rpx;
  margin-top: 8rpx;
  cursor: pointer;
}
.section {
  margin: 0 24rpx 24rpx 24rpx;
  background: #fff;
  border-radius: 20rpx;
  box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.04);
  padding: 24rpx 0 0 0;
}
.section-title {
  font-size: 30rpx;
  font-weight: 600;
  color: #333;
  margin-left: 32rpx;
  margin-bottom: 16rpx;
}
.study-row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  padding: 0 24rpx 24rpx 24rpx;
}
.study-card {
  flex: 1;
  margin: 0 8rpx;
  background: #f8fafc;
  border-radius: 16rpx;
  box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.03);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24rpx 0 16rpx 0;
  cursor: pointer;
  transition: box-shadow 0.2s;
}
.study-card:active {
  box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.08);
}
.study-icon {
  width: 56rpx;
  height: 56rpx;
  margin-bottom: 8rpx;
}
.study-title {
  font-size: 24rpx;
  color: #555;
}
.list-section {
  padding-bottom: 0;
}
.menu-list-vertical {
  margin: 0 0 0 0;
}
.menu-item-vertical {
  display: flex;
  align-items: center;
  padding: 0 32rpx;
  height: 96rpx;
  background: #fff;
  cursor: pointer;
  position: relative;
}
.menu-icon-vertical {
  width: 40rpx;
  height: 40rpx;
  margin-right: 24rpx;
}
.menu-title-vertical {
  flex: 1;
  font-size: 28rpx;
  color: #333;
}
.arrow {
  color: #bbb;
  font-size: 36rpx;
  margin-left: 8rpx;
}
.divider {
  height: 1rpx;
  background: #f0f0f0;
  margin: 0 32rpx;
}
</style> 