<template>
  <div class="apply-page">
    <!-- 导航栏 -->
    <div class="nav-header">
      <div class="back-btn" @click="goBack">
        <span class="back-icon">←</span>
      </div>
      <div class="nav-title">党员申请</div>
    </div>

    <!-- 主体内容 -->
    <div class="page-content">
      <div class="apply-container">
        <div class="apply-card">
          <div class="card-header">
            <h2 class="apply-title">党员招募</h2>
            <div class="title-divider"></div>
          </div>
          
          <div class="card-body">
            <div class="apply-description">
              国家平台总部招募党员团队主管，团队总人数达到100人即可成为党员主管，每月可享受60000元党员团队奖励金直接到账银行卡。加入中国共产党那一刻起，都必须无一例外地履行党员义务！
            </div>
            
            <button class="apply-button" @click="applyDan">我要参党</button>
          </div>
        </div>
      </div>
    </div>

    <!-- 实名认证弹窗 -->
    <div v-if="showAuthDialog" class="dialog-overlay">
      <div class="gov-dialog auth-dialog">
        <div class="dialog-header">
          <h3 class="dialog-title">系统提醒</h3>
          <div class="close-btn" @click="showAuthDialog = false">
            <span class="close-icon">×</span>
          </div>
        </div>
        <div class="dialog-body">
          <div class="warning-icon">⚠️</div>
          <div class="dialog-content">
            <p>您还未完成实名认证</p>
            <p>请先进行实名认证后再申请</p>
          </div>
          <button class="gov-btn primary" @click="goToAuth">立即认证</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {applyDangyuan} from '@/api/home.js'
import { getUserInfo } from '@/api/home'
import { Toast } from 'vant';

export default {
  name: 'InvitePeople',
  data() {
    return {
      cards: [
        {
          title: '初级退休补贴金',
          rate: '10%',
          amount: '3000元',
          count: '1份'
        },
        {
          title: '一级退休补贴金',
          rate: '10%',
          amount: '6000元',
          count: '1份'
        },
        {
          title: '二级退休补贴金',
          rate: '10%',
          amount: '10000元',
          count: '1份'
        },
        {
          title: '三级退休补贴金',
          rate: '10%',
          amount: '20000元',
          count: '1份'
        }
      ],
      userInfo: {},
      showAuthDialog: false
    }
  },
  methods:{
    goBack() {
      this.$router.go(-1)
    },
    async getUserInfo() {
      try {
        const res = await getUserInfo();
        this.userInfo = res.data;
      } catch (error) {
        console.error('获取用户信息失败:', error);
      }
    },
    async applyDan() {
      // 检查实名认证状态
      if (this.userInfo.if_real === 0) {
        this.showAuthDialog = true;
        return;
      }
      
      const res = await applyDangyuan();
      if(res.cooe === 1){
        Toast.success('申请成功');
      }
    },
    goToAuth() {
      this.showAuthDialog = false;
      this.$router.push('/user-center');
    }
  },
  created() {
    this.getUserInfo();
  }
}
</script>

<style lang="scss" scoped>
.apply-page {
  min-height: 100vh;
  background: linear-gradient(to bottom, #2f9580 0%, #4fb3a1 100%);
  display: flex;
  flex-direction: column;
}

.nav-header {
  height: 56px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  
  .back-btn {
    position: absolute;
    left: 16px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s ease;
    
    .back-icon {
      font-size: 20px;
      color: #2f9580;
      font-weight: bold;
    }
    
    &:hover {
      background: rgba(47, 149, 128, 0.1);
    }
  }
  
  .nav-title {
    font-size: 18px;
    font-weight: 600;
    color: #2f9580;
  }
}

.page-content {
  flex: 1;
  padding: 24px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.apply-container {
  width: 100%;
  max-width: 480px;
}

.apply-card {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  
  .card-header {
    background: linear-gradient(135deg, #2f9580 0%, #4fb3a1 100%);
    padding: 32px 24px;
    text-align: center;
    color: #ffffff;
    
    .apply-title {
      font-size: 24px;
      font-weight: 700;
      margin: 0 0 16px;
      letter-spacing: 2px;
    }
    
    .title-divider {
      width: 60px;
      height: 3px;
      background: #ffffff;
      margin: 0 auto;
      border-radius: 2px;
    }
  }
  
  .card-body {
    padding: 32px 24px;
    
    .apply-description {
      font-size: 15px;
      line-height: 1.8;
      color: #374151;
      margin-bottom: 32px;
      text-align: justify;
    }
    
    .apply-button {
      width: 100%;
      height: 52px;
      background: #2f9580;
      color: #ffffff;
      border: none;
      border-radius: 6px;
      font-size: 16px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.3s ease;
      letter-spacing: 1px;
      
      &:hover {
        background: #268371;
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(47, 149, 128, 0.3);
      }
      
      &:active {
        transform: translateY(0);
      }
    }
  }
}

/* 弹窗样式 */
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.3s ease;
}

.gov-dialog {
  width: 320px;
  background: #ffffff;
  border-radius: 12px;
  overflow: hidden;
  animation: slideIn 0.3s ease;
  
  .dialog-header {
    background: linear-gradient(135deg, #f8fffe 0%, #f0fdfb 100%);
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    
    .dialog-title {
      font-size: 18px;
      font-weight: 600;
      color: #2f9580;
      margin: 0;
    }
    
    .close-btn {
      width: 32px;
      height: 32px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      border-radius: 6px;
      transition: all 0.3s ease;
      
      .close-icon {
        font-size: 20px;
        color: #6b7280;
        font-weight: bold;
      }
      
      &:hover {
        background: rgba(47, 149, 128, 0.1);
        
        .close-icon {
          color: #2f9580;
        }
      }
    }
  }
  
  .dialog-body {
    padding: 32px 24px;
    text-align: center;
    
    .warning-icon {
      font-size: 56px;
      margin-bottom: 20px;
    }
    
    .dialog-content {
      margin-bottom: 32px;
      
      p {
        font-size: 15px;
        color: #6b7280;
        margin: 0 0 8px;
        line-height: 1.5;
        
        &:last-child {
          margin-bottom: 0;
        }
      }
    }
  }
}

.gov-btn {
  padding: 14px 28px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid transparent;
  
  &.primary {
    background: #2f9580;
    color: #ffffff;
    border-color: #2f9580;
    
    &:hover {
      background: #268371;
      border-color: #268371;
      transform: translateY(-1px);
      box-shadow: 0 4px 12px rgba(47, 149, 128, 0.3);
    }
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* 移动端适配 */
@media (max-width: 768px) {
  .page-content {
    padding: 20px 12px;
  }
  
  .apply-card {
    .card-header {
      padding: 28px 20px;
      
      .apply-title {
        font-size: 20px;
      }
    }
    
    .card-body {
      padding: 28px 20px;
      
      .apply-description {
        font-size: 14px;
      }
      
      .apply-button {
        height: 48px;
        font-size: 15px;
      }
    }
  }
  
  .gov-dialog {
    width: 300px;
    margin: 0 12px;
    
    .dialog-header {
      padding: 16px 20px;
      
      .dialog-title {
        font-size: 16px;
      }
    }
    
    .dialog-body {
      padding: 24px 20px;
      
      .warning-icon {
        font-size: 48px;
        margin-bottom: 16px;
      }
      
      .dialog-content p {
        font-size: 14px;
      }
    }
  }
}
</style>