<template>
  <view class="contract-page">
    <view class="content">
      <view class="title">{{ agreementTitle }}</view>
      <view class="article">
        <rich-text :nodes="agreementContent"></rich-text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      type: '',
      agreementTitle: '',
      agreementContent: ''
    }
  },
  
  onLoad(options) {
    this.type = options.type || 'user';
    this.loadAgreement();
  },
  
  methods: {
    async loadAgreement() {
      try {
        const res = await this.$http.get('/api/setting/agreement', {
          type: this.type
        });
        
        if (res.code === 0) {
          this.agreementTitle = res.data.title;
          this.agreementContent = res.data.content;
        }
      } catch (error) {
        console.error('加载协议失败:', error);
        // 显示默认内容
        this.agreementTitle = '用户协议';
        this.agreementContent = '<p>协议内容加载中...</p>';
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.contract-page {
  min-height: 100vh;
  background-color: #fff;
  padding: 30rpx;
}

.content {
  .title {
    font-size: 36rpx;
    font-weight: bold;
    color: #333;
    text-align: center;
    margin-bottom: 40rpx;
  }
  
  .article {
    font-size: 28rpx;
    color: #666;
    line-height: 1.8;
  }
}
</style>

