<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)"
          >立即参与</button>
        </div>
      </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:{}
    }
  },
  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){
      joinRetirement(item.type).then(res=>{
        console.log(res,'2222222222');
      })
    },
    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;
      }
    },
  },
  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;
}
</style> 