<template>
	<view class="hzIndex">
	<hzHeader title="服务受理详情"></hzHeader>
	<view class="hzContent"  style="padding-top: 200upx;">
		<view class="details">
			<view class="detail_msg">
				<!-- <view class="info-item">
					<text class="label">部门： </text>
					<text class="infoSpan">{{item.repair_dept_name}}</text>
				</view> -->
				<view class="info-item">
					<text class="label">服务类型： </text>
					<text class="infoSpan">{{item.DATA_VALUE}}</text>
				</view> 
				<view class="info-item">
					<text class="label">办公室： </text>
					<text class="infoSpan">{{item.OFFICE}}</text>
				</view> 
				<view class="info-item">
					<!-- <text class="label">需求描述： </text>
					<text class="infoSpan">{{ item.DEMAND }}</text> -->
					<view style="color: #333;font-size: 30upx;font-weight: bold;padding: 10upx 0px;">
						<text>需求描述：</text>
					</view>
					<view style="width: 100%;border: 1px solid #E5E5E5;margin-top: 20upx;padding: 20upx;min-height: 200upx;color: #666;border-radius: 10upx;">
						<textarea class="textarea"  v-model="item.DEMAND"  placeholder="请输入服务反馈结果" disabled="true"  maxlength="100"/>
					</view>
				</view> 
				<view v-if="item.NUMBER" class="info-item">
					<text class="label">数量： </text>
					<text class="infoSpan">{{ item.NUMBER }}</text>
				</view>
				<!-- <view v-if="item.fault_detail" class="info-item">
					<text class="label">问题描述： </text>	
					<text class="infoSpan">{{item.fault_detail}}</text>
				</view>
				<view class="info-item">
					<text class="label">{{pageTitle[item.fault_type]}}位置： </text>
					<text class="infoSpan">{{item.repair_place+" "+(item.repair_floor||'')+(item.repair_room_no?"-"+item.repair_room_no+'':'')}}</text>
				</view> -->
				
				<view class="info-item">
					<text class="label">服务时间： </text>	
					<text class="infoSpan">{{item.APPLICANT_TIME}}</text>
				</view>
				<view class="info-item status">	
					<text class="label">服务状态： </text>
					<text v-if="item.STATE =='0'" class="infoSpan2"  >待处理</text><!-- statusred -->
					<text v-if="item.STATE =='1'" class="infoSpan" style="color: green;">进行中</text>
					<text v-if="item.STATE =='2'" class="infoSpan" style="color: green;">已完成</text>
				</view>
				<view class="info-item">
					<text class="label">申请人： </text>
					<text class="infoSpan">{{ item.USER_NAME }}</text>
				</view>
				<view class="info-item" v-if="item.APPROVAL_NAME">
					<text class="label">办理人:</text>
					<text class="infoSpan">{{ item.APPROVAL_NAME }}</text>
				</view>
				<view class="info-item" v-if="item.FEEDBACK">
					<view style="color: #333;font-size: 30upx;font-weight: bold;padding: 10upx 0px;">
						<text>服务反馈结果：</text>
					</view>
					<view style="width: 100%;border: 1px solid #E5E5E5;margin-top: 20upx;padding: 20upx;min-height: 250upx;color: #666;border-radius: 10upx;">
						<textarea class="textarea" style="width: 100%;" v-model="item.FEEDBACK"  placeholder="请输入服务反馈结果" disabled="true"  maxlength="200"/>
					</view>
				</view>
				<view class="info-item" v-if="item.STATE==1||item.STATE==2">
					<view style="color: #333;font-size: 30upx;font-weight: bold;padding: 10upx 0px;">
						<text>服务前照片：</text>
					</view>
					<view style="width: 100%;margin-top: 20upx;padding: 20upx;min-height: 250upx;color: #666;border-radius: 10upx;">
						 <image :src="item.SERVICE_FRONT" mode="" style="width: 100%;height: 400upx;"><image>
					</view>
				</view>
				<view class="info-item" v-if="item.STATE==2">
					<view style="color: #333;font-size: 30upx;font-weight: bold;padding: 10upx 0px;">
						<text>服务后照片：</text>
					</view>
					<view style="width: 100%;margin-top: 20upx;padding: 20upx;min-height: 250upx;color: #666;border-radius: 10upx;">
						 <image :src="item.SERVICE_AFTER" mode="" style="width: 100%;height: 400upx;"><image>
					</view>
				</view>
				<view class="info-item" v-if="item.STATE==2&&item.EVALUATE_CONTENT">
					<view style="color: #333;font-size: 30upx;font-weight: bold;padding: 10upx 0px;">
						<text>服务评价：</text>
					</view>
					<view style="width: 100%;padding: 20upx;height:100upx;display: flex;align-items: center;">
						 <view style="width: 70%;padding: 20upx;">
						 	 <stars-rating :starsIndex="item.EVALUATE_NUM" :isEditStars="false" @starsClick="evaluateStar(1,$event)"></stars-rating>
						 </view>
						 <view style="width: 30%;">2024-05-10</view>
					</view>
					<view style="width: 100%;border: 1px solid #E5E5E5;padding: 20upx;min-height: 200upx;color: #666;border-radius: 10upx;">
						<textarea style="width: 100%;" v-model="item.EVALUATE_CONTENT"  placeholder="服务评价" disabled="true"  maxlength="200"/>
					</view>
					
				</view>
				<!-- <view class="img-box" >
					<image v-for="(itemImg,imgIndex) in item.pictures" :key="imgIndex" :src="formatImgUrl(itemImg)" mode="" @click="vbPicture(new Array(formatImgUrl(itemImg)))"></image>
				</view> -->
				
			</view> 
		</view>
		
		
		<view class="footer-btn" v-if="item.STATE =='0'">
			<view class="btn" @click="start()">开始服务</view>
		</view>
		<view class="footer-btn" v-if="item.STATE =='1' && item.APPROVAL_ID ==userId">
			<view class="btn" @click="confirm()">结束服务</view>
		</view>

		<view class="occupied" style="height: 200upx;"></view>
	</view>
	</view>
