<template>
	<view class="content">
		<view class="step_num">
			<view class="step step1">签到</view>
			<view class="step step2">巡检设备</view>
			<view class="step step3">巡检总结</view>
		</view>
		<view class="project_container">
			<view class="myContentBox myContainer" v-for="(items,index) in data_result.details" :key="index">
				<view class="top_container detail_list_top">
					<view class="report_status">[{{items.serialNo}}]-{{items.deviceName}}</view>
					<!-- <view class="report_status">停机时间:{{items.offTime?items.offTime:''}}</view> -->
					<view class="edit" @click="edit(index)">编辑</view>
				</view>
				<view style="clear: both;">
					<view class="multi_list_item">
						<view class="list_item list_item-">
							<view class="list_item_name">巡检项目:</view>
							<view class="list_item_content">{{items.projectName}}</view>
						</view>
						<view class="list_item list_item-">
							<view class="list_item_name">巡检结果:</view>
							<view class="list_item_content" v-if="items.result==2" style="color: red;">异常</view>
							<view class="list_item_content" v-else-if="items.result==1" style="color: #3382FF;">正常</view>
						</view>
					</view>

					<view class="list_item ">
						<view class="list_item_name">巡检标准:</view>
						<view class="list_item_content">{{items.function}}</view>
					</view>
					<view class="list_item">
						<view class="list_item_name">巡检记录:</view>
						<view class="list_item_content">{{items.content?items.content:''}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="goHome" @click='goMain()'>
			<img src="../../static/img/gohome.png">
		</view>
		<view class="bottom_btn">
			<view class="previous" @click="toPrevious()">上一步</view>
			<view class="next"  @click="toNext()">下一步</view>
		</view>
	</view>
</template>

<script>
import {mapState,mapMutations} from 'vuex'
	export default {
		data() {
			return {
				id: '',
				data_result: {
				}
			}
		},
			computed: {
            ...mapState(['patrolDetails'])
        },
		onLoad(option) {
			this.id = option.id;
			if(this.id==undefined){
				uni.reLaunch({
				    url: 'eqPatrol'
				});
				return false;
			}
			
			var _this = this;
			this.$http.request({
				url: '/apis/patrolRecord/recordDetail',
				params: {
					id: option.id
				},
			}).then(res => {
				if (res.statusCode == '200') {
					this.data_result = res.data;
					if(this.patrolDetails.patrolDetails==undefined){
						var patrolDetailsArray=[];
						for(var i=0;i<res.data.details.length;i++){
							var j={
								id:res.data.details[i].id,
								offTime:res.data.details[i].offTime,
								result:res.data.details[i].result,
								content:res.data.details[i].content,
							}
							patrolDetailsArray.push(j)
						}
						this.setpatrolDetails({id:this.id,patrolDetails:patrolDetailsArray});
					}else if(this.patrolDetails.id==this.id){
						for(var i=0;i<this.patrolDetails.patrolDetails.length;i++){
								this.data_result.details[i].offTime=this.patrolDetails.patrolDetails[i].offTime;
								this.data_result.details[i].result=this.patrolDetails.patrolDetails[i].result;
								this.data_result.details[i].content=this.patrolDetails.patrolDetails[i].content;
						}
						this.$forceUpdate()
					}
					
				}
			}).catch(err => {
				console.log(err)
			});
		},
	
		methods:{
			...mapMutations(['setpatrolDetails']),
			  toNext(){
				  if(this.patrolDetails.patrolDetails && this.patrolDetails.patrolDetails.length>0){
					  var arrays = this.patrolDetails.patrolDetails;
					  for(var i=0; i<arrays.length; i++){
						  if(!arrays[i].result){
							  uni.showToast({
							  	title: '请编辑完成巡检项目',
							  	icon: 'none',
							  	duration: 2000
							  });
							  return false;
						  }
					  }
				  }
				  uni.navigateTo({
					  url: "patrolStep3?id="+this.id
				  });
			  },
			  //编辑
			  edit(index){
				  	uni.redirectTo({
				  	    url: "patrolEdit?id="+this.id+"&detailId="+this.data_result.details[index].id+"&index="+index
				  	});
			  },
			toPrevious() {
				uni.navigateBack({})
			},
		}
	}
</script>


<style scoped>
	.content {
		position: relative;
		min-height: 100%;
		overflow: auto;
		padding-bottom: 140upx;
		box-sizing: border-box;
	}

	.step_num {
		display: flex;
		flex-direction: row;
		justify-content: center;
		width: 100%;
		height: 80upx;
		background-color: #fff;
		padding-right: 48upx;
		box-sizing: border-box;
	}

	.step {
		position: relative;
		font-size: 28upx;
		line-height: 80upx;
		padding-left: 30upx;
		float: left;
	}

	.step:before {
		position: absolute;
		left: 0px;
		content: '1';
		border: 1px solid #000;
		width: 28upx;
		height: 28upx;
		box-sizing: border-box;
		line-height: 28upx;
		border-radius: 200upx;
		font-size: 20upx;
		text-align: center;
		top: 26upx;
	}

	.step:after {
		position: absolute;
		content: '';
		width: 60upx;
		height: 2upx;
		background-color: #000;
		top: 40upx;
		left: 88upx;
	}

	.step2 {
		margin-left: 64upx;
	}

	.step2:before {
		content: '2';
	}

	.step2:after,
	.step3:after {
		left: 144upx;
	}

	.step3 {
		margin-left: 64upx;
		color: #828282;
	}
	.step3:after{
		background: transparent;
	}

	.step3:before {
		content: '3';
		border: 2upx solid #828282;
	}

	.project_container {
		position: relative;
		margin-top: 20upx;
		overflow: auto;
	}


	.top_container {
		position: relative;
		width: 100%;
		background-color: #fff;
		padding: 30upx 30upx 30upx 30upx;
		box-sizing: border-box;
		color: #333;
		box-shadow: 2px 2px 20upx rgba(0, 0, 0, 0.1);
	}

	.detail_list_top {
		border-bottom: 1px solid #EDEDED;
		box-shadow: none;
		padding-right: 100upx;
	}
.edit{
	position: absolute;
	font-size: 28upx;
	color: #3382FF;
	right: 30upx;
	top: 30upx;
	
}
	.report_status {
		line-height: 40upx;
		word-break: break-all;
		font-size: 28upx;
	}

	.detail_list{
		position: relative;
		background-color: #fff;
		width: 90%;
		margin: auto;
		box-shadow: 1px 1px 20upx rgba(0,0,0,0.1);
		margin-bottom: 30upx;
		overflow: auto;
	}
	.list_item {
		position: relative;
		width: 100%;
		min-height: 70upx;
		padding: 0 30upx;
		box-sizing: border-box;
	}

	.multi_list_item {
		position: relative;
		overflow: auto;
	}

	.list_item- {
		width: 50%;
		float: left;
	}

	.list_item_name {
		position: absolute;
		left: 30upx;
		font-size: 28upx;
		color: #999;
		line-height: 70upx;
		width: 140upx;
	}

	.list_item- .list_item_name {
		width: 120upx !important;
	}

	.list_item_content {
		position: relative;
		padding: 0 0 0 140upx;
		font-size: 28upx;
		line-height: 70upx;
		color: #333;
		overflow: hidden;
		height: 70upx;
		text-overflow: ellipsis;
		white-space: nowrap
		
	}
	.bottom_btn{
		position: absolute;
		left: 5%;
		bottom: 15px;
		width: 90%;
		height: 82upx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		
	}
	.next,.previous {
		width: 48%;
		border-radius: 5px;
		border: 1px solid #3382FF;
		text-align: center;
		color: #3382FF;
		line-height: 82upx;
		background-color: #fff;
		}
		.next{
			border: none;
			background-color:#3382FF ;
			color: #fff;
		}
</style>
