<template>
  <div class="usremei-container">
    <div class="top-bg"></div>
    <div class="desc-card">
      <div class="desc-title">国家社会保险公共服务平台《民生为本》万亿补贴！</div>
      <div class="desc-content">
        国家鼓励民众参与《退休计划补贴政策》，使用红旗资产参与退休计划获得退休金，退休金是国家按照社会保障制度规定，根据对社会所作出的贡献和所具备的享有享受养老保险待遇或退休条件，因年老丧失劳动能力退出劳动岗位后的基本生活而建立的一种社会保险制度，主要用于保障职工退休后的生活需要
      </div>
    </div>
    <div
      class="plan-card"
      v-for="item in plans"
      :key="item.id"
    >
      <div class="plan-header">
        {{ item.title }}
      </div>
      <div class="plan-table-row">
        <div class="plan-col">
          <div class="plan-label">参与金额</div>
          <div class="plan-value">{{ item.money }}红旗资产</div>
        </div>
        <div class="plan-col">
          <div class="plan-label">退休金</div>
          <div class="plan-value">{{ item.computing_power }}</div>
        </div>
        <div class="plan-col">
          <div class="plan-label">日收益</div>
          <div class="plan-value">{{ item.power }}%</div>
        </div>
        <div class="plan-col-btn">
          <button 
            class="plan-btn" 
            :class="{ 'disabled': !canClick(item) }"
            @click="canClick(item) && toPayment(item)"
            :disabled="!canClick(item)"
          >{{disabled ? '立即参与' : '已参与'}}</button>
        </div>
      </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'
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 => {
          console.log(res, '2222222222');
        })
        .catch(err => {
          console.error(err);
        })
        .finally(() => {
          this.loading = false;
        });
    },
    canClick(item) {
      const { chuji, yiji, erji, sanji } = this.userInfo;
      switch(item.id) {
        case 1:
          return chuji === 0;
        case 2:
          return yiji === 0;
        case 3:
          return erji === 0;
        case 4:
          return sanji === 0;
        default:
          return 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-top: 60px;
  padding-bottom: 80px; /* 为底部tab预留空间 */
  box-sizing: border-box; /* 确保padding不会增加容器高度 */
  overflow-y: auto; /* 允许内容滚动 */
  position: relative; /* 为fixed定位提供参考 */
}

.desc-card {
  background: #fff8e1;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  margin: 0px 16px 24px 16px;
  padding: 18px 16px 12px 16px;
  z-index: 2;
  position: relative;
}
.desc-title {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 8px;
}
.desc-content {
  font-size: 12px;
  color: #333;
  line-height: 1.7;
}
.plan-card {
  background: #d0021b;
  border-radius: 8px;
  margin: 0 16px 22px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.10);
  
}
.plan-header {
  background: #fff8e1;
  color: #333;
  font-size: 14px;
  font-weight: bold;
  padding: 6px 12px;
  border-bottom: 1px solid #f5c6cb;
}
.plan-table-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  padding: 0 18px;
  height: 70px;
}
.plan-col {
  width:auto;
  font-size:12px;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
}
.plan-label {
  color: #333;
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 2px;
}
.plan-value {
  margin-top:6px;
  font-size: 14px;
  text-align:center;
}
.plan-col-btn {
  
  display: flex;
  justify-content: center;
  align-items: center;
}
.plan-btn {
  background: #b80032;
  color: #fff;
  border: none;
  border-radius: 18px;
  padding: 2px 6px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}
.plan-btn:hover {
  background: #a00028;
}
.plan-btn.disabled {
  background: #cccccc;
  cursor: not-allowed;
}
.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: 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);
  }
}
</style> 