<template>
	<view class="deetailPage">
		<headers :showBack="true">
			<view class="headerName">
				查看检查记录
			</view>
		</headers>
		<view class="tab flex2">
			<view class="tabType" @click="changeTab(1)" :class="checkedTab==1?'checkedTab':'noCheckTab'">检查详细</view>
			<view class="tabType" @click="changeTab(2)" :class="checkedTab==2?'checkedTab':'noCheckTab'">过程记录</view>
		</view>
		<view class="content" v-if="checkedTab==1">
			<view class="type flex2">
				<view>检查部位：</view>
				<view>{{basicInfo.regionName}}</view>
			</view>
			<view class="type flex2" v-if="recordType == 1">
				<view>问题分类：</view>
				<view>{{basicInfo.dangerName}}/{{basicInfo.dangerItemName}}</view>
			</view>
			
			<view class="type flex2" v-if="recordType == 1">
				<view>问题描述：</view>
				<view>{{basicInfo.dangerItemContent}}</view>
			</view>
			<view class="type flex2" v-else>
				<view>排查分类：</view>
				<view>{{basicInfo.dangerItemContent}}</view>
			</view>
			
			<view class="type">
				<view>补充说明：</view>
				<pre class="pre">{{basicInfo.dangerDesc}}</pre>
			</view>
			<view class="type" v-if="recordType == 1">
				<view>整改要求：</view>
				<pre class="pre">{{basicInfo.remark}}</pre>
			</view>
			<view class="type flex2" v-if="recordType == 1">
				<view>问题等级：</view>
				<view>{{basicInfo.level==1?'一级':basicInfo.level==2?'二级':basicInfo.level==3?'三级':basicInfo.level==4?'四级':''}}</view>
			</view>
			<view class="type flex2" v-if="recordType == 1">
				<view>紧急程度：</view>
				<view>{{basicInfo.urgentLevel==1?'一般':basicInfo.urgentLevel==2?'严重':basicInfo.urgentLevel==3?'紧要':''}}</view>
			</view>
			<view class="type flex2">
				<view>检查人：</view>
				<view>{{basicInfo.inspectManName}}</view>
			</view>
			<view class="type flex2">
				<view>检查时间：</view>
				<view>{{basicInfo.inspectTime}}</view>
			</view>
	<!-- 		<view class="type flex2">
				<view>图纸定位：</view>
				<view>{{basicInfo.rectifyPeopleName}}</view>
			</view> -->
			<view class="type flex2">
				<view>分包单位：</view>
				<view>{{basicInfo.enterpriseName}}</view>
			</view>
			<view class="type flex2" v-if="recordType == 1">
				<view>整改时限：</view>
				<view>{{basicInfo.changeLimitTime}}</view>
			</view>
			<view class="type flex2" v-if="recordType == 1">
				<view>整改人：</view>
				<view>{{basicInfo.changeName}}</view>
			</view>
			<view class="type flex2" v-if="recordType == 1">
				<view>复查人：</view>
				<view>{{basicInfo.reviewName}}</view>
			</view>
			<view class="type flex2" v-if="recordType == 1">
				<view>核检人：</view>
				<view>{{basicInfo.verifyManName}}</view>
			</view>
			<view class="type flex2" v-if="recordType == 1">
				<view>通知人：</view>
				<!-- <view>{{basicInfo.notifyPersonName}}</view> -->
				<view>{{basicInfo.notifyPerson}}</view>
			</view>
			<view class="type flex2" v-if="recordType == 1">
				<view>现场整改：</view>
				<view>{{basicInfo.status==2?'未完成':basicInfo.status==5?'已完成':''}}</view>
			</view>
			<view class="type">
				<view>上传图片：</view>
				<view class="accessory">
					<image @click="previewImage(item.split('*')[1])" v-if="imgFileList.length>0" v-for="(item,index) in imgFileList" :key="index" :src="item.split('*')[1]"
					 class="accessoryImg"></image>
				</view>
			</view>
			<view style="margin-top: 10px;">
				<view>视频/音频附件：</view>
					<view @click="playVideo(item.split('*')[1],'video')" v-if="videoFileList.length>0" v-for="(item,index) in videoFileList" :key="index" 
					 style="line-height: 28px; color: #4181FE;width: 95%;white-space: nowrap; overflow: hidden;text-overflow: ellipsis;">{{item.split('*')[0]}}</view>
			</view>
		</view>
		
		
		
		<view class="content record" v-if="checkedTab==2">
			<view v-if="issueInfoList.length>0">
				<ul class="flex table_title">
					<li>发起顺序</li>
					<li>人员</li>
					<li>时间</li>
					<li>状态</li>
				</ul>
				<view v-for="(item,index) in issueInfoList" :key="index">
					<ul class="flex table_item" @click="handleShowItem(index)">
						<li>
							<span class="table_index">{{index}}</span>{{item.typeName}}
						</li>
						<li>
							<!-- {{item.createUserName}} -->{{item.peopleName}}
						</li>
						<li>
							{{item.createTime.split(' ')[0]}}
						</li>
						<li>
							<span :class="{'table_error': item.status == 1, 'table_success': item.status == 2}">{{item.statusText}}</span>
							<span class="icon-down" v-show="item.isShow"></span>
							<span class="icon-right" v-show="!item.isShow"></span>
						</li>
					</ul>
					<view class="table_content" v-show="item.isShow">
						<view class="imgList">
							<ul v-for="(item2, index2) in item.fileList" :key="index2">
								<li class="img-item">
									<image :src="url_config+'image/'+item2.url" @click="previewImage(url_config+'image/'+item2.url)">
								</li>
							</ul>
						</view>
						<view class="message">
							<span>备注：</span>
							<span>{{item.additionalRemarks}}</span>
						</view>
					</view>
				</view>
			</view>
			
			<view class="noData" v-if="issueInfoList.length==0">
				<image class="noDataImg" src="../../../static/noData.png"></image>
				<view>暂无数据</view>
			</view>
			<view class="approveBtn">
				<view class="btn" v-if="
          userInfo.userId == basicInfo.changeId && entryType == 2 && issueInfoList.length <= 0 || userInfo.userId == basicInfo.changeId && entryType == 2 && issueInfoList.length > 0 && issueInfoList[issueInfoList.length-1].statusText !== '已整改'"
				 @click="replyBtn(1)">整改回复</view>
			</view>
			<view class="approveBtn">
				<view class="btn" v-if="userInfo.userId==basicInfo.reviewId && entryType == 3 && issueInfoList.length > 0 && issueInfoList[issueInfoList.length-1].type !== 2"
				 @click="replyBtn(2)">复查回复</view>
			</view>
			<view class="approveBtn">
				<view class="btn" v-if="userInfo.userId==basicInfo.verifyManId && entryType == 4 && issueInfoList.length > 0 && issueInfoList[issueInfoList.length-1].type !== 3"
				 @click="replyBtn(3)">核验回复</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checkedTab: 1,
				imgFileList: [],
				videoFileList:[],
				basicInfo: {},
				issueInfoList: [],
				userInfo: {},
				entryType: '',
				recordType: 1 ,// 1为质量问题  2为排查记录
				id:'',
			}
		},
		onLoad(option) {
			this.id = option.id;
			this.userInfo = JSON.parse(uni.getStorageSync('userInfo'));
			this.entryType = Number(option.type)
		},
		onShow() {
			this.getBasicInfo();
			this.getIssueInfo();
		},
		methods: {
			handleShowItem(index){
				this.issueInfoList[index].isShow = !this.issueInfoList[index].isShow
				let newObj = this.issueInfoList[index]
				this.issueInfoList.splice(index, 1, newObj)
				// console.log(index, this.issueInfoList[index])
			},
			//切换tab
			changeTab(type) {
				this.checkedTab = type;
				if (type == 1) {
					this.getBasicInfo();
				} else {
					this.getIssueInfo();
				}
			},
			//获取基本信息
			getBasicInfo() {
				let that = this;
				this.sendRequest({
					url: 'xmgl/qualityInspectionRecord/selectQualityInspectionRecordById',
					method: 'post',
					data: {
						id: that.id
					},
					success: res => {
						console.log(res.result, this.userInfo)
						that.recordType = res.result.recordType
						that.basicInfo = res.result;
						if (res.result.imageUrl) {
							that.imgFileList = res.result.imageUrl.split(',');
						}
						if (res.result.fileUrl) {
							that.videoFileList = res.result.fileUrl.split(',');
						}
					}
				})
			},
			//获取整改信息
			getIssueInfo() {
				let that = this;
				this.sendRequest({
					url: 'xmgl/qualityRectifyRecord/selectRectifyRecordList',
					method: 'post',
					data: {
						qualityId: that.id
					},
					success: res => {
						console.log(res.result)
						// console.log(JSON.parse(res.result[0].fileUrl))
						that.issueInfoList = res.result;
						that.issueInfoList.forEach((item, index) => {
							if (item.fileUrl) {
								item.fileList = JSON.parse(item.fileUrl)
							}
							if(item.type == 1) {
								item.typeName = '整改人'
								item.peopleName = this.basicInfo.changeName
							} else if(item.type == 2) {
								item.typeName = '复查人'
								item.peopleName = this.basicInfo.reviewName
							} else if(item.type == 3) {
								item.typeName = '核验人'
								item.peopleName = this.basicInfo.inspectManName
							}
							
							if (item.status == 1) {
								item.isPass = false
							} else {
								item.isPass = true
							}
							item.isShow = false
							if (item.type == 1 && item.status == 1) {
								item.statusText = '未整改'
							} else if(item.type == 1 && item.status == 2){
								item.statusText = '已整改'
							} else if(item.type == 2 && item.status == 1){
								item.statusText = '复查不合格'
							} else if(item.type == 2 && item.status == 2){
								item.statusText = '复查合格'
							} else if(item.type == 3 && item.status == 1){
								item.statusText = '核验不合格'
							} else if(item.type == 3 && item.status == 2){
								item.statusText = '核验合格'
							}
						})
					}
				})
			},

			//新增回复
			replyBtn(type) {
				let stateId = this.issueInfoList.length > 0 ? this.issueInfoList[this.issueInfoList.length - 1].id : '';
				let createId = this.basicInfo.creatorId ? this.basicInfo.creatorId : this.basicInfo.inspectManId
				uni.navigateTo({
					url: './reply?id=' + this.id + '&type=' + type + '&stateId=' + stateId + '&createId=' + createId
				})
			},
			//播放视频
			playVideo(url,type){
				uni.navigateTo({
					url:'../carWashManage/mediaPlay?url='+url+'&type='+type
				})
			},
			
			//预览图片
			previewImage(url){
				uni.previewImage({
					urls:[url]
				})
			}

		}
	}
