<template>
  <view class=" mine-container" :style="{height: `${windowHeight}px`}">
    <!--顶部个人信息栏-->
    <view class=" header-section">
      <view class=" flex padding justify-between uni-row">
        <view class=" flex align-center uni-row">
          <view v-if="avatar==null" class="cu-avatar xl round bg-white">
            <view class="text-gray icon"></view>
          </view>
          <image v-if="avatar" @click="handleToAvatar" :src="avatar" class="cu-avatar xl round" mode="widthFix">
          </image>
          <view v-if="name == null" @click="handleToLogin" class=" login-tip">
            点击登录
          </view>
          <view v-if="name" @click="handleToInfo" class=" user-info">
            <view class=" u_title">
              用户名：{{ name }}
            </view>
          </view>
        </view>
        <view @click="handleToInfo" class=" flex align-center uni-row">
          <text>个人信息</text>
          <view class=""></view>
        </view>
      </view>
    </view>

    <view class=" content-section">
      <view class=" mine-actions grid col-4  uni-row">
        
      </view>

      <view class=" menu-list">
        <view class=" list-cell list-cell-arrow" @click="handleToEditInfo">
          <view class=" menu-item-box uni-row">
            <view class=" menu-icon"></view>
            <view class="font-14">编辑资料</view>
          </view>
        </view>
        <view class=" list-cell list-cell-arrow" @click="handleHelp">
          <view class=" menu-item-box uni-row">
            <view class="menu-icon"></view>
            <view class="font-14">常见问题</view>
          </view>
        </view>
        <view class=" list-cell list-cell-arrow" @click="handleAbout">
          <view class=" menu-item-box uni-row">
            <view class=" menu-icon"></view>
            <view class="font-14">关于我们</view>
          </view>
        </view>
        <view class=" list-cell list-cell-arrow" @click="handleToSetting">
          <view class=" menu-item-box uni-row">
            <view class="menu-icon"></view>
            <view class="font-14">应用设置</view>
          </view>
        </view>
      </view>

    </view>
  </view>
</template>

<script lang="uts">  
  import {state,LogOut} from '@/store'
  export default {
    data() {
		const globalData = getApp().globalData
		const config = globalData.config != null ? globalData.config as UTSJSONObject : null;
		const appInfo:UTSJSONObject|null = config?.get('appInfo') as UTSJSONObject;
      return {
        name: state.name as string,
        version: appInfo?.get('version') as string | ''
      }
    },
    computed: {
      avatar() {
        return state.avatar as string
      },
      windowHeight() {
        return (uni.getSystemInfoSync().windowHeight - 50 ) as number
      }
    },
    methods: {
      handleToInfo() {
        uni.navigateTo({
          url: '/pages/mine/info/index'
        });
      },
      handleToEditInfo() {
        uni.navigateTo({
          url: '/pages/mine/info/edit'
        });
      },
      handleToSetting() {
        uni.navigateTo({
          url: '/pages/mine/setting/index'
        });
      },
      handleToLogin() {
        uni.reLaunch({
          url: '/pages/login'
        });
      },
      handleToAvatar() {
		// 上传头像待优化
        // uni.navigateTo({
        //   url: '/pages/mine/avatar/index'
        // });
		uni.showToast({
		  title: '模块建设中~',
		  icon: 'none'
		});
      },
      handleLogout() {
        uni.showModal({
          title: '提示',
          content: '确定注销并退出系统吗？',
          success: (res) => {
            if (res.confirm) {
              LogOut().then(() => {
                uni.reLaunch({
                  url: '/pages/index'
                });
              });
            }
          }
        });
      },
      handleHelp() {
        uni.navigateTo({
          url: '/pages/mine/help/index'
        });
      },
      handleAbout() {
        uni.navigateTo({
          url: '/pages/mine/about/index'
        });
      },
      handleJiaoLiuQun() {
        uni.showToast({
          title: 'QQ群：①133713780、②146013835',
          icon: 'none'
        });
      },
      handleBuilding() {
        uni.showToast({
          title: '模块建设中~',
          icon: 'none'
        });
      }
    }
  }
</script>

<style lang="scss">
  .my-page {
    background-color: #f5f6f7;
	width: 100%;
	height: 100%;
  }

  .mine-container {
    width: 100%;
    height: 100%;


    .header-section {
      padding: 15px 15px 45px 15px;
      background-color: #3c96f3;
      color: white;

      .login-tip {
        font-size: 18px;
        margin-left: 10px;
      }

      .cu-avatar {
        border: 2px solid #eaeaea;

        .icon {
          font-size: 40px;
        }
      }

      .user-info {
        margin-left: 15px;

        .u_title {
          font-size: 18px;
          line-height: 30px;
        }
      }
    }

    .content-section {
      position: relative;
      top: -50px;

      .mine-actions {
        margin: 15px 15px;
        padding: 20px 0px;
        border-radius: 8px;
        background-color: white;

        .action-item {
          .icon {
            font-size: 28px;
          }

          .text {
            font-size: 13px;
            margin: 8px 0px;
          }
        }
      }
    }
  }
</style>
