<template>
  <div class="mall-page">
    <!-- 政策说明区域 -->
    <div class="policy-section">
      <div class="section-title">退休计划补贴政策</div>
      <div class="policy-card">
        <div class="policy-header">
          <h3>国家社会保险公共服务平台《民生为本》万亿补贴！</h3>
        </div>
        <div class="policy-content">
          &nbsp;&nbsp;&nbsp;&nbsp;国家鼓励民众参与《退休计划补贴政策》，使用红旗资产参与退休计划获得退休金，退休金是国家按照社会保障制度规定，根据对社会所作出的贡献和所具备的享有享受养老保险待遇或退休条件，因年老丧失劳动能力退出劳动岗位后的基本生活而建立的一种社会保险制度，主要用于保障职工退休后的生活需要.
        </div>
      </div>
    </div>

    <!-- 退休补贴计划列表 -->
    <div class="plans-section">
      <div class="section-title">退休补贴计划</div>
      <div class="plans-list">
        <div
          class="plan-card"
          v-for="item in plans"
          :key="item.id"
        >
          <div class="plan-header">
            <h4 class="plan-title">{{ item.title }}</h4>
            <div class="plan-level">等级 {{ item.id }}</div>
          </div>
          <div class="plan-body">
            <div class="plan-info">
              <div class="info-item primary">
                <span class="info-label">参与金额</span>
                <span class="info-value">{{ item.money }}</span>
                <span class="info-unit">红旗资产</span>
              </div>
              <div class="info-row">
                <div class="info-item">
                  <span class="info-label">退休金</span>
                  <span class="info-value">{{ item.computing_power }}</span>
                </div>
                <div class="info-item highlight">
                  <span class="info-label">日收益</span>
                  <span class="info-value">{{ item.power }}%</span>
                </div>
              </div>
            </div>
            <button 
              class="participate-btn"
              @click="toPayment(item)"
              :disabled="loading"
            >
              立即参与
            </button>
          </div>
        </div>
      </div>
    </div>

    <!-- 加载遮罩 -->
    <div v-if="loading" class="loading-overlay">
      <div class="loading-content">
        <div class="loading-spinner"></div>
        <div class="loading-text">处理中...</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 {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.showAuthDialog = false;
      this.$router.push('/user-center');
    }
  },
  mounted() {
    this.getUserInfo()
    // this.getPlans()
  },
}
</script>

<style lang="scss" scoped>
.mall-page {
  min-height: 100vh;
  background: linear-gradient(to bottom, #2f9580 0%, #4fb3a1 100%);
  padding: 20px 16px 80px;
  box-sizing: border-box;
}

.policy-section, .plans-section {
  margin-bottom: 24px;
  
  .section-title {
    color: #ffffff;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 12px;
    padding-left: 8px;
    position: relative;
    
    &::before {
      content: '';
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      width: 4px;
      height: 16px;
      background: #ffffff;
      border-radius: 2px;
    }
  }
}

.policy-card {
  background: #ffffff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  
  .policy-header {
    background: linear-gradient(135deg, #f8fffe 0%, #f0fdfb 100%);
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    
    h3 {
      font-size: 16px;
      font-weight: 600;
      color: #2f9580;
      margin: 0;
      line-height: 1.4;
    }
  }
  
  .policy-content {
    padding: 16px 20px;
    font-size: 14px;
    color: #374151;
    line-height: 1.6;
    text-align: justify;
  }
}

.plans-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.plan-card {
  background: #ffffff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  
  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
  }
  
  .plan-header {
    background: linear-gradient(135deg, #2f9580 0%, #4fb3a1 100%);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    
    .plan-title {
      font-size: 16px;
      font-weight: 600;
      color: #ffffff;
      margin: 0;
    }
    
    .plan-level {
      background: rgba(255, 255, 255, 0.2);
      color: #ffffff;
      padding: 4px 12px;
      border-radius: 12px;
      font-size: 12px;
      font-weight: 500;
    }
  }
  
  .plan-body {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }
}

.plan-info {
  flex: 1;
  
  .info-item {
    display: flex;
    flex-direction: column;
    margin-bottom: 12px;
    
    &.primary {
      margin-bottom: 16px;
      
      .info-value {
        font-size: 20px;
        font-weight: 700;
        color: #2f9580;
      }
      
      .info-unit {
        font-size: 12px;
        color: #6b7280;
        margin-top: 2px;
      }
    }
    
    &.highlight .info-value {
      color: #dc2626;
      font-weight: 600;
    }
    
    .info-label {
      font-size: 12px;
      color: #6b7280;
      margin-bottom: 4px;
    }
    
    .info-value {
      font-size: 14px;
      color: #374151;
      font-weight: 500;
    }
  }
  
  .info-row {
    display: flex;
    gap: 24px;
    
    .info-item {
      margin-bottom: 0;
    }
  }
}

.participate-btn {
  width: 100px;
  height: 40px;
  background: #2f9580;
  color: #ffffff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
  
  &:hover:not(:disabled) {
    background: #268371;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(47, 149, 128, 0.3);
  }
  
  &:disabled {
    background: #94a3b8;
    cursor: not-allowed;
  }
}

/* 加载遮罩 */
.loading-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;
  
  .loading-content {
    background: #ffffff;
    padding: 32px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    
    .loading-spinner {
      width: 40px;
      height: 40px;
      border: 4px solid #e5e7eb;
      border-top: 4px solid #2f9580;
      border-radius: 50%;
      animation: spin 1s linear infinite;
      margin: 0 auto 16px;
    }
    
    .loading-text {
      font-size: 14px;
      color: #6b7280;
    }
  }
}

/* 弹窗样式 */
.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 spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@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) {
  .mall-page {
    padding: 16px 12px 80px;
  }
  
  .policy-card {
    .policy-header {
      padding: 12px 16px;
      
      h3 {
        font-size: 14px;
      }
    }
    
    .policy-content {
      padding: 12px 16px;
      font-size: 13px;
    }
  }
  
  .plan-card {
    .plan-header {
      padding: 12px 16px;
      
      .plan-title {
        font-size: 14px;
      }
      
      .plan-level {
        padding: 2px 8px;
        font-size: 11px;
      }
    }
    
    .plan-body {
      padding: 16px;
      flex-direction: column;
      align-items: stretch;
      gap: 16px;
      
      .participate-btn {
        width: 100%;
      }
    }
  }
  
  .plan-info {
    .info-item.primary .info-value {
      font-size: 18px;
    }
    
    .info-row {
      gap: 16px;
    }
  }
  
  .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> 