<template>
	<view class="visitOrderDetail content_box">
		<view class="cargoDetail-item">
			<view class="detail-title flex_center" style="border: none;">
				<view class="flex_center flex_cen">
					访问号: {{isEmpty(orderInfo.accessNo)}}
					<image src="../../static/img/icon/copy.png" @click="copyAccessNo"></image>
				</view>
				
				<view v-if="orderInfo.statusLabel"
					:class="['detail-title-label', tagClass(isEmpty(orderInfo.statusLabel))]">
					{{isEmpty(orderInfo.statusLabel)}}
				</view>
			</view>
			<!-- 订单明细" -->
			<view class="detail-title">
				<bs-customCell label="车牌号:" :value="orderInfo.truckNo" labelCol="3" wrapCol="9" />
				<bs-customCell label="司机姓名:" :value="orderInfo.driverName" labelCol="3" wrapCol="9" />
				<bs-customCell label="司机手机:" :value="orderInfo.driverPhone" labelCol="3" wrapCol="9" />
				<bs-customCell label="拜访地点:" :value="addressName" labelCol="3" wrapCol="9" />
				<bs-customCell label="预约时间:" :value="getTimeLabel(orderInfo.bookingTime,'D')" labelCol="3" wrapCol="9" />
			</view>

		</view>

		<view class="material">

			<view class="detail-title">
				<bs-customCell label="被访部门:" :value="orderInfo.visitedDepartment" labelCol="3" wrapCol="9" />
				<bs-customCell label="被访人:" :value="orderInfo.visitedStaff" labelCol="3" wrapCol="9" />
				<bs-customCell label="联系方式:" :value="orderInfo.visitedTel" labelCol="3" wrapCol="9" />
			</view>
		</view>
		 
		<view style="background: #fff;">
			<view style="font-size: 28rpx;font-weight: bolder;margin-left: 24rpx;margin-bottom: 24rpx;">
				<bs-customCell label="进度流程" :labelCustomStyle="`color:#434343`" labelCol="12" wrapCol="0" />
			</view>
	
			<view style="display: flex;" class="passDetail">
				<u-steps :current="current" direction="column" inactiveColor="#BFBFBF" activeColor="#2979ff">
					<u-steps-item 
						:title="`${title.label} ${getTimeLabel(title.time)}`"
						v-for="(title, index) in processInfoAct" :key="index">
						<view slot="desc">
							<view class="descSlot" v-if="title.auditRemarks">
								{{title.auditRemarks}}
							</view>
						</view>
						<view slot="icon">
							<view v-if="index<current" class="passIcon" style="height: 32rpx; width: 32rpx; "></view>

							<view v-else-if="index==current && title.label == '已拒绝'" class="rejectIcon" style="height: 32rpx; width: 32rpx;"></view>
							
							<view v-else-if="index==current && title.label != '已拒绝'" style="height: 32rpx; width: 32rpx; border-radius: 16rpx;background-color: #2979ff;"></view>
	
							<view v-else style="height: 32rpx; width: 32rpx; border-radius: 16rpx;background-color: #BFBFBF;"></view>
						</view>
	
					</u-steps-item>
				</u-steps>
			</view>
		</view>



	</view>
</template>

