<template>
  <div class="realauth-container">
    <!-- Add Toast component -->
    <Toast ref="toast" />
    <!-- 导航栏 -->
    <div class="nav-bar">
      <div class="back-btn" @click="$router.back()">
        <i class="arrow-left"></i>
      </div>
      <div class="title">实名认证</div>
    </div>

    <div class="content">
      <!-- 已认证状态 -->
      <div v-if="userInfo.if_real === 1" class="auth-success-container">
        <div class="success-card">
          <div class="success-icon">
            <svg viewBox="64 64 896 896" data-icon="check-circle" width="80px" height="80px" fill="#2f9580" aria-hidden="true">
              <path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 01-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"></path>
            </svg>
          </div>
          <div class="success-title">认证成功</div>
          <div class="success-text">您已完成实名认证</div>
        </div>
      </div>

      <!-- 未认证状态 -->
      <div v-else>
        <!-- 认证表单 -->
        <div class="form-container">
          <div class="form-item">
            <div class="form-label">证件类型</div>
            <div class="form-value">身份证</div>
          </div>

          <div class="form-item">
            <div class="form-label">证件姓名</div>
            <input 
              type="text" 
              class="form-input"
              placeholder="请输入您的真实姓名"
              v-model="formData.realName"
            >
          </div>

          <div class="form-item">
            <div class="form-label">证件号码</div>
            <input 
              type="text" 
              class="form-input"
              placeholder="请输入18位身份证号码"
              v-model="formData.idCard"
            >
          </div>

          <div class="submit-section">
            <button 
              class="submit-btn"
              @click="handleSubmit"
            >
              提交认证
            </button>
          </div>
        </div>

        <!-- 注意事项 -->
        <div class="notice-section">
          <div class="section-header">
            <div class="section-title">注意事项</div>
          </div>
          <div class="notice-content">
            <div class="notice-item">
              <div class="notice-text">为保证您的权益请认真查看以下条例，如有疑问请及时联系在线客服</div>
            </div>
            <div class="notice-item">
              <div class="notice-text">身份证件拍摄不完整有反光</div>
            </div>
            <div class="notice-item">
              <div class="notice-text">提交信息和身份证件不一致</div>
            </div>
            <div class="notice-item">
              <div class="notice-text">为了您的信息安全审核期间由AI机器人全程负责我们无法干预</div>
            </div>
            <div class="notice-item">
              <div class="notice-text">使用虚假信息的用户我们将采取相应措施,包含且不限于封号、冻结资产、限制登录等</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Toast from '@/components/Toast.vue';
import { setReal, getUserInfo } from '@/api/home';

export default {
  name: 'RealAuthentication',
  components: {
    Toast
  },
  data() {
    return {
      userInfo: {},
      formData: {
        realName: '',
        idCard: ''
      }
    }
  },
  created() {
    this.getUserInfo();
  },
  methods: {
    async getUserInfo() {
      try {
        const res = await getUserInfo();
        this.userInfo = res.data;
      } catch (error) {
        this.$refs.toast.show('获取用户信息失败', 'error');
      }
    },
    async handleSubmit() {
      if (!this.formData.realName) {
        this.$refs.toast.show('请输入姓名', 'warning');
        return;
      }
      if (!this.formData.idCard) {
        this.$refs.toast.show('请输入证件号码', 'warning');
        return;
      }

      try {
        const params = {
          type: '身份证',
          name: this.formData.realName,
          idCard: this.formData.idCard
        };

        const res = await setReal(params);

        if (res.code === 1) {
          this.$refs.toast.show('认证信息提交成功', 'success');
          setTimeout(() => {
            this.$router.back();
          }, 1500);
        } else {
          this.$refs.toast.show(res.msg || '认证失败，请重试', 'error');
        }
      } catch (error) {
        this.$refs.toast.show('网络错误，请稍后重试', 'error');
      }
    }
  }
}
</script>

