<template>
	<view class="container">
		<view class="page">
			<view class="maintenance">
				<view class="information">
					<view class="evaluation">
						<view class="rate">
							<view class="name">评价:</view><uni-rate v-model="rateValue" :size="20" />
						</view>
						<view class="textarea">
							<uni-easyinput type="textarea" v-model="evaluation" placeholder="请输入您的评价" />
						</view>
					</view>
					<view class="content">
						<view class="item">
							<view class="name">报修地址</view>
							<view class="detail">{{formModel.repairAddress}}</view>
						</view>
						<view class="item">
							<view class="name">维修物品</view>
							<view class="detail">{{formModel.repairArticle}}</view>
						</view>
						<view class="item">
							<view class="name">标题</view>
							<view class="detail">{{formModel.repairTitle}}</view>
						</view>
						<view class="item">
							<view class="name">手机号码</view>
							<view class="detail">{{formModel.ownerPhone}}</view>
						</view>
						<view class="item">
							<view class="name">预约上门时间</view>
							<view class="detail">{{formModel.reservationTime}}</view>
						</view>
						<view class="item text">
							<view class="name">问题描述</view>
							<view class="detail">{{formModel.repairDesc}}</view>
						</view>
						<view class="item text" v-if="imageList.length">
							<view class="name">附件</view>
							<view class="image">
								<image @click="onPreviewImage(url, imageList)" v-for="(url, index) in imageList" :key="index" :src="url" class="icon"></image>
							</view>
						</view>
						<view class="item text" style="margin-top:16rpx;" v-if="maintenancePhotos.length">
							<view class="name">维修照片</view>
							<view class="image">
								<image @click="onPreviewImage(url, maintenancePhotos)" v-for="(url, index) in maintenancePhotos" :key="index" :src="url" class="icon"></image>
							</view>
						</view>
					</view>
				</view>
				<view class="form-submit" @click="onSubmit">提交</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCommunityRepairDetailApi,
		editCommunityRepairApi
	} from '@/config/api.js'
	import serverConfig from "@/config/server_config.js";
	export default {
		data() {
			return {
				rateValue: 5,
				evaluation: '',
				formModel: {},
				imageList: [],
				maintenancePhotos: []
			}
		},
		methods: {
			async getDetail(id) {
				let {result} = await getCommunityRepairDetailApi({id})
				this.formModel = {...result}
				let maintenanceImg = result.repairPhoto ? result.repairPhoto.split(',') : []
				this.imageList = maintenanceImg.map(item=> `${serverConfig.imageURL}${item}`)
				let maintenancePhotos = result.maintenancePhoto ? result.maintenancePhoto.split(',') : []
				this.maintenancePhotos = maintenancePhotos.map(item=> `${serverConfig.imageURL}${item}`)
			},
			async onSubmit() {
				await editCommunityRepairApi({
					id: this.formModel.id,
					repairEvaluate: this.evaluation,
					evaluateCount: this.rateValue
				})
				uni.$emit('change-maintenance');
				setTimeout(()=> {
					uni.showToast({
						title: '评价成功！',
						icon: 'none'
					});
					setTimeout(()=> {
						uni.navigateBack({delta: 2});
					}, 1500)
				}, 30)
			},
			onPreviewImage(currentUrl, list) {
				uni.previewImage({
					current: currentUrl, // 图片的地址url
					urls: list // 预览的地址url
				})
			}
		},
		onLoad(option) {
			this.getDetail(option.id)
		}
	}
</script>
<style>
	page {
		background-color: #F8F6F9;
	}
</style>
<style lang="scss" scoped>
	.page {
		padding: 30rpx;
	}

	.maintenance {
		.evaluation {
			.rate {
				display: flex;
				align-items: center;
				margin-bottom: 30rpx;

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

			.textarea {
				background-color: #F8F8F8;
			}
		}

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

			.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;
					}
				}

				.text {
					height: auto;

					.detail {
						line-height: 52rpx;
					}

					.image {
						display: flex;

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

		}
	}

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