</script>

<style>
	.flex {
		display: flex;
		align-items: center;
	}

	.flex2 {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.flex3 {
		display: flex;
	}

	.deetailPage {
		width: 100%;
		height: 100%;
	}

	.tab {
		width: 100%;
		height: 45px;
		text-align: center;
		box-shadow: 0 0 10px rgba(194, 194, 194, 0.5);
	}

	.tabType {
		width: 50%;
		line-height: 43px;
		border-bottom: 1px solid rgba(194, 194, 194, 0.2);

	}

	.checkedTab {
		color: #4181FE;
		border-bottom: 2px solid #4181FE;

	}

	.noCheckTab {
		padding-bottom: 2px;
	}

	.content {
		width: 100%;
		box-sizing: border-box;
		padding: 20rpx 16rpx
	}

	.type {
		font-size: 30rpx;
		line-height: 40px;
		border-bottom: 1px solid rgba(194, 194, 194, 0.2);
	}

	.pre {
		padding: 10px 30rpx;
		background-color: rgba(194, 194, 194, 0.2);
		min-height: 50px;
		width: 100%;
		white-space: pre-wrap;
		word-wrap: break-word;
		box-sizing: border-box;
		line-height: initial;
	}

	.accessory {
		width: 100%;
		height: 70px;
		padding: 0 10px;
		box-sizing: border-box;
	}

	.accessoryImg {
		width: 110rpx;
		height: 60px;
		margin-right: 8px;
	}

	.userImg {
		width: 25px;
		height: 25px;
		border-radius: 50%;
		box-shadow: 0px 0 15px rgba(194, 194, 194, 0.5);
		margin-top: 5px;
	}

	.bubble {
		margin-left: 18px;
		width: 90%;
		box-sizing: border-box;
	}

	.bubble .bubble_content {
		width: 90%;
		background-color: #fff;
		padding: 10px 15px;
		display: inline-block;
		border-radius: 6px;
		position: relative;
		box-shadow: -2px 0 15px rgba(194, 194, 194, 0.5);
		position: relative;

	}

	.bubble .bubble_content::after {
		content: '';
		border: 8px solid #ffffff00;
		border-right: 8px solid #fff;
		position: absolute;
		top: 10px;
		left: -16px;
	}

	.record {
		/* background-color: rgba(234, 234, 234, 0.4); */
		padding-bottom: 60px;
	}

	.bubble_content .name {
		font-size: 30rpx;
		margin: 10px 0;
	}

	.time {
		color: rgba(153, 153, 153, 1);
		font-size: 24rpx;
		font-family: PingFangSC-Regular;

	}

	.item_title {
		margin: 10px 0;
		font-family: PingFangSC-Regular;
		font-size: 28rpx;
		opacity: 0.8;
	}

	.approveBtn {
		position: fixed;
		bottom: 15px;
		width: calc(100% - 30px);
		box-sizing: border-box;
		z-index: 99;
	}

	.approveBtn .btn {
		width: 70%;
		line-height: 40px;
		background-color: #4181FE;
		color: #fff;
		text-align: center;
		border-radius: 30px;
		margin: 0 auto;
		box-shadow: 0 5px 5px rgba(65, 129, 254, 0.3);
	}

	.approveBtn .btn:active {
		background-color: rgba(65, 129, 254, 0.8);
	}

	.pass_wrap {
		position: absolute;
		top: 100px;
		right: 20px;
		z-index: 10;
	}

	.pass_icon {
		width: 80px;
		height: 80px;
	}

	.noData {
		text-align: center;
		font-size: 32rpx;
		margin-top: 120px;
		color: #bed0fb;
	}

	.noDataImg {
		width: 125px;
		height: 98px;
	}
	.table_title{
		list-style: none;
		justify-content: space-between;
		padding-left: 0;
		align-items: center;
		height: 56rpx;
		border-bottom: 1px solid #f1f1f1;
	}
	.table_title li{
		flex: 1;
		text-align: center;
		line-height: 56rpx;
	}
	.table_index{
		display: block;
		border-radius: 50%;
		color: #fff;
		background: #488DEC;
		width: 32rpx;
		height: 36rpx;
		text-align: center;
		line-height: 36rpx;
		margin-right: 10rpx;
	}
	.table_success{
		display: block;
		color: #13B98C;
		background: rgba(19,185,140,0.2);
		line-height: 32rpx;
		padding: 6rpx;
	}
	.table_error{
		display: block;
		color: #EA3941;
		background: rgba(234,57,65,0.2);
		line-height: 32rpx;
		padding: 6rpx;
	}
	.table_item{
		list-style: none;
		justify-content: space-between;
		padding-left: 0;
		align-items: center;
		height: 100rpx;
		border-bottom: 1px solid #f1f1f1;
	}
	.table_item li{
		flex: 1;
		text-align: center;
		font-size: 30rpx;
		line-height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.table_item li:last-child{
		justify-content: flex-end;
	}
	.table_item li:nth-child(1){
		flex: none;
		width: 136rpx;
	}
	.table_title li:nth-child(1){
		flex: none;
		width: 136rpx;
	}
	.icon-down{
		height: 32rpx;
		width: 28rpx;
		background: url(../../../static/icon-down-black.png) center no-repeat;
		background-size: 100%;
		margin-left: 4rpx;
	}
	.icon-right{
		height: 32rpx;
		width: 16rpx;
		background: url(../../../static/icon-right.png) center no-repeat;
		background-size: 100%;
		margin-left: 8rpx;
	}
	.table_content{
		background: #f1f1f1;
		padding: 28rpx;
	}
	.imgList{
		margin-bottom: 20rpx;
	}
	.imgList ul{
		list-style: none;
		padding: 0;
		display: flex;
		flex-wrap: wrap;
		align-items: center;
	}
	.imgList ul li {
		width: 30%;
		height: 100px;
		margin: 0 10rpx;
		margin-bottom: 20rpx;
	}
	.imgList ul li image{
		width: 100%;
		height: 100%;
	}
</style>
