system-notify.vue 4.12 KB
<template>
	<view class="notify-page">
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<view class="notify-page-top-select">
			<view @click="handleTypeClick" class="top-select">
				<u--input suffixIcon="arrow-down" shape="circle" disabled v-model="notifyType"
					:placeholder="$t('userCenter.pleaseSelectType')" border="surround"></u--input>
				<u-action-sheet safe-area-inset-bottom :show="showType" :actions="actions.map(item=>({...item,name:$t(item.name)}))" :title="$t('userCenter.pleaseSelectType')" @close="showType = false"
					@select="handleTypeSelect"></u-action-sheet>
			</view>
		</view>
		<view style="height: 110rpx;"></view>
		<view class="notify-main">
			<mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback"
				@up="upCallback">
				<view class="u-flex main">
					<view @click="handleNotifyDetail(item, index)" class="u-flex main-item" v-for="(item, index) in list"
						:key="index">
						<view class="u-flex item">
							<view class="item-avatar">
								<u-avatar class="avatar" shape="circle" size="40" :src="item.sysNotice.avatar">
								</u-avatar>
							</view>
							<view class="u-flex item-content">
								<text class="text-top text-clip">{{ item.sysNotice.title }}</text>
								<text class="text-bottom text-clip">{{ item.sysNotice.senderDate }}</text>
							</view>
						</view>
						<view class="item-right u-flex" style="justify-content: space-between;">
							<text class="text">{{ formatType(item.sysNotice.type) }}</text>
							<!-- readStatus===0则阅读状态表示未阅读 -->
							<u-badge style="margin-right: 10rpx;" v-if="item.readStatus == '0'" numberType="overflow"
								isDot />
						</view>
					</view>
				</view>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
	import api from '@/api/index.js'
	import { useNavigateTo } from '@/plugins/utils.js'
	import { actions } from './config/data.js'

	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				notifyType:'',
				showType: false,
				actions,
				page: {
					page: 0,
					pageSize: 10
				},
				downOption: {
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				list: [],
				selectType: '',
				distance: 0,
			};
		},
		onShow(){
			this.$nextTick(()=>{
				uni.setNavigationBarTitle({
					title:this.$t('menu.systemNot')
				})
			})
		},
		onLoad(e) {
			// 隐藏原生的tabbar
			uni.hideTabBar();
		},
		methods: {
			formatType(e) {
				const findName = this.actions.find((item)=>item.value===e && item.value!=='')
				if(!findName) return
				return this.$t(findName.name)
			},
			handleTypeClick() {
				this.showType = true;
				uni.hideKeyboard();
			},
			handleTypeSelect(e) {
				this.selectType = e.value;
				this.page.page = 1;
				this.notifyType = e.name;
				this.loadData(1, !this.selectType ? null : this.selectType);
			},
			downCallback() {
				this.list.length = 0;
				this.page.page = 1;
				this.loadData(1);
				this.selectType = '';
				this.notifyType = '';
			},
			upCallback() {
				if (this.selectType) {
					this.page.page += 1;
					this.loadData(this.page.page, this.selectType);
				} else {
					this.page.page += 1;
					this.loadData(this.page.page);
				}
			},
			async loadData(page, type) {
				let params = {
					page,
					pageSize: 10,
					type
				};
				const res = await api.notifyApi.getNotifyApi({
					params,
					custom: {
						load: false
					}
				})
				uni.stopPullDownRefresh();
				this.mescroll.endByPage(res.items.length, res.total);
				if (page == 1) {
					this.list = res.items;
				} else {
					this.list = this.list.concat(res.items);
				}
			},
			async handleNotifyDetail(item, index) {
				this.list[index].readStatus = 1;//点击了则说明阅读了
				await api.notifyApi.byNotifyIdGetDetailApi(item.sysNotice.id)
				useNavigateTo('./notify-detail?data=', item.sysNotice)
			}
		}
	};
</script>

<style lang="scss" scoped>
	@import './static/systemNotify.scss';

	::v-deep .u-badge--error {
		position: relative;
		right: 11rpx;
	}
</style>