<style scoped>
.realauth-container {
  min-height: 100vh;
  background: linear-gradient(to bottom, #2f9580 0%, #4fb3a1 100%);
}

.nav-bar {
  height: 56px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  color: #fff;
  display: flex;
  align-items: center;
  position: relative;
  padding: 0 15px;
}

.back-btn {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.arrow-left {
  width: 12px;
  height: 12px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(45deg);
}

.title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 18px;
  font-weight: 600;
}

.content {
  padding: 20px;
  min-height: calc(100vh - 56px);
}

.auth-success-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 60vh;
}

.success-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 30px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  max-width: 300px;
  width: 100%;
}

.success-icon {
  margin-bottom: 20px;
}

.success-title {
  font-size: 20px;
  color: #2f9580;
  font-weight: 600;
  margin-bottom: 12px;
}

.success-text {
  font-size: 16px;
  color: #374151;
  line-height: 1.6;
}

.form-container {
  background: #fff;
  border-radius: 16px;
  padding: 24px 20px;
  margin-bottom: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.form-item {
  margin-bottom: 24px;
}

.form-item:last-child {
  margin-bottom: 0;
}

.form-label {
  font-size: 15px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 12px;
  display: block;
}

.form-value {
  height: 48px;
  line-height: 48px;
  padding: 0 16px;
  background: #f8f9fa;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  color: #6b7280;
  font-size: 16px;
}

.form-input {
  width: 100%;
  height: 48px;
  border: 2px solid #e5e7eb;
  background: #f8f9fa;
  border-radius: 12px;
  font-size: 16px;
  padding: 0 16px;
  color: #374151;
  transition: all 0.3s ease;
  box-sizing: border-box;
}

.form-input::placeholder {
  color: #9ca3af;
}

.form-input:focus {
  outline: none;
  border-color: #2f9580;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(47, 149, 128, 0.1);
}

.submit-section {
  margin-top: 32px;
  text-align: center;
}

.submit-btn {
  width: 100%;
  height: 52px;
  background: #2f9580;
  border-radius: 12px;
  border: none;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(47, 149, 128, 0.3);
}

.submit-btn:hover {
  background: #268371;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(47, 149, 128, 0.4);
}

.submit-btn:active {
  transform: translateY(0);
}

.notice-section {
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.section-header {
  background: linear-gradient(135deg, #2f9580 0%, #4fb3a1 100%);
  padding: 16px 20px;
}

.section-title {
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.notice-content {
  padding: 20px;
}

.notice-item {
  margin-bottom: 16px;
  position: relative;
  padding-left: 16px;
}

.notice-item:last-child {
  margin-bottom: 0;
}

.notice-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  width: 4px;
  height: 4px;
  background: #2f9580;
  border-radius: 50%;
}

.notice-text {
  color: #374151;
  font-size: 14px;
  line-height: 1.6;
}

/* 移动端适配 */
@media (max-width: 768px) {
  .nav-bar {
    height: 50px;
    padding: 0 12px;
  }
  
  .back-btn {
    width: 36px;
    height: 36px;
  }
  
  .title {
    font-size: 16px;
  }
  
  .content {
    padding: 16px;
  }
  
  .success-card {
    padding: 30px 20px;
    max-width: 280px;
  }
  
  .success-title {
    font-size: 18px;
  }
  
  .success-text {
    font-size: 15px;
  }
  
  .form-container {
    padding: 20px 16px;
  }
  
  .form-item {
    margin-bottom: 20px;
  }
  
  .form-label {
    font-size: 14px;
    margin-bottom: 10px;
  }
  
  .form-value {
    height: 44px;
    line-height: 44px;
    font-size: 15px;
    padding: 0 14px;
  }
  
  .form-input {
    height: 44px;
    font-size: 15px;
    padding: 0 14px;
  }
  
  .submit-btn {
    height: 48px;
    font-size: 15px;
  }
  
  .section-header {
    padding: 12px 16px;
  }
  
  .section-title {
    font-size: 15px;
  }
  
  .notice-content {
    padding: 16px;
  }
  
  .notice-item {
    margin-bottom: 14px;
    padding-left: 14px;
  }
  
  .notice-text {
    font-size: 13px;
  }
}
</style> 