message.vue 3.8 KB
<template>
	<view class="main">
		<u-swiper :list="imgList" @change="change" @click="click"></u-swiper>
		<view class="items" v-for="item in list">
			<view class="">
				<image src="/static/icon/1816.png" v-if="item.type == 1"
					style="width: 80rpx; height: 80rpx;margin-right:16rpx" mode=""></image>
				<image src="/static/icon/1815.png" v-else-if="item.type == 2"
					style="width: 80rpx; height: 80rpx;margin-right:16rpx" mode=""></image>
				<image src="/static/icon/Group 1813@2x.png" v-else style="width: 80rpx; height: 80rpx;margin-right:16rpx"
					mode=""></image>
			</view>
			<view style="display: flex;flex-direction: column;width: 100%;">
				<view class=" flexB" style="margin-bottom: 10rpx;">
					<p style="color: #0d1013e6;font-size: 32rpx;font-weight: 500;">{{item.title}}</p>
					<p class="font">{{item.createtime}}</p>
				</view>
				<view class="flexB">
					<p class="one font">{{item.content}}</p>
					<p class="dian"></p>
				</view>
			</view>
		</view>
		<view class="">
			<u-loadmore :status="status" :load-text="loadText" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				imgList: [],
				status: 'loadmore',
				loadText: {
					loadmore: '轻轻上拉加载更多...',
					loading: '努力加载中...',
					nomore: '没有更多了'
				},
				page: 1,
			}
		},
		methods: {
			formattedDate(timestamp) {
				const date = new Date(timestamp);
				const year = date.getFullYear();
				const month = (date.getMonth() + 1).toString().padStart(2, '0');
				const day = date.getDate().toString().padStart(2, '0');
				const formattedDate = `${year}-${month}-${day}`;
				return formattedDate
			},
			change() {

			},
			click(e) {
				console.log(e);
				if (this.imgList[e].type == 2) {
					uni.navigateTo({
						url: `/pages/subPages/outer?url=${this.imgList[e].image}`
					})
				} else {
					uni.navigateTo({
						url: `/pages/subPages/detail?id=${this.imgList[e].equip_id}`
					})
				}

			},
			getList() {
				uni.$u.http.post('/api/message/msg_list', {
					page: this.page,
					pagenum: 10
				}).then(res => {
					this.status = 'loadmore'
					if (this.page === 1) {
						this.list = []
					}
					res.data.data.forEach(data => {
						this.list.push(data)
					})
					if (this.list.length < 10) this.status = 'nomore';
					else this.status = 'loading';
				}).catch(err => {
					console.log(err);
				})
			},
			getBanner() {
				uni.$u.http.get('/api/message/banner').then(res => {
					console.log(res);
					this.imgList = res.data.map(item => {
						return {
							url: item.image_url,
							image: item.url,
							equip_id: item.equip_id,
							type: item.type
						}
					})
				}).catch(err => {
					console.log(err);
				})
			}
		},

		onReachBottom() {
			this.status = 'loading';
			this.page = this.page + 1;
			this.getList()
		},

		onLoad() {
			let token = uni.getStorageSync('token')
			if (token) {
				this.getList()
				this.getBanner()
			} else {
				uni.showToast({
					title: '请登陆后重试',
					icon: 'none'
				})

				setTimeout(() => {
					uni.redirectTo({
						url: '/pages/index/login'
					})
				}, 2000)
			}

		}
	}
</script>

<style scoped lang="scss">
	.font {
		color: #0d101366;
		font-size: 26rpx;
		font-weight: 400;
	}

	.flexB {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.main {
		padding: 24rpx;
	}

	.one {
		width: 450rpx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.items {
		display: flex;
		align-items: center;
		height: 156rpx;
		border-radius: 12rpx;
		opacity: 1;
		background: #ffffffff;
		padding: 0 24rpx;
		margin-top: 20rpx;
	}

	.dian {
		width: 14.4rpx;
		height: 14.4rpx;
		border-radius: 35.2rpx;
		opacity: 1;
		border: 2rpx solid #ffffffff;
		background: #fc4338ff;
	}
</style>