<script>
	import {
		getVisitOrderDetails,
		GetOrderHistoryEvent
	} from '../../api/apiList'
	import {
		formatGMT
	} from '../../utils/util.js'

	export default {
		options: { styleIsolation: 'shared' },
		data() {
			return {
				isDrag: false,
				currentDockId: "",
				addressName: "",
				orderId: "",
				orderInfo: {},
				materialList: [],
				activeNames: [],
				orderTime: "",
				dragMaterialList: [],
				changeSortIndex: [],
				cancelModal: false,
				cancelInfo: '',
				processInfoAct: [],
				processInfo: [{
						"status": "100.Auditing",
						"label": "提交审批",
						"time": ''
					},
					{
						"status": "110.Audited",
						"label": "已审核待入场",
						"time": ''
					},
					{
						"status": "600.Reject",
						"label": "已拒绝",
						"time": ''
					},
				
					{
						"status": "290.Entry",
						"label": "已入场",
						"time": ''
					},
					{
						"status": "400.Exit",
						"label": "已离场",
						"time": ''
					}
				],
				time: {},
				locationTime: ''
			}
		},
		methods: {
			tagClass(statusLabel){
				let result  = ""
				if(statusLabel == '已拒绝'){
					result = 'tag-reject'
				}else if(statusLabel == '已审核待入场' || statusLabel == '已入场'){
					result = 'tag-checked'
				}else if(statusLabel == '待审核'){
					result = "tag-checking"
				}else{
					result = "closed"
				}
				return result
			},

			copyAccessNo() {
				uni.setClipboardData({
					data: this.isEmpty(this.orderInfo.accessNo)
				});
			},
			
			getTimeLabel(time, type) {
				if (time) {
					return formatGMT(time, type)
			
				}
				return ''
			},

			handleStatus() {
				this.processInfoAct = [];
				let {status,statusLabel,auditRemarks} = this.orderInfo

				for (let item of this.processInfo){
					switch(item.status){
						case "100.Auditing": 
							item.time = this.orderInfo.bookingTime;
							this.processInfoAct.push(item)
							break;
						case "110.Audited": 
							item.time = this.orderInfo.auditTime;
							if(status != "600.Reject"){
								item.auditRemarks = auditRemarks 
								this.processInfoAct.push(item)
							}
							break;
						case "600.Reject": 
							item.time = this.orderInfo.auditTime; 
							if(status == "600.Reject"){
								this.processInfoAct.push(item)
								item.auditRemarks = auditRemarks
								return
							}
							break;
						case "290.Entry": 
							if(status == "290.Entry"){
								item.time = this.orderInfo.entryTime; 
							}
							this.processInfoAct.push(item)
							break;
						case "400.Exit": 
							if(status == "400.Exit"){
								item.time = this.orderInfo.exitTime;
							}
							this.processInfoAct.push(item)
							break;
					} 
				}
			},

			isEmpty(value) {
				if (value) return value
				return ''
			},

			btnClick() {
				if (this.isDrag) {
					this.changeCargoSort()
					this.materialList = this.dragMaterialList
				} else {
					this.isDrag = true

				}
			},

			changeDock(materialInfo) {
				console.log(materialInfo)
				uni.navigateTo({
					url: `/subpkg/changeDock/changeDock?materialInfo=${JSON.stringify(materialInfo)}`
				})
			},

			getVisitOrderDetails() {
				let that = this
				getVisitOrderDetails({
					"args": {

					},
					"aux": {
						"id": this.orderId
					}
				}).then(res => {
					that.orderInfo = res.data.data.header
					that.addressName = res.data.data.header["address.name"]
					this.handleStatus()
				}).catch(res => {
					console.log(res)
				})
			},

			changeCargoSort() {
				let that = this
				ChangeCargoSort({

					// "args":{
					// 	items :
					// 	   that.changeSortIndex
					// },
					"aux": {
						items: that.changeSortIndex
					}
				}).then(res => {
					that.isDrag = false
					that.getVisitOrderDetails()
				})
			}
		},
		onLoad(atts) {
			this.orderId = atts.id
			this.getVisitOrderDetails()
			
		},
		mounted() {},
		computed: {
			current() {
				for (let i = this.processInfoAct.length - 1; i >= 0; i--) {
					if (this.processInfoAct[i].time) {
						return i
					}

				}
				return -1
			}
		},
		onShow() {
			this.orderInfo = {},
			this.materialList = []
			this.dragMaterialList = []
			this.getVisitOrderDetails()
		}
	}
</script>

