<template>
  <view class="Mall4j terms-container">
    <!-- 服务条款/隐私协议 -->
    <rich-text :nodes="content" />
  </view>
</template>

<script setup>
import util from '@/utils/util'

const content = ref('')
onLoad((options) => {
  uni.setNavigationBarTitle({
    title: options.sts === 'serviceTerms' ? '服务条款' : options.sts === 'servicePolicy' ? '隐私策略' : '服务条款和隐私策略'
  })
  ServiceTermsConfig(options.sts)
})

/**
 * 服务条款与隐私策略
 * @param key 'serviceTerms'代表服务条款，'service-policy'代表隐私策略
 */
const ServiceTermsConfig = (key) => {
  let url = ''
  if (key === 'serviceTerms') {
    url = '/mall4cloud_admin/ua/app/sys_config/service_protocol'
  } else if (key === 'servicePolicy') {
    url = '/mall4cloud_admin/ua/app/sys_config/privacy_protocol'
  }
  http.request({
    url,
    method: 'GET'
  }).then(res => {
    content.value = util.formatHtml(res)
  }).catch(errMsg => {
    if (errMsg.msg) {
      uni.showToast({
        title: errMsg.msg,
        duration: 2000,
        icon: 'none'
      })
      setTimeout(() => {
        uni.navigateBack()
      }, 1800)
    }
  })
}

</script>

<style lang="scss" scoped>
/* terms-page */
.terms-container {
  padding: 40rpx;
}
</style>
