<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="complaintsDetail.handleStatus"><view class="tag">{{complaintsDetail.statusName}}</view></view>
						</view>
						<view class="item text" v-if="complaintsDetail.complaintImg && complaintsDetail.complaintImg.length">
							<view class="name">附件</view>
							<view class="image">
								<image @click="onPreviewImage(item)" v-for="(item,index) in complaintsDetail.complaintImg" :key="index" :src="item" class="icon"></image>
							</view>
						</view>
						<view class="item text" v-if="complaintsDetail.handleStatus === 'finish'">
							<view class="name">处理结果</view>
							<view class="detail">{{complaintsDetail.handleResult}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCommunityComplaintDetailApi
	} from '@/config/api.js'
	import serverConfig from "@/config/server_config.js";
	import {Moment} from '@/utils/moment.js'
	const handleStatus = {
		waitPending: '待处理',
		pending: '处理中',
		finish: '处理完成'
	}
	export default {
		data() {
			return {
				complaintsDetail: {
					complaintTheme: '',
					userName: '',
					userPhone: '',
					problemDesc: '',
					handleStatus: '',
					statusName: '',
					complaintImg: []
				}
			}
		},
		methods: {
			async getDetail(id) {
				let {result} = await getCommunityComplaintDetailApi({id})
				let complaintImg = result.complaintImg ? result.complaintImg.split(',') : []
				complaintImg = complaintImg.map(item=> `${serverConfig.imageURL}${item}`)
				this.complaintsDetail = {
					...result,
					complaintImg,
					complaintTime: new Moment(new Date(result.createTime).getTime()).format('YYYY-MM-DD HH:mm'),
					statusName: handleStatus[result.handleStatus]
				}
			},
			onPreviewImage(currentUrl) {
				uni.previewImage({
					current: currentUrl, // 图片的地址url
					urls: this.complaintsDetail.complaintImg // 预览的地址url
				})
			}
		},
		onLoad(options) {
			if(options.id) {
				this.getDetail(options.id)
			} else {
				let complaintsDetail = getApp().globalData.complaintInfo
				let complaintImg = complaintsDetail.complaintImg ? complaintsDetail.complaintImg.split(',') : []
				complaintImg = complaintImg.map(item=> `${serverConfig.imageURL}${item}`)
				this.complaintsDetail = {
					...complaintsDetail,
					complaintImg,
					complaintTime: new Moment().format('YYYY-MM-DD HH:mm'),
					handleStatus: 'waitPending',
					statusName: '待处理'
				}
			}
		}
	}
</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;
					&.waitPending .tag {
						color: #F1BD4D;
						border: 1px solid #F1BD4D;
						background-color: #FFFCF6;
					}
					&.pending .tag {
						color: #6A59F2;
						border: 1px solid #6A59F2;
						background-color: #F6F5FF;
					}
					&.finish .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;
				margin-top: 10rpx;

				.detail {
					line-height: 52rpx;
				}

				.image {
					display: flex;

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

	}

</style>