<template>
	<view class="my-notice-box">
		<!-- 标题 -->
		<view class="dl-title">
			我的通告
		</view>
		<!-- 搜索框 -->
		<view class="dl-search-box">
			<uni-search-bar placeholder="请输入搜索内容" style="width: 100%;" @confirm="clear"
				v-model="queryParams.searchValue" @clear="search" @cancel="clear">
			</uni-search-bar>
		</view>
		<!-- 菜单 -->
		<view class="dl-menu-box">
			<view v-for="(item,index) in menus" @click="itemClick(index,item)" class="dl-menu"
				:class="index==menuIndex?'dl-menu click':'dl-menu'">{{item}}</view>
		</view>
		<!-- 通告列表 -->
		<view class="dl-body">
			<view class="dl-item-box">
				<scroll-view style="height: 100%;" scroll-y="true" @scrolltolower="onReachBottomCus" refresher-enabled
					@refresherrefresh="onRefresherrefresh" :refresher-triggered="isTriggered">
					<my-notice-item v-if="dataList.length>0" :dataList="dataList"></my-notice-item>
					<view style="text-align: center" v-if="dataList.length==0">
						<image class="" src="@/static/images/nothing.png"></image>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		toast,
		hasRights
	} from '@/utils/common.js'
	import myNoticeItem from '@/pages/components/my-notice-item.vue'
	import {
		myNoticeList
	} from '@/api/business/notice.js'
	import rightsCode from '@/utils/rightsCode'
	import {
		getCatgByCode
	} from '@/api/system/config.js'
	export default {
		components: {
			myNoticeItem
		},
		data() {
			return {
				menus: ['全部', '审核中', '已通过', '未合作'],
				menuIndex: 0,
				dataList: [],
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					searchValue: ""
				},
				total: 0,
				//下来刷新状态
				isTriggered: false,
			}
		},
		mounted() {
			this.initData("dl_platform", "platformList")
			this.initData("dl_blogger_type", "bloggerTypeList")
			this.selectDataList()
		},
		methods: {
			/**
			 * 初始化数据
			 * @param {Object} code
			 * @param {Object} dataObj
			 */
			initData(code, dataObj) {
				let that = this
				getCatgByCode({
					code: code
				}).then(res => {
					if (res.code == 200) {
						this[dataObj] = res.data
					}
				}).catch((e) => {
					uni.showToast({
						icon: 'error',
						duration: 2000,
						title: e
					});
				})
			},
			/**
			 * 查询数据
			 */
			selectDataList() {
				myNoticeList(this.queryParams).then(res => {
					this.isTriggered = false
					if (res.code == 200) {
						if (this.queryParams.pageNum == 1) {
							this.dataList = res.data.records
						} else {
							this.dataList = this.dataList.concat(res.data.records)
						}
						this.total = res.data.total
					}
				}).catch((e) => {
					this.isTriggered = false
					uni.showToast({
						icon: 'error',
						duration: 2000,
						title: e
					});
				})
			},
			/**
			 * 搜索框搜索
			 * @param {Object} res
			 */
			search(res) {
				this.queryParams.pageNum = 1
				this.total = 0
				this.selectDataList()
			},
			clear(res) {
				this.queryParams.pageNum = 1
				this.total = 0
				this.queryParams.searchValue = ""
				this.selectDataList()
			},
			/**
			 * 查看通告详情
			 * @param {Object} item
			 */
			goDetail(item) {
				this.$tab.navigateTo(`/pages/notice/detail?id=${item.id}`)
			},
			/**
			 * 菜单点击
			 * @param {Object} index
			 * @param {Object} item
			 */
			itemClick(index, item) {
				this.menuIndex = index
				this.queryParams.reportStatus = item
				this.queryParams.pageNum = 1
				this.total = 0
				this.selectDataList()
			},
			/**
			 * 上滑加载数据
			 */
			onReachBottomCus() {
				//判断 如果页码*页容量大于等于总条数，提示该页数据加载完毕
				if (this.queryParams.pageNum * this.queryParams.pageSize >= this.total) {
					toast("没有更多数据了")
					return
				}
				//页码+1,调用获取数据的方法获取第二页数据
				this.queryParams.pageNum++
				this.selectDataList()
			},
			/**
			 * 下拉刷新数据
			 */
			onRefresherrefresh() {
				this.isTriggered = true
				this.queryParams.pageNum = 1
				this.total = 0

				this.selectDataList()
			},
		}
	}
</script>

<style lang="scss">
	.my-notice-box {
		// padding-top: var(--status-bar-height);
		width: 100%;
		color: #363636;
		background-color: white;
		font-size: 38rpx;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: start;
		position: relative;

		.dl-title {
			padding-top: calc(var(--status-bar-height) + 62rpx);
			padding-left: 15rpx;
			padding-bottom: 15rpx;
			font-size: 32rpx;
			width: 100%;
			position: relative;
			text-align: center;
			font-weight: bold;
			z-index: 10;
			// padding: 62rpx 0 15rpx 15rpx;
			border-bottom: 1px solid #F4F4F4;
		}

		.dl-search-box {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			padding: 10rpx 20rpx 0 20rpx;
		}

		.dl-menu-box {
			border-bottom: 1rpx solid #EEEEEE;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			padding-top: 20rpx;

			.dl-menu {
				flex-grow: 1;
				font-size: 30rpx;
				margin: 0 20rpx;
				padding-bottom: 12rpx;
				text-align: center;
			}

			.click {
				color: #FF434E;
				font-weight: bold;
				border-bottom: 3px solid #FF434E;
			}
		}

		.dl-body {
			flex: 1;
			width: 100%;
			height: 100%;
			background-color: #EEEEEE;
			padding: 0 20rpx 0 20rpx;

			.dl-item-box {
				height: calc(100vh - var(--status-bar-height) - var(--window-bottom) - 440rpx);
				isplay: flex;
				flex-direction: column;
			}
		}
	}
</style>