<template>
	<view>
		<navbar title="订单详情" leftClick @leftClick="$utils.navigateBack" />

		<!-- 水洗店 -->
		<view class="" v-if="userShop">
			<view class="controls">
				<view class="title">
					<image src="../static/order/icon.png" mode=""></image>
					{{ order.statusDictText }}
				</view>
				<!-- <view class="tips">
					待送回
				</view> -->
				
				<!-- <orderTypeBtn
				:type="order.type" 
				:status="order.status" 
				:detail="order"></orderTypeBtn> -->
				
				<view class="btns">
					<view
					 v-if="[4, 18, 19].includes(order.status)"
					@click.stop="orderConfirmAccept(order)">
						确认接单
					</view>
					
					<!-- 待收货 -->
					<template v-if="order.status == 2">
						<view @click.stop="confirmReceiveGoods(order)">
							确认收货
						</view>
						<view @click.stop="" class="btn2">
							查看物流
						</view>
					</template>
						
					<!-- 待检查 -->
					<template v-if="order.status == 5">
						<view @click.stop="orderConfirmedDamage(order, 1)"
						>
							确认下一步
						</view>
						
						<view @click.stop="$utils.navigateTo
						(`/pages_order/order/damageReport?id=${order.id}`)" 
						class="btn2"
						>
							破损上报
						</view>
					</template>
					
					<view
					 v-if="[8, 12].includes(order.status)"
					@click.stop="$refs.deliverGoods.open()" class="b2">
						发货填写单号
					</view>
					
					<view
					 v-if="[6].includes(order.status)"
					@click.stop="orderFinishedWashing(order)">
						水洗完成
					</view>
					
				</view>
				
			</view>
			<view class="steps" v-if="steps.length > 0">
				<uv-steps activeColor="#FD5100"
				:current="stepsCurrent" dot>
					<uv-steps-item 
					:title="item.name" 
					:key="index" 
					v-for="(item, index) in steps">
					</uv-steps-item>
				</uv-steps>
			</view>
		</view>

		<!-- 酒店和水洗店 -->
		<view class="info">
			<view class="flex" style="display: flex;">
				<view style="width: 8rpx;height: 30rpx;
				background: #FD5100;border-radius: 6rpx;" />
				<view class="head-title">{{ typeText[order.type].name }}</view>
			</view>

			<view class="flex">
				<view class="server-item"
				v-for="(p, i) in order.orderDetails"
				:key="i">

					<view class="img-box">
						<image :src="p.pic" mode="aspectFill"></image>
					</view>

					<view class="server-info">

						<view class="server-title">
							{{p.goodsName}}
							<!-- <view class="coupon">领券立减</view> -->
						</view>

						<!-- <view class="current-price" v-if="order.orderPay">
							<text class="unit">￥</text>{{order.orderPay}}
						</view> -->
						
						<view
						class="current-price"
						v-if="p.washPay">
							水洗费用：{{ p.washPay }}元
						</view>
						
						<view
						class="current-price"
						v-if="p.rentPay">
							租赁费用：{{ p.rentPay }}元
						</view>
						
						<view
						class="current-price"
						v-if="p.deposit">
							押金：{{ p.deposit }}元
						</view>

						<view class="sales-volume" style="margin-top: 5px;">
							<view class="desc">规格：{{p.sku}}</view>
						</view>

						<view class="sales-volume" style="margin-top: 5px;">
							<view class="desc">数量：{{p.num}}</view>
						</view>

						<view class="time-coupon">

							<!-- <view class="flex">
								<image src="@/static/home/time-icon.png"></image>
								<view class="time">{{msgOrder.useTime}}分钟</view>
							</view> -->

							<!-- <view class="sales-volume">
								<image src="@/static/icons/icon1.png"></image>
								<view class="desc">已售出{{msgShop.payNum}}+单</view>
							</view> -->

						</view>

					</view>

				</view>
			</view>

			<!-- <view class="line min_tips">
				<view class="head-div flex">
					<view style="width: 118rpx;height: 118rpx;border-radius: 50%;overflow: hidden;">
						<image style="width: 118rpx;" :src="msgTechnician.image" mode="widthFix"></image>
					</view>
					<view style="padding: 10rpx 34rpx;display: flex;flex-direction: column;justify-content: space-around;">
						<view class="nickname">
							{{msgTechnician.title}}
							<view v-if="msgTechnician.isVip" class="tag">
								<image src="@/static/order/s.png" mode="aspectFit"></image>
								<view class="auth">官方认证</view>
							</view>
						</view>
						<view class="days">
							<van-rate v-model="msgTechnician.score" :size="10" readonly color="#ffb54c" void-icon="star"
								void-color="#eee" />
							<view class="">
								好评{{msgTechnician.pinNum}}
							</view>
						</view>
					</view>
				</view>
				<view @click="gototechnicianDetail(msgTechnician)" class="btn-x">
					服务技师
				</view>
			</view> -->

			<view class="line address">
				<view class="address-top">
					<view class="">
						收货地址
					</view>
					<view class="copy">
						<image
							@click="$utils.copyText(order.userName + ' ' + order.userPhone + ' ' + order.userAddress)"
							src="../static/order/copy.png"></image>
					</view>
				</view>
				<view class="addressDetail">
					<view class="">{{order.userName}} {{order.userPhone}}</view>
					<view class="">{{order.userAddress}}</view>
				</view>
			</view>


			<view class="line">
				<view class="t min_tips" v-if="!userShop && order.originalPrice">
					<view class="">
						应付款
					</view>
					<view class="current-price">
						￥{{ order.originalPrice }}
					</view>
				</view>

				<!-- 水洗店不展示 -->
				<view class="t min_tips" v-if="!userShop && order.orderPay">
					<view class="">
						实付款
					</view>
					<view class="current-price">
						￥{{ order.orderPay }}
					</view>
				</view>

				<!-- 水洗店不展示 -->
				<view class="min_tips" v-if="!userShop && order.rentPay">
					<view class="">
						租赁费用
					</view>
					<view class="">
						￥{{ order.rentPay }}
					</view>
				</view>

				<view class="min_tips" v-if="order.washPay">
					<view class="">
						水洗费用
					</view>
					<view class="">
						￥{{ order.washPay}}
					</view>
				</view> 
				<!-- <view class="min_tips">
					<view class="">
						押金
					</view>
					<view class="">
						￥{{ order.price }}
					</view>
				</view> -->

				<view class="min_tips" v-if="order.discountPrice">
					<view class="">
						已优惠
					</view>
					<view class="">
						￥{{ order.discountPrice}}
					</view>
				</view> 
			</view>

			<!-- 订单信息 -->
			<view class="line">
				<view class="t min_tips">
					<view class="">
						订单信息
					</view>
				</view>
				<view class="min_tips">
					<view class="">
						订单编号
					</view>
					<view class="">
						{{order.id}}
					</view>
				</view>
				<view class="min_tips">
					<view class="">
						下单时间
					</view>
					<view class="">
						{{order.createTime}}
					</view>
				</view>
			</view>


			<!-- 下单须知 -->
			<view class="line">
				<!-- <view class="t min_tips">
					<view class="">
						下单须知
					</view>
				</view>
				<view class="min_tips" style="line-height: 40rpx;">
					{{msgShop.projectExplain}}
				</view> -->
				<view class="btns">
					<view 
					v-if="!userShop"
					@click="$utils.navigateTo('/pages_order/order/createWash')" 
					class="btnS">
						我要水洗
					</view>
				</view>
				<view class="btns">
					
					<view @click="$refs.customerServicePopup.open()" class="btn">
						联系平台客服
					</view>
					
					<view 
					v-if="userShop"
					@click="$refs.customerServicePopup.open(order.userPhone, '客户')" class="btn">
						联系客户
					</view>
					
					<view 
					v-else
					@click="$refs.customerServicePopup.open(bindShop.phone, '水洗店')" class="btn">
						联系水洗店
					</view>
				</view>
			</view>

		</view>
		
		<deliverGoods
		ref="deliverGoods"
		:orderId="orderId"
		@getData="getData"/>
		
		
		<!-- 联系客服弹框 -->
		<customerServicePopup ref="customerServicePopup" />
	</view>
