<template>
	<view class="container">
	  <view class="main">
	    <view :class="['item', index === tipsList.length - 1 && 'no_border']" v-for="(item, index ) in tipsList" :key="index" :data-item="item" @click="headerNoticeClick">
	      <image class="left_pic" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/ConvenServer/_assets/Group_476.png" mode=""/>
	      <view class="center">
	        <view class="title">{{item.title}}</view>
	        <view class="center_bottom">
	          <view class="center_bottom_item">
	            <image class="center_bottom_item_pic" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/User/_assets/location.png" mode=""/>
	            <view class="center_bottom_item_desc">{{title}}</view>
	          </view>
	          <view class="center_bottom_item">
	            <image class="center_bottom_item_pic" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/community/_assets/Alarm-clock.png" mode=""/>
	            <view class="center_bottom_item_desc">{{item.intro}}</view>
	          </view>
	        </view>
	      </view>
	      <view class="right">
	        <image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/User/_assets/more.primary.12x22.png" mode="" class="right_pic"/>
	      </view>
	    </view>
	  </view>
	</view>
</template>

<script>
	import { request, NavgateTo } from '../../../utils';
	import { apiArr } from '../../../api/community';
	
	export default {
		data() {
			return {
				isOnshow: false,
				noticeList: [],
				page_num: 1,
				tipsList: [],
				title: '',
				id: '',
			}
		},
		methods: {
			async init(id) {
				const res = await request(apiArr.tipsList, 'POST', {
					community_id: Number(id),
					page_num: this.page_num || 1,
					page_size: 10,
				});
				
				let flag = false;
				if (res?.rows && res?.rows?.length == this.page_size) {
					flag = true
				} else {
					flag = false
				}
				
				console.log('ressss', res);
				this.tipsList = this.tipsList.concat(res?.rows || []);
				this.page_num = this.page_num + 1;
				this.flag = flag;
				this.isOnshow = true;
			},
			
			
			headerNoticeClick(event) {
				const { item } = event.currentTarget.dataset;
				NavgateTo(`/packages/community/desc/desc?id=${item.news_id}&title=${item.title}`)
			},
			
		},
		
		onLoad(options) {
			// 基于父页面传递参数设置页面名称
			uni.setNavigationBarTitle({
				title: options.title,
			})
			this.title = options?.title;
			this.id = options?.id;
			this.init(options.id);
	},
		
		onShow() {
			if (this.isOnshow) {
				this.page_num = 1;
				this.tipsList = [];
				this.flag = false;
				this.init(this.id);
			}
		},
		
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom() {
			if (this.flag) {
				this.init(this.id);
			}
		},
	}
</script>

<style>
	@import url("./index.css");
</style>
