<template>
  <view class="w-body">
    <w-public />
    <w-navbar left-back fixed :title="title"></w-navbar>
    <view style="padding: .5rem; font-size: .8rem;  line-height: 1.8;">
      <view v-if="showTitle" style="padding-bottom: .5rem; margin-bottom: .5rem; border-bottom: solid 1px #0001;">
        <view style="font-size: 1rem; font-weight: bold;">{{ content.noticeTitle }}</view>
        <view v-if="showTime">{{ content.createTime }}</view>
      </view>
      <rich-text :nodes="content.noticeContent"></rich-text>
    </view>
  </view>
</template>

<script setup>
import { onLoad, onShow, onReady } from '@dcloudio/uni-app'
import { ref, getCurrentInstance } from 'vue'
import { listNotice, getNotice } from '@/api/system/notice'

const { proxy } = getCurrentInstance();

const title = ref("");
const showTitle = ref(false);//显示文章标题
const showTime = ref(false);

const content = ref({});

onLoad(async (e) => {
  title.value = e.title;
  showTitle.value='true'==e.showTitle;
  showTime.value='true'==e.showTime;
  if (e.id) {
    let r = await getNotice(e.id);
    if (r.data && r.data.status == '0') {
      if (!title.value) {
        title.value = r.data.noticeTitle;
      }
      if(!e.showTitle){
        showTitle.value=true;
      }
      content.value = r.data;
    } else {
      uni.$w.to('msg?ok=false&msg=文章不存在&to=launch');
    }
    console.info(r);
    return;
  }
  let r = await listNotice({ pageSize: 1, orderByColumn: 'notice_id', isAsc: 'desc', noticeType: e.type, status: 0,searchCount:false });
  console.debug(r);
  if (r.rows?.length == 1) {
    if (!title.value) {
      title.value = r.rows[0].noticeTitle;
    }
    content.value = r.rows[0];
  } else {
    uni.$w.to('msg?ok=false&msg=文章不存在&to=launch');
  }

})


</script>

<style lang="scss" scoped>
.w-body {
  --navbar-height: 44px;
  background-color: var(--w-bg);
  font-size: .9rem;
  min-height: 100vh;
}
</style>
