<template>
	<view class="container">
		<view class="page">
			<view class="complaints" v-if="maintenanceList.length !== 0">
				<view class="information" v-for="item in maintenanceList" :key="item.id" @click="toDetail(item.id)">
					<view class="title" :class="item.handleStatus === 'finish' ? 'gray' : 'yellow'">{{item.complaintTheme}}<view class="tag">{{item.statusName}}</view>
					</view>
					<view class="content">
						<view class="item">
							<view class="name">投诉人</view>
							<view class="detail">{{item.userName}} {{item.userPhone}}</view>
						</view>
						<view class="item">
							<view class="name">投诉时间</view>
							<view class="detail">{{item.complaintTime}}</view>
						</view>
					</view>
				</view>
			</view>
			<no-data :show="maintenanceList.length === 0" text="暂无投诉信息"></no-data>
		</view>
		<view class="form-submit-fixed">
			<view class="form-submit" @click="toEditor()">新增投诉</view>
		</view>
	</view>
</template>

<script>
	import {
		getCommunityComplaintListApi,
	} from '@/config/api.js'
	import {Moment} from '@/utils/moment.js'
	import noData from '@/components/no-data/no-data'
	const handleStatus = {
		waitPending: '待处理',
		pending: '处理中',
		finish: '处理完成'
	}
	export default {
		components: {noData},
		data() {
			return {
				maintenanceList: []
			}
		},
		methods: {
			toDetail(id) {
				uni.navigateTo({
					url: '/pages/complaintsDetail/index?id=' + id
				});
			},
			toEditor() {
				uni.navigateTo({
					url: '/pages/complaintsAdd/index',
				});
			},
			async getList() {
				let {result} = await getCommunityComplaintListApi()
				this.maintenanceList = result.records.map(item=> {
					return {
						...item,
						statusName: handleStatus[item.handleStatus],
						complaintTime: new Moment(new Date(item.createTime).getTime()).format('YYYY-MM-DD HH:mm'),
					}
				})
			}
		},
		onLoad() {
			this.getList()
		},
		onShow() {

		}
	}
</script>
<style>
	page {
		background-color: #F8F6F9;
	}
</style>
<style lang="scss" scoped>
	.complaints {
		padding: 30rpx 30rpx 90rpx;
		background-color: #F8F6F9;
		.information {
			background-color: #ffffff;
			border-radius: 16rpx;
			padding: 30rpx;
			margin-bottom: 30rpx;

			.title {
				height: 40rpx;
				line-height: 40rpx;
				padding-left: 20rpx;
				font-size: 32rpx;
				color: #373737;
				font-weight: bold;
				margin-bottom: 30rpx;

				.tag {
					font-size: 22rpx;
					padding: 2rpx 20rpx;
					border-radius: 30rpx;
					display: inline-block;
					float: right;
				}
			}

			.yellow {
				border-left: 2px solid #F1BD4D;

				.tag {
					color: #F1BD4D;
					border: 1px solid #F1BD4D;
					background-color: #FFFCF6;
				}
			}

			.gray {
				border-left: 2px solid #B6B6BA;

				.tag {
					color: #B6B6BA;
					border: 1px solid #B6B6BA;
					background-color: #F8F8F8;
				}
			}

			.content {
				border-top: 1px solid #F0F0F2;
				padding-top: 20rpx;

				.item {
					display: flex;
					height: 70rpx;
					line-height: 70rpx;

					.name {
						width: 35%;
						font-size: 28rpx;
						color: #CECED3;
					}

					.detail {
						font-size: 28rpx;
						color: #373737;
					}
				}
			}

		}
	}

	.form-submit-fixed {
		position: fixed;
		width: 100%;
		bottom: 10rpx;
	}

	.form-submit {
		margin: 0 30rpx;
		box-sizing: border-box;
		height: 80rpx;
		line-height: 80rpx;
		background-color: #6A59F2;
		border-radius: 80rpx;
		text-align: center;
		font-size: 28rpx;
		color: #FFFFFF;
	}
</style>