<template>
	<view class="page">
		<uni-nav-bar @clickLeft="goto(1, 1)" left-icon="back"  :border="false" :shadow="false" :fixed="true"
		:title="$t('notice.title')" backgroundColor="#fff">
			<template v-slot:right>
			    <span style="font-size: 28rpx;" @click="allRead">{{$t('notice.text1')}}</span>
			</template>
		</uni-nav-bar>
		<view style="width: 92%; margin: 20rpx auto;" v-if="list.length > 0">
			<view class="cell_list" v-for="item in list" :key="item.id" style="margin-top: 20rpx; border-radius: 20rpx;" @click="onPageJump(item.id)">
				<view class="t">
					<view>
						<span v-if="item.is_read == 0" style="background-color: #FF4E4E; display: block;margin-right: 20rpx; width: 16rpx; height: 16rpx; border-radius: 10rpx; float: left; margin-top: 14rpx;"></span>
						<span style="font-size: 32rpx; color: #3d3d3d; font-weight: 600; float: left;">{{item.title}}</span>
					</view>
					<view class="d">{{item.intro}}</view>
					<view class="d">{{item.created_at}}</view>
				</view>
				<view class="cell_right arrow"></view>
			</view>
			
		</view>
		<view style="text-align: center; padding-bottom: 160rpx;" v-if="list.length == 0">
			<image style="width: 360rpx; height: 360rpx; margin: 160rpx auto 0rpx auto;" src="/static/images/w5.png" mode="cover"></image>
			<view style="color: #999; font-size: 28rpx; font-weight: 400;">{{$t('nodata')}}</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				list: [],
				page: 1,
				limit: 10,
			};
		},
		computed: {
			...mapState(['userInfo'])
		},
		//第一次加载
		onLoad(e) {
			this.getnotice();
		},
		//页面显示
		onShow() {},
		//方法
		methods: {
			getnotice(){
				let data = {
					category_id: 10,
					page: this.page,
					limit: this.limit,
					lang: this.$i18n.locale
				}
				this.$http.post('/api/article/list', data).then(res => {
					if(res.code == 0){
						res.data.data.forEach(item => {
							this.list.push(item);
						})
					}
				});
			},
			goto(url, type) {
			    if (type == 2) {
			        return uni.switchTab({ url: url })
			    }
			    if (type == 1) {
			        return uni.navigateBack({ delta: url });
			    }
			    uni.navigateTo({
			        url: url
			    })
			},
			allRead(){
				let ids = this.list.filter(item => item.is_read == 0).map(item => item.id);
				if(ids.length > 0){
					this.$http.get('/api/article/mask_as_read?id='+ids.join(',')+'&lang='+this.$i18n.locale).then(res => {
						if(res.code == 0){
							uni.showToast({
								title: "Success"
							})
							this.list.filter(item => item.is_read == 0).forEach(unRead => {
								unRead.is_read = 1;
							});
						}
					});
				}else{
					uni.showToast({
						title: "Success"
					})
				}
			},
			onPageJump(id) {
				uni.navigateTo({
					url: '/pages/mine/noticedetails?id=' + id
				});
			},
		},
		//页面隐藏
		onHide() {},
		//页面卸载
		onUnload() {},
		//页面下来刷新
		onPullDownRefresh() {
			//console.log(111);
		},
		//页面上拉触底
		onReachBottom() {
			this.page = this.page + 1;
			let data = {
				category_id: 10,
				page: this.page,
				limit: this.limit,
				lang: this.$i18n.locale
			}
			this.$http.post('/api/article/list', data).then(res => {
				if(res.code == 0){
					res.data.data.forEach(item => {
						this.list.push(item);
					})
				}
			}).catch(err => {
				this.page = this.page - 1;
			});
		},
		//用户点击分享
		onShareAppMessage(e) {
			return this.wxShare();
		}
	};
</script>
<style lang="scss" scoped>
	@import '@/style/mixin.scss';
	body{background-color: #F8F8F8;}
	.page{ min-height: 100vh;background-color: #F8F8F8;}
	.wallet1{
		border-radius: 20rpx; padding: 40rpx 30rpx; width: 84%; margin: 20rpx auto;
		background: url('/static/images/w1.png') #2B66F6; background-repeat: no-repeat; background-position: 92% 10rpx;
	}
	.cell_list .t{
		color: #3d3d3d; font-size: 32rpx; font-weight: 400; line-height: 50rpx;
	}
	.cell_list .d{
		color: #999; font-size: 24rpx; font-weight: 400; line-height: 40rpx; clear: both;
	}
	.cell_list .u{
		color: #1D61E7; font-weight: 600;float: right; font-size: 32rpx;
	}
	.cell_list .u1{
		color: #333; font-weight: 600;float: right;font-size: 32rpx;
	}
	.w{
		background-color: #F8F8F8; border-radius: 20rpx; padding: 40rpx 20rpx;
	}
	.w .t{
		text-align: center; margin-top: 20rpx; font-size: 28rpx;
	}
</style>