<template>
    <AppLayout title="我的" back-gorund-color="#F4F4F4">
        <!-- 自定义tabbar -->
        <CustomTabBar :currentPage="4" />
        
        <!-- 企业信息卡片 -->
        <view class="company-info-card btn-feel" @click="goToCompanyInfo">
            <view class="company-avatar">
                <image class="company-avatar-img" :src="companyInfo.avatar || '/static/icon/company-default.png'"></image>
            </view>
            <view class="company-details">
                <view class="company-name">{{ companyInfo.name || '科里喀什分公司' }}</view>
                <view class="company-completeness">信息完整度 {{ companyInfo.completeness || '100%' }}</view>
            </view>
            <view class="company-arrow">
                <uni-icons color="#A2A2A2" type="right" size="16"></uni-icons>
            </view>
        </view>

        <!-- 服务专区 -->
        <view class="service-zone-card">
            <view class="service-title">服务专区</view>
            <view class="service-item btn-feel">
                <view class="service-left">
                    <image class="service-icon" src="/static/icon/real-name-auth.png"></image>
                    <text class="service-text">实名认证</text>
                </view>
                <view class="service-status">已通过</view>
            </view>
            <view class="service-item btn-feel">
                <view class="service-left">
                    <image class="service-icon" src="/static/icon/notification.png"></image>
                    <text class="service-text">通知与提醒</text>
                </view>
                <view class="service-status">已开启</view>
            </view>
        </view>

        <!-- 退出登录按钮 -->
        <view class="logout-btn btn-feel" @click="logOut">
            退出登录
        </view>

        <!-- 退出确认弹窗 -->
        <uni-popup ref="popup" type="dialog">
            <uni-popup-dialog
                mode="base"
                title="确定退出登录吗？"
                type="info"
                :duration="2000"
                :before-close="true"
                @confirm="confirm"
                @close="close"
            ></uni-popup-dialog>
        </uni-popup>
    </AppLayout>
</template>

<script setup>
import { reactive, inject, ref, onMounted } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';

const { $api, navTo } = inject('globalFunction');
const popup = ref(null);

// 企业信息数据
const companyInfo = reactive({
    name: '科里喀什分公司',
    avatar: '/static/icon/company-avatar.png',
    completeness: '100%'
});

function goToCompanyInfo() {
    navTo('/pages/mine/company-info');
}

function logOut() {
    popup.value.open();
}

function close() {
    popup.value.close();
}

function confirm() {
    // 这里可以调用退出登录的API
    console.log('退出登录');
    // 跳转到登录页面或首页
    uni.reLaunch({
        url: '/pages/index/index'
    });
}

onShow(() => {
    // 获取企业信息
    getCompanyInfo();
});

function getCompanyInfo() {
    // 这里可以调用API获取企业信息
    // $api.createRequest('/app/company/info').then((resData) => {
    //     Object.assign(companyInfo, resData.data);
    // });
}
</script>

<style lang="stylus" scoped>
.company-info-card {
    display: flex;
    align-items: center;
    padding: 30rpx;
    background: #FFFFFF;
    margin: 20rpx;
    border-radius: 20rpx;
    box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
    
    .company-avatar {
        width: 100rpx;
        height: 100rpx;
        border-radius: 50%;
        overflow: hidden;
        margin-right: 24rpx;
        
        .company-avatar-img {
            width: 100%;
            height: 100%;
        }
    }
    
    .company-details {
        flex: 1;
        
        .company-name {
            font-size: 36rpx;
            font-weight: 600;
            color: #333333;
            margin-bottom: 8rpx;
        }
        
        .company-completeness {
            font-size: 28rpx;
            color: #6C7282;
        }
    }
    
    .company-arrow {
        margin-left: 20rpx;
    }
}

.service-zone-card {
    background: #FFFFFF;
    margin: 0 20rpx 20rpx;
    border-radius: 20rpx;
    box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
    padding: 32rpx;
    
    .service-title {
        font-size: 32rpx;
        font-weight: 600;
        color: #000000;
        margin-bottom: 32rpx;
    }
    
    .service-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 24rpx 0;
        border-bottom: 1rpx solid #F5F5F5;
        
        &:last-child {
            border-bottom: none;
        }
        
        .service-left {
            display: flex;
            align-items: center;
            
            .service-icon {
                width: 44rpx;
                height: 44rpx;
                margin-right: 16rpx;
            }
            
            .service-text {
                font-size: 28rpx;
                color: #333333;
            }
        }
        
        .service-status {
            font-size: 28rpx;
            color: #6E6E6E;
        }
    }
}

.logout-btn {
    height: 96rpx;
    background: #FFFFFF;
    margin: 0 20rpx 40rpx;
    border-radius: 20rpx;
    text-align: center;
    line-height: 96rpx;
    font-size: 28rpx;
    color: #256BFA;
    box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
}

.btn-feel {
    transition: transform 0.2s ease;
    
    &:active {
        transform: scale(0.98);
    }
}
</style>
