<template>
  <view class="page">
    <u-parse :content="agreementContent"></u-parse>
  </view>
</template>

<script>
export default {
  data() {
    return {
      agreementContent: "",
      language: "",
    };
  },
  computed: {
    i18n() {
      return this.$t("index");
    },
  },
  methods: {
    getAgreementContent() {
      uni.$u.http.get(`/api/agreement?code=margin_rule`).then((res) => {
        this.agreementContent = res;
        //判断选择的语言
        if (this.language == "zh-CN") {
          this.agreementContent = res.content_cn;
        } else if (this.language == "en-US") {
          this.agreementContent = res.content_en;
        } else if (this.language == "es-ES") {
          this.agreementContent = res.content_es;
        } else {
          this.agreementContent = res.content_ita;
        }
      });
    },
  },
  mounted() {
    //获取当前选择的语言
    const _this = this;
    uni.getStorage({
      key: "language", // 这里替换成你要获取的数据的key
      success: function (res) {
        _this.language = res.data; // 输出获取到的数据
      },
      fail: function () {
        // 获取失败的处理逻辑
      },
    });
    this.getAgreementContent();
    uni.setNavigationBarTitle({
      title: this.i18n.marginStatement,
    });
  },
};
</script>

<style>
.page {
  width: 94vw;
  background-color: #fff;
  padding: 0 24rpx;
  font-size: 28rpx;
  color: #222;
  opacity: 0.6;
}
</style>
