<template>
<div style="height:100%">
    <div class="headers">
      <div class="back" @click="goBack">
        <img src="@/assets/back.png" alt="">
      </div>
      <div class="title">党员申请</div>
    </div>
  <div class="invite-page">
    <div class="apply-card">
      <div class="apply-title">党员招募</div>
      <div class="apply-divider"></div>
      <div class="apply-desc">
        国家平台总部招募党员团队主管，团队总人数达到100人即可成为党员主管，每月可享受60000元党员团队奖励金直接到账银行卡。加入中国共产党那一刻起，都必须无一例外地履行党员义务！
      </div>
      <button class="apply-btn" @click="applyDan">我要参党</button>
    </div>
  </div>
  <!-- 实名认证提示弹窗 -->
  <div v-if="showAuthDialog" class="custom-dialog-mask">
    <div class="custom-dialog auth-dialog">
      <div class="dialog-close" @click="showAuthDialog = false">
        <i class="close-icon"></i>
      </div>
      <div class="dialog-icon">
        <svg t="1710401275044" class="auth-icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6356">
          <path d="M512 512m-448 0a448 448 0 1 0 896 0 448 448 0 1 0-896 0Z" fill="#1890FF" p-id="6357"></path>
          <path d="M512 320c-17.7 0-32 14.3-32 32v256c0 17.7 14.3 32 32 32s32-14.3 32-32V352c0-17.7-14.3-32-32-32z" fill="#FFFFFF" p-id="6358"></path>
          <path d="M512 720m-48 0a48 48 0 1 0 96 0 48 48 0 1 0-96 0Z" fill="#FFFFFF" p-id="6359"></path>
        </svg>
      </div>
      <div class="dialog-title auth-title">温馨提示</div>
      <div class="dialog-content">您还未完成实名认证<br/>请先进行实名认证</div>
      <button class="dialog-btn auth-btn" @click="goToAuth">去认证</button>
    </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.$router.push('/user-center');
    }
  },
  created() {
    this.getUserInfo();
  }
}
</script>

<style lang="scss" scoped>
.invite-page {
  min-height: 100%;
  background: url('~@/assets/dangyuan.jpg') no-repeat center center;
  background-size: 100% 100%;
  padding: 0px 16px 32px 16px;
  box-sizing: border-box;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 55px;
}
 .headers {
    position: relative;
    height: 44px;
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid #eee;

    .back {
      position: absolute;
      left: 15px;
      font-size: 20px;
      img{
        width: 20px;
        height: 20px;
      }
    }

    .title {
      font-size: 18px;
      font-weight: 500;
    }
  }

.apply-card {
  width: 90%;
  max-width: 420px;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  padding: 28px 18px 24px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 auto;
}

.apply-title {
  color: #ed145b;
  font-size: 22px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 12px;
  letter-spacing: 2px;
}

.apply-divider {
  width: 100%;
  height: 1px;
  background: #e0e0e0;
  margin-bottom: 18px;
}

.apply-desc {
  color: #222;
  font-size: 16px;
  line-height: 1.8;
  text-align: left;
  margin-bottom: 32px;
  word-break: break-all;
}

.apply-btn {
  width: 50%;
  max-width: 260px;
  height: 36px;
  background: #ed145b;
  color: #000;
  border: none;
  border-radius: 24px;
  font-size: 16px;
  font-weight: 600;
  margin: 0 auto;
  cursor: pointer;
  transition: background 0.2s;
  box-shadow: 0 2px 8px rgba(237, 20, 91, 0.08);
  letter-spacing: 2px;
}

.apply-btn:hover {
  background: #c9104a;
}

/* 新增认证弹窗样式 */
.custom-dialog-mask {
  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;
}

.custom-dialog {
  position: relative;
  width: 280px;
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  animation: dialogFadeIn 0.3s ease;
}

.dialog-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 16px;
}

.auth-icon {
  width: 100%;
  height: 100%;
}

.dialog-title {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 12px;
}

.auth-title {
  color: #1890FF;
}

.dialog-content {
  font-size: 14px;
  color: #666;
  line-height: 1.8;
  margin: 16px 0 24px;
}

.dialog-btn {
  width: 100%;
  height: 40px;
  border: none;
  border-radius: 20px;
  font-size: 16px;
  color: #fff;
  cursor: pointer;
  transition: all 0.3s ease;
}

.auth-btn {
  background: #1890FF;
}

.auth-btn:hover {
  background: #40a9ff;
}

.auth-dialog {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.dialog-close:hover {
  transform: rotate(90deg);
}

.dialog-close .close-icon {
  position: relative;
  width: 16px;
  height: 16px;
}

.dialog-close .close-icon::before,
.dialog-close .close-icon::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 2px;
  background-color: #999;
  top: 50%;
  left: 0;
}

.dialog-close .close-icon::before {
  transform: rotate(45deg);
}

.dialog-close .close-icon::after {
  transform: rotate(-45deg);
}

@keyframes dialogFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media screen and (max-width: 375px) {
  .invite-page {
    padding: 0 12px 45px 12px;
  }
  
  .apply-card {
    width: 92%;
    padding: 20px 15px 18px 15px;
  }
  
  .apply-title {
    font-size: 20px;
  }
  
  .apply-desc {
    font-size: 14px;
    margin-bottom: 24px;
  }
  
  .apply-btn {
    width: 60%;
    height: 34px;
    font-size: 15px;
  }
}
</style>