<style lang="scss" scoped>
	.visitOrderDetail {
		
		background-color: #F9F9F9;

		.cargoDetail-item {
			padding: 0 24rpx;
			margin-bottom: 24rpx;
			padding-bottom: 24rpx;
			background: #FFFFFF;
			position: relative;
			opacity: 0.8;
			color: #434343;

			.custom-cell-label {
				color: #8C8C8C;
			}



		}

		.material {
			padding: 0 24rpx;
			margin-bottom: 32rpx;
			background: #FFFFFF;

			.detail-row-title {
				color: #8C8C8C;
				height: 64rpx;
				line-height: 64rpx;
				padding-left: 20rpx;
			}

			/deep/.custom-cell-row {
				margin-top: 16rpx;

			}

			.outer-frame {
				overflow: hidden;

				.foldPanel-title {
					color: #434343;
					font-size: 28rpx;
					padding-left: 20rpx;
					font-weight: bolder;
					height: 88rpx;
					background-color: #F0F0F0;
					border-radius: 10rpx;

					.foldPanel-right-icon {
						margin-right: 20rpx;
					}
				}

				/deep/.uni-collapse-item {
					margin-top: 24rpx;

				}

				/deep/.cargo-detail-table {
					background: #FFFFFF;
					padding-bottom: 10rpx;


					.detail-col-item {
						margin: 32rpx 20rpx;

						.cargo-title {
							font-size: 28rpx;
							padding-left: 20rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
					}

					.change_btn {
						height: 64rpx;
						width: 171rpx;
						border: 2rpx solid #8C8C8C;
						border-radius: 32rpx;
						color: #8C8C8C;
						font-size: 28rpx;
						line-height: 64rpx;
						margin-right: 24rpx;
					}
				}

			}
		}

		.detail-title {
			font-size: 28rpx;
			color: #BCBCBC;
			margin-top: 31rpx;
			justify-content: space-between;
			padding-bottom: 24rpx;

			.t-icon-order {
				width: 50rpx;
				height: 50rpx;
				margin-right: 20rpx;
			}


			.detail-title-label {
				height: 48rpx;
				text-align: center;
				line-height: 48rpx;
				border-radius: 8rpx;
				padding: 0 24rpx;
			}

			.tag-checked{
				color:rgba(102, 204, 204, 1) !important; 
				background: rgba(102, 204, 204, 0.1) !important;
			}
			.tag-checking{
				color:rgba(247, 166, 74, 1); 
				background: rgba(247, 166, 74, 0.1);
			} 
			.tag-reject{
				color:rgba(235, 47, 72, 1); 
				background: rgba(235, 47, 72, 0.1);
			}

			.closed {
				background-color: #bfbfc1;
				color: #fefeff;
			}

			image {
				width: 28rpx;
				height: 28rpx;
				margin-left: 12rpx;
			}

			img {
				width: 28rpx;
				height: 28rpx;
				margin-left: 12rpx;
			}
		}

s
		/deep/.u-modal {
			.u-modal__title {
				color: #434343 !important;
				font-weight: unset !important;
				padding: 38rpx auto !important;
			}

			.u-textarea {
				background-color: #FAFAFA;
			}
		}


		.passDetail {
			margin: 0 24rpx;
			/deep/.u-steps {
				flex: 1;

				.u-text {
					flex: none;

					.u-text__value {
						font-size: 28rpx !important;
					}
				}

				.u-steps-item {
				
					flex: none;

					&:last-child {
						height: auto;
					}
				}

				.u-steps-item__wrapper__dot {
					width: 32rpx;
					height: 32rpx;
				}

				.u-steps-item__wrapper {
					background-color: #fff !important;
				}

				.u-steps-item__content {
					margin-left: 32rpx !important;
				}

				.u-icon__icon {
					font-size: 32rpx !important;
				}
			}

			/deep/.u-steps-item__line {
				height: 100% !important;

				&:last-child {
					height: 0 !important;
				}
			}

			.slot-icon {
				width: 32rpx;
				height: 32rpx;
				background-color: transparent;
				border-radius: 100px;
				font-size: 12px;
				color: #2E75E6;
				line-height: 21px;
				text-align: center;
			}


			.passIcon {
				display: inline-flex;
				justify-content: center;
				align-items: center;
				width: 32rpx;
				height: 32rpx;
				background-color: #2E75E6;
				border-radius: 50%;
			}

			.passIcon::after {
				content: '✓';
				color: #fff;
				font-size: 24rpx;
				font-weight: bold;
			}

			.rejectIcon{
				display: inline-flex;
				justify-content: center;
				align-items: center;
				width: 32rpx;
				height: 32rpx;
				background-color: red;
				border-radius: 50%;
			}
			.rejectIcon::after {
				content: '×';
				color: #fff;
				font-size: 24rpx;
				font-weight: bold;
			}

		}

		.descSlot{
			width: 100%;
			background: #F5F5F5;
			border-radius: 8rpx;
			font-size: 28rpx;
			color: #434343;
			padding: 24rpx;
		}

	}
</style>
