<template>
  <view class="Mall4j page-distribution-notice-detail">
    <view
      v-if="news.msgTitle"
      class="news-detail-title"
    >
      {{ news.msgTitle }}
    </view>
    <view class="news-detail-content">
      <rich-text :nodes="news.content" />
    </view>
  </view>
</template>

<script setup>
let msgId = null
onLoad((option) => {
  msgId = option.id
})

onLoad(() => {
  // 分销员信息
  getDisInfo()
  // 获取分销公告详情
  getDistributionDetail()
})

/**
 * 获取分销员信息
 */
const getDisInfo = () => {
  http.request({
    url: '/tmerclub_marketing/distribution_user/distribution_user_info',
    method: 'GET'
  }).then(res => {
    if (res.state === -1) {
      uni.showModal({
        title: '',
        showCancel: false,
        content: $t('distributorBanned'),
        confirmColor: '#eb2444',
        success (res) {
          if (res.confirm) {
            uni.switchTab({
              url: '/pages/user/user'
            })
          }
        }
      })
    }
    if (res.state === 2) {
      uni.showToast({
        title: $t('distributorCleared'),
        mask: true,
        icon: 'none'
      })
      uni.showModal({
        title: '',
        content: $t('distributorCleared'),
        confirmText: $t('confirm'),
        confirmColor: '#eb2444',
        showCancel: false
      })
    }
  })
}

// 获取分销详情
const news = ref({})
const getDistributionDetail = () => {
  http.request({
    url: '/tmerclub_marketing/distribution_msg?msgId=' + msgId,
    method: 'GET'
  }).then(res => {
    nextTick(() => {
      res.content = util.formatHtml(res.content)
      news.value = res
    })
  })
}

</script>

<style lang="scss" scoped>
@use "./distribution-notice-detail.scss";
</style>
