<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="200"/>
					</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"  v-model="item.FEEDBACK"  placeholder="请输入服务反馈结果" disabled="true"  maxlength="100"/>
					</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"></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 =='2'&&!item.EVALUATE_CONTENT">
			<view class="btn" @click="evaluate()">服务评价</view>
		</view>
		<uni-popup ref="popup" type="bottom">
			<view class="popup-content">
				<view class="history-box" :style="{ 'width': popupWidth + 'px' }">
					<view class="head-box">
						 <text @click="closePeople" style="font-weight: bold;">X</text>
					</view>
					<view class="history-table">
						 <view style="padding:20upx 10upx;display: flex;" v-if="item.STATE==1||item.STATE==2">
							<view style="color: #333;font-size: 28upx;font-weight: bold;padding: 20upx 0px;">
								<text>综合评价：</text>
							</view>
							<view style="width: 70%;margin-left: 20upx;padding: 20upx;">
								 <stars-rating :starsIndex="starsIndex" :isEditStars="true" @starsClick="evaluateStar(1,$event)"></stars-rating>
							</view>
						 </view>
						 <view style="width: 100%;border: 1px solid #E5E5E5;padding: 20upx;min-height: 150upx;color: #666;border-radius: 10upx;">
						 	<textarea style="width: 100%;" v-model="evaluateText"  placeholder="描述一下服务感受"  maxlength="200"/>
						 </view>
						
					</view>
					<view style="display: flex;justify-content: center;width: 100%;position: fixed;bottom: 40upx;" @click="addEvaluate">
						<view class="sumbitBtn" >评价</view>
					</view>
					 
				</view>
			</view>
		</uni-popup>
		<view class="occupied" style="height: 200upx;"></view>
	</view>
	</view>
</template>

<script>
	import {
		getProperty,
		addServiceEvaluate
	} 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: {},
				pageTitle:['报修','报事'],
				id:0,
				popupWidth:200,
				starsIndex: 0,
				submitFlag:true,
				evaluateText:'',
			}
		},
		onLoad(option) {
			this.id = option.id||0;
			this.getProperty();
		},
		onShow() {
			
		},
		methods: {
			evaluate() {
				var _this = this
				uni.getSystemInfo({
				  success: function (info) {
				    // console.log('页面宽度：' + info.windowWidth);
					_this.popupWidth = info.windowWidth*1;
					_this.starsIndex = 5;
					_this.evaluateText='';
					_this.$refs.popup.open()
				  }
				});
			},
			evaluateStar() {
				// console.log(...arguments)	
				// console.log(arguments[0])
				let starstype = arguments[0]
				if(starstype==1){
					this.starsIndex = arguments[1];
				}	
			},
			closePeople() {
				this.$refs.popup.close()
			},
			addEvaluate(){
				if(!this.submitFlag){
					return false;
				}
				this.submitFlag=false;
				if (!this.evaluateText) {
					alertTip('请输入服务评价');
					this.submitFlag = true;
					return false;
				}
				let params =  {
						method: addServiceEvaluate,
						data: {
							userId:this.userId,
							id:this.id,
							evaluateNum:this.starsIndex,
							evaluateContent:this.evaluateText,
						}
					};
				callbackRequest(params).then(res => {
					res = res.data;
					console.log(res)
					if (res.returnCode == 1) {
						alertTip(res.returnMsg);
						setTimeout(()=> {
						    this.$refs.popup.close()
						    uni.navigateBack({
						        delta: 1
						    });
						}, 1000)
					} else {
						alertTip(res.returnMsg);
					}
				});
			},
			getProperty(){
				var _this = this
				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];
						_this.item.EVALUATE_NUM= Number(_this.item.EVALUATE_NUM);
					} else {
						alertTip(res.returnMsg);
					}
				});
			},	
		}
	}
</script>

<style lang="scss">
	@import '@/static/css/common.scss';
	.history-box{
		background-color: #fff;
		height: 800upx;
		.head-box{
			width: 100%;
			height: 80upx;
			line-height: 80upx;
			padding: 10upx 40upx;
			border-bottom: 2upx solid #e5e5e5;
			display: flex;
			justify-content: flex-end;
		}
		.history-table{
			width: 100%;
			padding: 0upx 20upx;
		}
		.sumbitBtn{
			width: 70%;
			// width: 98%;
			height: 90upx;
			line-height: 90upx;
			background-color: red;
			color: #fff;
			font-size: 32upx;
			text-align: center;
			border-radius: 50upx;
		}
		// .history-cell{
		// 	width: 100%;
		// 	height: 100upx;
		// 	line-height: 100upx;
		// 	padding: 0upx 20upx;
		// 	display: flex;
		// 	justify-content: space-between;
		// 	border-bottom: 2upx solid #e5e5e5;
		// }
	}
 
	.details{
		// height: 550upx;
		background: white;
		margin: 20upx;
		border-radius: 15upx;
		padding-bottom:15upx;
		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;
			}
		}
		.detail_msg {
			margin-left: 20upx;
			border-radius: 10upx;
			.info-item{
				border-bottom:1px solid #f8f8f8;
				padding:20upx 10upx;
				line-height: 50upx;
				.label{
					display:inline-block;
					width:180upx;
					font-size:28upx;
					color:#333;
					font-weight:bold;
				}
			}
			.status {
				.infoSpan{
					color: #00c277;
				}
				.infoSpan2{
					color: red;
				}
			}
			.img-box {
				// background: #fff;
				image{
					width: 200upx;
					height: 200upx;
					margin:20upx 20upx 0 0;
				}
			}
		}
	}

</style>