</template>

<script>
	import {
		mapGetters,
		mapState
	} from 'vuex'
	import mixinOrder from '@/mixins/order.js'
	import customerServicePopup from '@/components/config/customerServicePopup.vue'
	import deliverGoods from '@/components/userShop/deliverGoods.vue'
	export default {
		components: {
			customerServicePopup,
			deliverGoods,
		},
		mixins : [mixinOrder],
		computed: {
			...mapGetters(['userShop']),
			...mapState(['bindShop']),
		},
		data() {
			return {
				stepsCurrent: 0,
				steps: [//水洗店看到的步骤条
					// [//租赁订单
					// 	'客户待支付',
					// 	'平台待发货',
					// 	'待收货',//确认收货接口
					// 	'服务完成',
					// ],
					// [//水洗订单
					// 	'客户待支付',
					// 	'检查破损',//确认破损状态接口
					// 	'开始清洗',//开始清洗接口
					// 	'服务完成',
					// ],
					// [//换货
					// 	'下单',
					// 	'寄回商品',//快递接口
					// 	'平台待收货',
					// 	'客户待支付',
					// 	'服务完成',
					// ],
					// [//退货
					// 	'下单',
					// 	'寄回商品',//快递接口
					// 	'平台待收货',
					// 	'服务完成',
					// ],
				],
				order: {},
				orderId: 0,
				typeText: [{
						name: '租赁押金'
					},
					{
						name: '水洗租赁'
					},
					{
						name: '破损换货'
					},
					{
						name: '退货退款'
					}
				],
			}
		},
		onLoad(agrs) {
			this.orderId = agrs.id
		},
		onShow() {
			this.getData()
			if(this.userShop){
				this.typeText[0].name = '租赁订单'
				this.$forceUpdate()
			}else{
				this.$store.commit('getBindShop')
			}
		},
		onPullDownRefresh() {
			this.getData()
			if(this.userShop){
			}else{
				this.$store.commit('getBindShop')
			}
		},
		methods: {

			// 查询订单详情
			getData() {
				this.$api('orderOne', {
					id: this.orderId
				}, res => {
					uni.stopPullDownRefresh()
					if (res.code == 200) {
						this.order = res.result
						
						res.result.hotelOrderFlows.forEach((n, i) => {
							if(this.order.status == n.value){
								this.stepsCurrent = i
							}
						})
						
						this.steps = res.result.hotelOrderFlows
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.order {
		padding-bottom: 10px;
	}

	.controls {
		margin: 20rpx;
		background-color: #fff;
		height: 400rpx;
		display: flex;
		flex-direction: column;
		width: 710rpx;
		border-radius: 20rpx;
		justify-content: center;
		align-items: center;

		.title {
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 40rpx;

			image {
				width: 100rpx;
				height: 100rpx;
				margin-right: 20rpx;
			}
		}

		.tips {
			font-size: 26rpx;
			color: #FD5100;
			margin-top: 10rpx;
		}

		.btns {
			margin-top: 50rpx;
			display: flex;
			view {
				margin: 0 20rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				color: #fff;
				background-color: $uni-color;
				padding: 15rpx 40rpx;
				border-radius: 40rpx;
			}

			.btn2 {
				background-color: #FFFFFF;
				border: 1px solid #A7A7A7;
				color: #A7A7A7;
			}
		}
	}

	.steps {
		margin: 20rpx;
		background-color: #fff;
		display: flex;
		flex-direction: column;
		width: 710rpx;
		border-radius: 20rpx;
		padding: 70rpx 0;

		/deep/ .uv-text__value {
			font-size: 22rpx !important;
		}
	}

	// .box {
	// 	padding: 20px;

	// 	.btns {
	// 		display: flex;
	// 		justify-content: center;
	// 		align-items: center;
	// 		margin-top: 10px;

	// 		.btn {
	// 			color: #fff;
	// 			padding: 10rpx 50rpx;
	// 			background-color: #ffb300;
	// 			border-radius: 30rpx;
	// 			font-size: 25rpx;
	// 			margin-right: 10rpx;
	// 		}

	// 		.btc {
	// 			background: #ccc;
	// 		}
	// 	}
	// }

	.info {
		margin: 10px;
		padding: 20rpx;
		background-color: #fff;
		width: calc(100% - 40px);
		border-radius: 10px;

		.head-title {
			font-family: PingFang SC, PingFang SC-Bold;
			color: #2f2e2e;
			line-height: 30rpx;
			margin-left: 10rpx;
		}

		.server-item {
			display: flex;
			flex-wrap: wrap;
			align-items: center;
			justify-content: space-between;
			background: white;
			border-radius: 15rpx;
			box-sizing: border-box;
			margin: 20rpx 0rpx;
			width: 100%;

			.img-box {
				width: 180rpx;
				height: 180rpx;
				border-radius: 10rpx;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.server-info {
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				width: calc(100% - 180rpx);
				box-sizing: border-box;
				padding: 10rpx 15rpx;

				.server-title {
					display: flex;
					margin-bottom: 10rpx;
				}

				.coupon {
					display: flex;
					justify-content: center;
					align-items: center;
					background: #F29E45;
					color: white;
					width: 120rpx;
					height: 40rpx;
					border-radius: 10rpx;
					margin-left: 10rpx;
					font-size: 22rpx;
				}

				.time-coupon,
				.price {
					display: flex;
					flex-wrap: wrap;
					align-items: center;
				}

				.time-coupon {
					margin: 10rpx 0rpx;
					font-size: 26rpx;
					justify-content: space-between;
					width: 100%;

					.flex {
						justify-content: center;
						align-items: center;
					}

					image {
						width: 25rpx;
						height: 25rpx;
					}

					.time {
						color: #B8B8B8;
						margin-left: 6rpx;
					}
				}

				.sales-volume {
					display: flex;
					align-items: center;
					color: #B8B8B8;
					font-size: 24rpx;

					image {
						width: 25rpx;
						height: 25rpx;
					}
				}
			}
		}

		.address {

			.address-top {
				display: flex;
				justify-content: space-between;
				align-items: center;

				image {
					width: 30rpx;
					height: 30rpx;
				}
			}

			.addressDetail {
				color: #777;
				font-size: 22rpx;
				padding: 5px 0;
			}

			text {
				background-color: #F29E45;
				padding: 8rpx 10rpx;
				color: #fff;
				font-size: 20rpx;
				margin-left: 10px;
				border-radius: 5px;
			}
		}

		.min_tips {
			font-size: 22rpx;
			color: #777;
			display: flex;
			justify-content: space-between;
			padding: 5px 0;
			align-items: center;
		}

		.current-price {
			font-size: 22rpx;
			color: $uni-color;
		}

		.line {
			border-top: 2px dotted #00000011;
			padding: 20rpx 0;

			.t {
				padding: 5px 0;
				color: #000;
				font-size: 26rpx;
			}
		}

		.head-div {
			.nickname {
				font-size: 30rpx;
				font-weight: 600;
				text-align: left;
				line-height: 42rpx;
				display: flex;
				align-items: center;

				.tag {
					position: relative;
					display: flex;
					align-items: center;

					image {
						height: 45rpx;
						width: 90rpx;
						vertical-align: middle;
					}

					.auth {
						position: absolute;
						white-space: nowrap;
						color: $uni-color;
						left: 23rpx;
						font-size: 17rpx;
					}
				}
			}

			.days {
				font-size: 20rpx;
				font-weight: 400;
				text-align: left;
				line-height: 56rpx;
				display: flex;
				align-items: center;

				view {
					padding-left: 5px;
				}
			}
		}

		.btn-x {
			color: $uni-color;
			border: 1px solid $uni-color;
			padding: 10rpx 20rpx;
			border-radius: 30rpx;
		}

		.btns {
			display: flex;
			justify-content: space-around;
			margin: 20rpx 0;

			.btnS{
				background-color: $uni-color;
				color: #fff;
				box-shadow: 0 0 5rpx 5rpx #FFAC6E;
				padding: 20rpx 0;
				flex-shrink: 0;
				border-radius: 35rpx;
				flex: 1;
				text-align: center;
			}
			
			.btn {
				color: $uni-color;
				border: 1px solid $uni-color;
				padding: 10rpx 20rpx;
				border-radius: 30rpx;
				flex: 1;
				margin: 10rpx;
				text-align: center;
			}
		}
	}
</style>