<template>
	<view class="container">
		<view class="page">
			<view class="complaints">
				<view class="information">
					<view class="title">{{complaintsDetail.complaintTheme || ''}}</view>
					<view class="content">
						<view class="item">
							<view class="name">投诉人</view>
							<view class="detail">{{complaintsDetail.userName || ''}}</view>
						</view>
						<view class="item">
							<view class="name">投诉时间</view>
							<view class="detail">{{complaintsDetail.complaintTime || ''}}</view>
						</view>
						<view class="item">
							<view class="name">联系方式</view>
							<view class="detail">{{complaintsDetail.userPhone || ''}}</view>
						</view>
						<view class="item text">
							<view class="name">问题描述</view>
							<view class="detail">{{complaintsDetail.problemDesc || ''}}</view>
						</view>
						<view class="item">
							<view class="name">状态</view>
							<view class="detail" :class="item.handleStatus === 'finish' ? 'gray' : 'yellow'"><view class="tag">{{complaintsDetail.statusName}}</view></view>
						</view>
						<view class="item text" v-if="complaintsDetail.handleStatus === 'finish'">
							<view class="name">处理结果</view>
							<view class="detail">{{complaintsDetail.handleResult}}</view>
						</view>
						<view class="item text">
							<view class="name">附件</view>
							<view class="image">
								<image v-for="(item,index) in complaintsDetail.complaintImg" :key="index" :src="item" class="icon"></image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCommunityComplaintDetailApi
	} from '@/config/api.js'
	import {Moment} from '@/utils/moment.js'
	const handleStatus = {
		waitPending: '待处理',
		finish: '处理完成'
	}
	export default {
		data() {
			return {
				complaintsDetail: {
					complaintTheme: '',
					userName: '',
					userPhone: '',
					problemDesc: '',
					handleStatus: '',
					statusName: '',
					complaintImg: []
				}
			}
		},
		methods: {
			async getDetail(id) {
				let {result} = await getCommunityComplaintDetailApi({id})
				this.complaintsDetail = {
					...result,
					complaintImg: result.complaintImg.split(','),
					complaintTime: new Moment(new Date(result.createTime).getTime()).format('YYYY-MM-DD HH:mm'),
					statusName: handleStatus[result.handleStatus]
				}
			}
		},
		onLoad(options) {
			if(options.id) {
				this.getDetail(options.id)
			} else {
				let complaintsDetail = getApp().globalData.complaintInfo
				this.complaintsDetail = {
					...complaintsDetail,
					complaintImg: complaintsDetail.complaintImg.split(','),
					complaintTime: new Moment().format('YYYY-MM-DD HH:mm'),
					handleStatus: 'waitPending',
					statusName: '待处理'
				}
			}
		},
		onShow() {

		}
	}
</script>
<style>
	page {
		background-color: #F8F6F9;
	}
</style>
<style lang="scss" scoped>
	.page {
		padding: 30rpx;
	}

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

		.title {
			height: 40rpx;
			line-height: 40rpx;
			font-size: 32rpx;
			color: #373737;
			border-bottom: 1px solid #f8f8f8;
			padding-bottom: 30rpx;
			font-weight: bold;
		}

		.content {
			margin-top: 20rpx;

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

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

				.detail {
					width: 65%;
					font-size: 28rpx;
					color: #373737;
					&.yellow .tag {
						color: #F1BD4D;
						border: 1px solid #F1BD4D;
						background-color: #FFFCF6;
					}

					&.gray .tag {
						color: #B6B6BA;
						border: 1px solid #B6B6BA;
						background-color: #F8F8F8;
					}
					.tag {
						height: 40rpx;
						line-height: 40rpx;
						font-size: 22rpx;
						padding: 2rpx 20rpx;
						border-radius: 30rpx;
						display: inline-block;
					}
				}
			}

			.text {
				height: auto;

				.detail {
					line-height: 52rpx;
				}

				.image {
					display: flex;

					.icon {
						width: 120rpx;
						height: 120rpx;
						border-radius: 10rpx;
						margin-right: 10rpx;
					}
				}
			}
		}

	}

</style>