</template>

<script>
	import {
		getProperty,updateProperty
	} from '@/common/api.js';
	
	import {
		callbackRequest,
		getStorage,
		alertTip,
		formatDate,
		sureAlterTip,
		vbPicture,
		formatImgUrl
	} from '@/common/util.js';
	import starsRating from '@/components/starsRating';
	export default {
		components: { starsRating },
		data() {
			return {
				vbPicture:vbPicture,
				formatImgUrl:formatImgUrl,
				userInfo:getStorage('userInfo'),
				userId:getStorage('userInfo').userId,
				formatDate:formatDate,
				item: {},
				id:0,
				feedback:'',
				submitFlag:true,
				
			}
		},
		onLoad(option) {
			this.id = option.id||0;
			this.getProperty();
		},
		onShow() {
			this.getProperty();
		},
		methods: {
			getProperty(){
				let params =  {
						method: getProperty,
						data: {
							userId:this.userId,
							id:this.id
						}
					};
				callbackRequest(params).then(res => {
					res = res.data;
					console.log(res)
					if (res.returnCode == 1) {
						this.item = res.returnData[0];
					} else {
						alertTip(res.returnMsg);
					}
				});
			},
			start() {
				uni.navigateTo({
					url: `/pages/malfunc-repair/service-photo?STATE=`+ this.item.STATE +'&id='+this.id
				});
			},
			confirm() {
				uni.navigateTo({
					url: `/pages/malfunc-repair/service-photo?STATE=`+ this.item.STATE +'&id='+this.id +'&APPROVAL_ID='+this.item.APPROVAL_ID
				});
			},

			submit(state){
				if(!this.submitFlag){
					return false;
				}
				this.submitFlag=false;
				if (this.item.APPROVAL_ID !=this.userId && this.item.APPROVAL_ID !=null) {
					alertTip('办理人与当前用户不一致');
					this.submitFlag = true;
					return false;
				}
				if (this.item.STATE =='1'&&!this.feedback) {
					alertTip('请输入服务反馈结果');
					this.submitFlag = true;
					return false;
				}
				let params = {
					"method": updateProperty,
					"data":{
						id: this.id,
						userId:getStorage('userInfo').id,
						userName:getStorage('userInfo').userName,
						state:this.item.STATE,
						feedback:this.feedback
					}
				};
				callbackRequest(params).then(res => {
					res = res.data;
					if (res.returnCode == 1) {
						alertTip(res.returnMsg);
						this.getProperty();
						uni.navigateBack({
						    delta: 1
						});
					} else {
						alertTip(res.returnMsg);
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import '@/static/css/common.scss';
	.details{
		// height: 550upx;
		background: white;
		margin: 20upx;
		border-radius: 15upx;
		padding-bottom:15rpx;
		position: relative;
		font-size: 26upx;
		.detail_header {
			border-bottom: #f8f8f8 5upx solid;
			height: 90upx;
			line-height: 90upx;
			margin: 15upx;
			border-radius: 10upx;
			.blueSign {
				height: 28upx;
				width: 5upx;
				background: #00c277;
				display: inline-block;
				margin-left: 20upx;
			}
			.font-tilte {
				font-weight:bold;
				margin-left: 20upx;
			}
		}
		.form-box {
			background: #fff;
			.form-item {
				overflow: hidden;
				border-bottom: 1px solid #eee;
				padding: 30upx 20upx;
				.label {
					float: left;
					width: 180upx;
					font-size: 28upx;
					color: #333;
					font-weight: bold;
					line-height: 50upx;
				}
				.ipt-box {
					margin-left: 160upx;
					input {
						width: 90%;
						height: 50upx;
						line-height: 50upx;
						font-size: 26upx;
						color: #666;
					}
				}
				.select {
					.arrow {
						float: right;
						width: 16upx;
						height: 29upx;
						margin-top: 10upx;
					}
					.picker {
						height: 50upx;
						line-height: 50upx;
						font-size: 26upx;
						color: #666;
						margin-left: 10upx;
					}
				}
			}
		}
		.detail_msg {
			margin-left: 20upx;
			border-radius: 10upx;
			.info-item{
				border-bottom:1px solid #f8f8f8;
				padding:20upx 10upx;
				line-height: 50upx;
				.label{
					float: left;
					width: 180upx;
					font-size: 28upx;
					color: #333;
					font-weight: bold;
					line-height: 50upx;
				}
			}
			.status {
				.infoSpan{
					color: #00c277;
				}
				.infoSpan2{
					color: red;
				}
			}
			.img-box {
				// background: #fff;
				image{
					width: 200upx;
					height: 200upx;
					margin:20upx 20upx 0 0;
				}
			}
		}
	}

</style>
