<template>
	<view class="page">
		<!-- <view class="head">
			<view class="logo-title">
				<image @click="goBack" src="../../static/left.png"></image>
				公告通知
			</view>
			<view class="title">
			</view>
			<view class="setting-mess"></view>
		</view> -->
		<view class="toptitle" style="margin-bottom: -50px;">
			<view class="toptitle_left" @click="goBack">
				<u-icon name="arrow-left" color="#fff" size="20"></u-icon>
			</view>
			<view class="toptitle_title">
				公告
			</view>
		</view>
		<view class="main">
			<view class="address-list">
				<view class="list" v-for="(item,index) in list" :key="index" @click="noticeDetail(item)">
					<view class="name-phone">
						<view class="name">
							<view class="name-title">{{item.title}}</view>
							<view v-html="item.titles"></view>
						</view>
						<view class="edit" style="display: flex;justify-content: flex-end;text-align: right;">
							<span>{{item.createtime}}</span>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					page: 1
				},
				list: [],
				lastPage: 0,
				title:"公告通知"
			};
		},
		onReachBottom() {
			if (this.form.page < this.lastPage) {
				this.form.page += 1;
				this.ggtzlb();
			}
		},
		onLoad(e) {
			this.ggtzlb();
		},
		methods: {
			getTime(data, type) { //data时间戳，type返回的类型默认Y,可传参Y和H
				let time = new Date(data * 1000);
				let Y = time.getFullYear();
				let Mon = time.getMonth() + 1;
				let Day = time.getDate();
				let H = time.getHours();
				let Min = time.getMinutes();
				let S = time.getSeconds();
				//自定义选择想要返回的类型
				if (type === "Y") { //返回年月日2020-10-10
					return `${Y}-${Mon}-${Day}`
				} else if (type === "H") { //返回时分秒20：10：10
					return `${H}:${Min}:${S}`
				} else { //返回年月日时分秒2020-10-10 10:26:38
					return `${Y}-${Mon}-${Day} ${H}:${Min}:${S}`
				}
			},
			ggtzlb() {
				this.API.ggtzlb(this.form).then(res => {
					console.log("列表", res);
					if (res.data.data.length > 0) {
						for (let i = 0; i < res.data.data.length; i++) {
							res.data.data[i].createtime = this.getTime(res.data.data[i].createtime)
							this.list.push(res.data.data[i])
						}
					}
					this.lastPage = res.data.last_page
				})
			},
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			noticeDetail(item) {
				uni.setStorageSync('gginfo',item)
				uni.navigateTo({
					url: '/pages/noticeDetail/noticeDetail'
				})
			},
		}
	}
</script>

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