<template>
  <div>
    <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="fund-card">
        <div class="title">参与基金</div>
        <div class="subtitle">
          {{item.title}}
        </div>
        <div class="form-section">
          <div class="label">请选择支付方式</div>
          <div class="pay-group">
            <label 
              v-for="item in payList" 
              :key="item.id" 
              class="pay-radio"
              :class="{ active: payType === item.title }"
            >
              <input 
                type="radio" 
                :value="item.title" 
                v-model="payType"
                class="radio-input"
              >
              <span class="radio-label">{{ item.title }}</span>
            </label>
          </div>
        </div>
        <div class="form-section">
          <div class="label">产品价格</div>
          <div class="price-field">
            <input 
              type="text" 
              v-model="item.money" 
              readonly 
              class="price-input"
            >
          </div>
        </div>
        <button 
          class="submit-btn"
          :disabled="!payType"
          @click="handleSubmit"
        >
          参与
        </button>
      </div>
    </div>
  </div>
</template>

<script>
import {getTong,getChongInfo} from '@/api/home.js'
import { Toast } from 'vant';
export default {
  name: 'InvitePeople',
  data() {
    return {
      payType: '',
      payList: [],
      item:{}
    }
  },
  methods:{
    goBack() {
      this.$router.go(-1)
    },
    async getPayType(){
      const res = await getTong()
      this.payList = res.data || []
    },
     handleSubmit() {
        // 处理提交逻辑
        let params = {
            type: this.payType,
            money: this.item.money,
        }
        getChongInfo(params).then(res => {
            if(res.code === 1){
            Toast.success('提交成功')
            setTimeout(() => {
                window.location.href = res.data.payUrl
            }, 1000);
            }
        })
          }
  },
  mounted(){
    this.getPayType()
    this.item = this.$route.query.item
  }
}
</script>

<style lang="scss" scoped>
.invite-page {
  min-height: 100vh;
  background: url('~@/assets/dabag.png') no-repeat center center;
  background-size: cover;
  padding: 120px 16px 32px 16px;
  box-sizing: border-box;
}

.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;
  }
}

.top-header {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
  padding-top:12px;
  .logo {
    width: 85px;
    height: 58px;
    object-fit: contain;
    background: #fff;
    margin-right: 16px;
  }
  .slogan {
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    line-height: 1.3;
    text-shadow: 0 2px 8px rgba(0,0,0,0.12);
  }
}

.fund-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  padding: 28px 18px 24px 18px;
  max-width: 350px;
  margin: 0 auto;
  text-align: center;
}

.title {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 8px;
}

.subtitle {
  font-size: 16px;
  color: #333;
  margin-bottom: 18px;
  .amount {
    font-weight: bold;
    font-size: 16px;
  }
}

.form-section {
  margin-bottom: 18px;
  text-align: left;
}

.label {
  font-size: 15px;
  color: #333;
  margin-bottom: 8px;
}

.pay-group {
  background: #f7f8fa;
  border-radius: 12px;
  padding: 6px 0;
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.pay-radio {
  margin-right: 18px;
  background: #fff;
  border-radius: 8px;
  padding: 4px 18px;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s;
  border: 1px solid #eee;

  &.active {
    background: #e8f5e9;
    border-color: #4caf50;
  }

  .radio-input {
    display: none;
  }

  .radio-label {
    font-size: 14px;
    color: #333;
  }
}

.price-field {
  background: #f7f8fa;
  border-radius: 8px;
  padding: 8px 12px;
  
  .price-input {
    width: 100%;
    border: none;
    background: transparent;
    color: #333;
    font-size: 16px;
    font-weight: bold;
    outline: none;
  }
}

.submit-btn {
  margin-top: 10px;
  height: 40px;
  width: 100%;
  font-size: 18px;
  border-radius: 12px;
  background: #f7f8fa;
  color: #999;
  border: none;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s;

  &:not(:disabled) {
    background: #4caf50;
    color: #fff;
  }

  &:disabled {
    cursor: not-allowed;
  }
}
</style>