<template>
	<view class="notice_main">
		<z-paging ref="paging" v-model="listData" @query="queryList" style="padding-top: 100rpx;" :auto="false">
			<template slot="top">
				<nav-bar title='专家讲座'></nav-bar>
				<van-cell-group style="margin-top: 24rpx;">
				  <van-field v-model="value" label="选择园区" placeholder="请选择园区" clickable readonly @click="showPicker = true" :right-icon="showPicker?'arrow-up':'arrow-down'" />
				</van-cell-group>
			</template>
			<view class="notice_item" v-for="(item,index) in listData" :key="index" @click="jumpDetail(item)">
				<view class="title">{{item.noticeName}}</view>
				<view class="tips">
					<image src="/static/firstaid/time-1.png"></image>
					<view class="left">发布时间</view>
					<view class="right">{{item.createdTime}}</view>
				</view>
				<view class="tips">
					<image src="/static/firstaid/location.png"></image>
					<view class="left">活动地点</view>
					<view class="right">{{item.parkTypeName}}</view>
				</view>
			</view>
			
			<van-popup v-model="showPicker" round position="bottom">
			  <van-picker
			    title="选择园区"
			    show-toolbar
			    :columns="option1"
			    @confirm="onConfirm"
					value-key="dataValue"
					@cancel="showPicker = false"
			  />
			</van-popup>
			
		</z-paging>
	</view>
</template>

<script>
	import navBar from "@/components/navBar/index.vue";
	import {
		callbackRequest
	} from '@/common/util.js';
	import {
		noticeList,
		noticePark
	} from '@/common/api.js';
	export default {
		components: {
			navBar
		},
		data() {
			return {
				listData: [],
				value: '',
				option1: [],
				showPicker: false,
				parkType: ''
			}
		},
		onLoad() {
			this.getParkType()
		},
		methods: {
			getParkType() {
				let params = {
					method: noticePark,
					dataType: 'park_type'
				}
				callbackRequest(params).then((res) => {
					if (res.returnCode == 1) {
						this.option1 = res.returnData
						console.log(this.option1)
						if(this.option1.length > 0) {
							this.value = this.option1[0].dataValue
							this.parkType = this.option1[0].dataCode
							this.$nextTick(() => {
								this.$refs.paging.reload()
							})
						}
					} else {
						uni.showToast({title: res.returnMsg,icon: 'none'});
					}
				})
			},
			
			queryList(pageNo, pageSize) {
				let params = {
					method: noticeList,
					currentPage: pageNo,
					isDeleted: "0",
					limit: pageSize,
					noticeName: "",
					publishStatus: "1",
					noticeName: "",
					noticeType: "1",
					parkType: this.parkType
				}
				callbackRequest(params).then((res) => {
					if (res.returnCode == 1) {
						if(pageNo * pageSize >= res.returnData.total) {
							this.$refs.paging.completeByNoMore(res.returnData.records,true);
							return
						}else{
							this.$refs.paging.completeByNoMore(res.returnData.records,false);
						}
					} else {
						uni.showToast({title: res.returnMsg,icon: 'none'});
					}
				})
			},
			
			onConfirm(e) {
				this.value = e.dataValue
				this.parkType = e.dataCode
				this.showPicker = false
				this.$nextTick(() => {
					this.$refs.paging.reload()
				})
			},

			jumpDetail(item) {
				uni.navigateTo({
					url: `/pages/device/noticeDetail?id=${item.id}`
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.notice_main {
		height: 100vh;
		width: 100vw;
		background-color: #F2F6FA;
	}
	.notice_main::-webkit-scrollbar {
			width: 0;
			height: 0;
		}
	.notice_item {
		width: calc(100% - 48rpx);
		background: #FFFFFF;
		border-radius: 18rpx;
		margin-left: 50%;
		transform: translateX(-50%);
		margin-top: 24rpx;
		padding: 26rpx 24rpx;
		box-sizing: border-box;
		.title {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 32rpx;
			color: #0E1A24;
			text-align: left;
			margin-bottom: 24rpx;
		}
		.tips {
			display: flex;
			align-items: center;
			margin-top: 12rpx;
			image {
				width: 30rpx;
				height: 30rpx;
				display: block;
				margin-right: 12rpx;
			}
			.left {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 30rpx;
				color: #4B5B68;
				margin-right: 24rpx;
			}
			.right {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 30rpx;
				color: #0E1A24;
			}
		}
	}
</style>