index.vue 3.3 KB
<template>
  <u-navbar autoBack title="消息通知" :safeAreaInsetTop="true" placeholder>
    <!-- <template #right>
      <view style="font-size: 26rpx; font-weight: 700">一键已读</view>
    </template> -->
  </u-navbar>
  <view class="message">
    <view v-for="(_, index) in list" :key="index" @click="jumpUrlHandler(_)">
      <view class="flexJ">
        <view class="flexA">
          <view class="poBox">
            <image :src="_.imgUrl" mode="aspectFill" />
            <view class="message-badge flexC" v-if="![0, '0'].includes(_.BadgeNum)">{{ _.BadgeNum < 99 ? _.BadgeNum : '99+' }}</view>
          </view>
          <view style="margin-left: 20rpx">
            <view class="message-title">{{ _.title }}</view>
            <text class="message-text">{{ _.text }}</text>
          </view>
        </view>
        <view>
          <view class="message-time">{{ _.time }}</view>
        </view>
      </view>
      <view class="flexD">
        <u-line margin="30rpx 0" v-if="index !== list.length - 1" length="80%"></u-line>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref, getCurrentInstance, ComponentPublicInstance } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { getMsg_count } from '../../api'
import { MessageCountType, PageMessageListType } from '../../types'

const { proxy } = getCurrentInstance() as { proxy: ComponentPublicInstance }

const list = ref<PageMessageListType[]>([
  { title: '系统通知', text: '', numKey: 'sysCount', textkey: 'sysFirstContent', timeKey: 'sysFirstTime', BadgeNum: 0, time: '暂无', type: '1', imgUrl: '/static/images/response.png' },
  { title: '用户反馈', text: '', numKey: 'userCount', textkey: 'userFirstContent', timeKey: 'userFirstTime', BadgeNum: 0, time: '暂无', type: '2', imgUrl: '/static/images/message.png' },
  { title: '续方通知', text: '', numKey: 'xufangCount', textkey: 'xufangContent', timeKey: 'xufangTime', BadgeNum: 0, time: '暂无', type: '3', imgUrl: '/static/images/xftz.png', url: '/pages2/order/renew' }
])

const getDataHandler = async () => {
  const { result }: { result: MessageCountType } = await getMsg_count()

  list.value = list.value.map(_ => ({ ..._, BadgeNum: result[_.numKey] || 0, text: result[_.textkey] || '暂无消息', time: result[_.timeKey] || '暂无' }))
}

const jumpUrlHandler = (_: PageMessageListType) => (['1', '2'].includes(_.type) ? proxy.$h.jumpUrl(`/pages2/message/list?title=${_.title}&type=${_.type}`) : proxy.$h.jumpUrl(_.url))

onShow(() => getDataHandler())
</script>

<style lang="scss" scoped>
.message {
  box-sizing: border-box;
  padding: 40rpx 24rpx;
  image {
    width: 108rpx;
    height: 108rpx;
    border-radius: 50%;
    margin-right: 20rpx;
  }
  &-title {
    color: #323233;
    font-size: 36rpx;
    font-weight: 700;
    margin-bottom: 8rpx;
    width: fit-content;
  }
  &-text {
    width: 50vw;
    color: #666666;
    font-size: 26rpx;
    @include oneLine(2);
  }
  &-time {
    color: #999999;
    font-size: 26rpx;
    margin-bottom: 12rpx;
    width: max-content;
  }
  .poBox {
    position: relative;
  }
  &-badge {
    box-sizing: border-box;
    padding: 1rpx 8rpx;
    background: #f44d36;
    border-radius: 50%;
    color: #ffffff;
    font-size: 20rpx;
    position: absolute;
    top: 0;
    right: 14rpx;
  }
}
</style>