<template>
  <div class="usremei-container">
    <div class="top-bg"></div>
    <div class="desc-card">
      <div class="desc-title">国家社会保险公共服务平台《民生为本》万亿补贴！</div>
      <div class="desc-content">
           &nbsp;&nbsp;&nbsp;&nbsp;国家鼓励民众参与《退休计划补贴政策》，使用红旗资产参与退休计划获得退休金，退休金是国家按照社会保障制度规定，根据对社会所作出的贡献和所具备的享有享受养老保险待遇或退休条件，因年老丧失劳动能力退出劳动岗位后的基本生活而建立的一种社会保险制度，主要用于保障职工退休后的生活需要.
      </div>
    </div>
    <div
      class="plan-card"
      v-for="item in plans"
      :key="item.id"
    >
      <div class="plan-header">
        {{ item.title }}
      </div>
      <div class="plan-content">
        <div class="plan-info">
          <div class="plan-amount">
            <span class="amount-label">参与金额</span>
            <span class="amount-value">{{ item.money }}红旗资产</span>
          </div>
          <div class="plan-details">
            <div class="detail-item">
              <span class="detail-label">退休金</span>
              <span class="detail-value">{{ item.computing_power }}</span>
            </div>
            <div class="detail-item">
              <span class="detail-label">日收益</span>
              <span class="detail-value highlight">{{ item.power }}%</span>
            </div>
          </div>
        </div>
        <button 
          class="action-btn"
          @click="toPayment(item)"
        >
          立即参与
        </button>
      </div>
    </div>
    <div v-if="loading" class="loading-mask">
      <div class="loading-spinner"></div>
      <div>加载中...</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 {getMiner,getUserInfo,joinRetirement} from '@/api/home.js'
import { Toast } from 'vant';
export default {
  name: 'Mall',
  data() {
    return {
      plans: [
          {
              "id": 1,
              "type": 1,
              "title": "初级退休补贴金",
              "money": "30000",
              "rent_cycle": 1825,
              "computing_power": "3000",
              "power": "10",
          },
          {
              "id": 2,
              "type": 2,
              "title": "一级退休补贴金",
              "money": "60000",
              "rent_cycle": 1825,
              "computing_power": "6000",
              "power": "10",
          },
          {
              "id": 3,
              "type": 3,
              "title": "二级退休补贴金",
              "money": "100000",
              "rent_cycle": 1825,
              "computing_power": "10000",
              "power": "10",
          },
          {
              "id": 4,
              "type": 4,
              "title": "三级退休补贴金",
              "money": "200000",
              "rent_cycle": 1825,
              "computing_power": "20000",
              "power": "10",
          }
      ],
      userInfo: {},
      loading: false,
      showAuthDialog: false
    }
  },
  methods:{
    async getUserInfo() {
      const res = await getUserInfo();
      this.userInfo = res.data;
    },
    getPlans(){
      let data = {
        page:'',
        size:'',
        type:1
      }
      getMiner(data).then(res=>{
        if(res.code === 1){
          this.plans = res.data
        }
      })
    },
    toPayment(item) {
      // 检查实名认证状态
      if (this.userInfo.if_real === 0) {
        this.showAuthDialog = true;
        return;
      }

      this.loading = true;
      joinRetirement(item.type)
        .then(res => {
          Toast({
            message: res.msg || (res.code === 1 ? '参与成功' : '参与失败'),
            duration: 2000,
            onClose: () => {
              if (res.code === 1) {
                this.getUserInfo();
              }
            }
          });
        })
        .catch(err => {
          Toast('网络异常，请重试');
          console.error(err);
        })
        .finally(() => {
          this.loading = false;
        });
    },
    goToAuth() {
      this.$router.push('/user-center');
    }
  },
  mounted() {
    this.getUserInfo()
    // this.getPlans()
  },
}
</script>

<style scoped>
.usremei-container {
  min-height: 100vh;
  background-image: url('../assets/dabag.png');
  background-size: cover;
  background-position: center;
  padding:60px 10px 60px;
  box-sizing: border-box;
}

.desc-card {
  background: rgba(255, 248, 225, 0.95);
  border-radius: 8px;
  margin: 0 0 8px;
  padding: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.desc-title {
  font-size: 15px;
  font-weight: bold;
  color: #d0021b;
  margin-bottom: 6px;
  line-height: 1.2;
}

.desc-content {
  font-size: 12px;
  color: #333;
  line-height: 1.4;
  max-height: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
 /* -webkit-line-clamp: 3; */
  -webkit-box-orient: vertical;
}

.plan-card {
  height: 135px;
  background: #fff;
  border-radius: 8px;
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  
}

.plan-header {
  background: #fce5b1;
  color: #000;
  font-size: 14px;
  font-weight: bold;
  padding: 6px 10px;

}

.plan-content {
  padding: 8px 10px;
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
}

.plan-info {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-right: 10px;
}

.plan-amount {
  text-align: left;
}

.amount-label {
  font-size: 12px;
  color: #666;
  margin-bottom: 2px;
}

.amount-value {
  font-size: 16px;
  font-weight: bold;
  color: #d0021b;
  white-space: nowrap;
}

.plan-details {
  display: flex;
  gap: 15px;
}

.detail-item {
  text-align: center;
}

.detail-label {
  font-size: 12px;
  color: #666;
  margin-bottom: 2px;
}

.detail-value {
  font-size: 14px;
  font-weight: bold;
  color: #333;
}

.detail-value.highlight {
  color: #d0021b;
}

.action-btn {
  width: 80px;
  height: 32px;
  background: #d0021b;
  color: #fff;
  border: none;
  border-radius: 16px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  flex-shrink: 0;
}

.loading-mask {
  position: fixed;
  left: 0; top: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.loading-spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #b80032;
  border-radius: 50%;
  width: 40px; height: 40px;
  animation: spin 1s linear infinite;
  margin-bottom: 10px;
}

@keyframes spin {
  0% { transform: rotate(0deg);}
  100% { transform: rotate(360deg);}
}

/* 认证弹窗样式 */
.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: 51%;
  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);
  }
}
</style> 