<template>
	<view>
		<!-- <mescroll-body  :up="upOption" ref="mescrollRef" @init="mescrollInit" @up="upCallback" @down="downCallback"> -->
			
			<view v-for='item in noticeList'>
				<view class="">
					<view>{{item.newsTitle}}</view>
					<view>{{parseTime(item.gmtCreate)}}</view>
				</view>
				<view>{{item.newsContent}}</view>
			</view>
		<!-- </mescroll-body> -->
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				noticeList:[],
				unreadList:[]
			};
		},
		onShow() {
			this.getList()
		},
		methods:{
			getList(){
				var that = this
				uni.showLoading({
						title: '数据加载中'
					})
				this.$request.baseRequest('admin.unimall.cardNewsInfo', 'list',{
					receiveId:uni.getStorageSync("userInfo").id,
				}, failres => {
					console.log('res+++++', failres.errmsg)
					this.$refs.uToast.show({
						type: 'error',
						message: failres.errmsg,
					})
					uni.hideLoading()
				}).then(res => {
					console.log(res)
					let curPageLen = res.data.items.length;
					let totalPage = res.data.total;
					this.noticeList=res.data.items
					if(this.noticeList.length>0){
						var data=this.noticeList.filter((item)=>{return item.newsFlag==0})
						this.unreadList=data
						if(this.unreadList.length>0){
							for(var i=0;i<this.unreadList.length;i++){
								this.unreadList[i].newsFlag=1
								this.$request.baseRequest('admin.unimall.cardNewsInfo', 'update',{
									cardNewsInfo:JSON.stringify(this.unreadList[i]),
								}, failres => {
									console.log('res+++++', failres.errmsg)
									this.$refs.uToast.show({
										type: 'error',
										message: failres.errmsg,
									})
									uni.hideLoading()
								}).then(res => {})
							}
							
						}
					}
					
					uni.hideLoading()
				})
			},
		}
		
	}
</script>

<style lang="scss">

</style>
