<template>
	<view class="container">
		<view class="page" v-if="noticeList.length">
			<view class="item" v-for="(item, index) in noticeList" :key="item.id" @click="toDetail(item, index)">
				<view class="top">
					<view class="title">
						<view class="point" v-if="item.noticeStatus === '0'"></view>
						<view class="name">{{item.noticeTitle}}</view>
					</view>
					<image src="../../static/images/icon_more.png" class="arrow"></image>
				</view>
				<view class="con">{{item.noticeContent}}</view>
			</view>
		</view>
		<no-data :show="noticeList.length === 0" text="暂无消息"></no-data>
	</view>
</template>

<script>
import {
	getUserNoticeListApi,
	updateStatusApi
} from '@/config/api.js'
import noData from '@/components/no-data/no-data'
export default {
	components: {noData},
	data() {
		return {
			noticeList: []
		}
	},
	methods: {
		toDetail(row, index) {
			if(row.busType === 'repair') {	// 维修
				uni.navigateTo({
					url: `/pages/maintenanceAaudit/index?id=${row.busId}`
				});
			} else if(row.busType === 'complaint') {	// 投诉
				uni.navigateTo({
					url: '/pages/complaintsDetail/index?id=' + row.busId
				});
			} else {	// 缴费
				uni.navigateTo({
					url: `/pages/payCostDetails/index?id=${row.busId}`,
				});
			}
			if(this.noticeList[index].noticeStatus === '0') {
				this.noticeList[index].noticeStatus = '1'
				updateStatusApi({id: row.id, noticeUserId: row.noticeUserId})	// 更改消息状态
				var pages = getCurrentPages();
				var page = pages[pages.length - 2];
				page.$vm.communityInfo.noticeNotRead -= 1
			}
		},
		async getList() {
			let {result} = await getUserNoticeListApi()
			this.noticeList = result.records
		}
	},
	onLoad(option) {
		this.getList(option.id)
	}
}
</script>
<style>
	page {
		background-color: #F8F6F9;
	}
</style>
<style lang="scss" scoped>
	// .page {
	// 	padding: 30rpx;
	// }

	.page {
		padding: 30rpx;

		.item {
			background-color: #ffffff;
			border-radius: 16rpx;
			padding: 30rpx;
			margin-bottom: 30rpx;

			.top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding-bottom: 20rpx;
				margin-bottom: 30rpx;
				border-bottom: 1px solid #F0F0F2;

				.title {
					display: flex;
					align-items: center;

					.point {
						width: 14rpx;
						height: 14rpx;
						background-color: #F6C864;
						border-radius: 14rpx;
					}

					.name {
						font-size: 32rpx;
						color: #373737;
						margin-left: 20rpx;
					}
				}

				.arrow {
					width: 16rpx;
					height: 24rpx;
				}
			}

			.con {
				font-size: 28rpx;
				color: #9D9CA6;
			}

		}

	}
</style>