<template>
	<view class="flex-col" :style="{height: winHeight + 'px'}">
		<!-- #ifdef MP -->
		<view class="cart_nav">
			<nav-bar iconColor='#fff' ref="navBarRef" navTitle="代取快递" backgroundColor="#FF6702" :isBackgroundColor="false">
			</nav-bar>
		</view>
		<!-- #endif -->
		<!-- <view class='newsList tui-skeleton flex-col' style="background-color: #fff;flex: 1;"> -->
		<!-- <view class='nav'>
				<scroll-view class="scroll-view_x" scroll-x scroll-with-animation :scroll-left="scrollLeft" style="width:auto;overflow:hidden;">
					<block v-for="(item,index) in navList" :key="index">
						<view class='item borRadius14 tui-skeleton-rect' :class='active==item.id?"on":""' @click='tabSelect(item.id, index)'>
							<view class="line1">{{item.name}}</view>
							<view class='line bg_color' v-if="active==item.id"></view>
						</view>
					</block>
				</scroll-view>
			</view> -->
		<view class="fast-top">送至：XXXXXXXXXXXXXXXXXXX <text>XXX</text> 收 19992837748<text class="iconfont icon-zhankai"></text></view>
		<navigator url="/pages/substitute_fast_mail/take_fast_mail/index">
			<view class="flex-center fast-top">
				<view class="fast-jia flex-center">
					＋
				</view>
				<view>添加代取快递信息</view>
			</view>
		</navigator>
		<scroll-view scroll-y scroll-with-animation style="flex: 1;overflow: hidden;">
			<view class="fast-box">
				<view class="flex-between-center">
					<view>
						<view class="fast-yz">XXXXXXXXXXXXXX驿站</view>
						<view class="fast-xx">XXXXXXXXXXXXXXXXXXXXXXXX宿舍</view>
					</view>
					<view class="flex-y-center">
						<image src="/static/img/phone.png" class="image2" /><text>联系驿站</text>
					</view>
				</view>
				<view class="flex-around-center fast-item">
					<radio class="radio" value="" color="#FF6702" />
					<image style="width: 135rpx; height: 135rpx;border-radius: 30rpx;" src="/static/img/ic-qu-chengse.png"></image>
					<view>
						<view class="fast-yz">取件码 <text>9-9-9999</text></view>
						<view class="fast-xx">圆通快递 YT1208768435738849</view>
					</view>
					<view>
						<view class="fast-yz">134m</view>
						<view class="bg-color-cash">￥<text class="fast-cash">2.50</text></view>
					</view>
				</view>
			</view>
		</scroll-view>
		<!-- <view class='list' style="flex: 1;">
				<template v-if="active == 1">
					<take-fast-mail ref="takeFastMailRef" :addressObj="addressItem" :addressExpressObj="addressExpressItem"></take-fast-mail>
				</template>
				<template v-if="active == 2">
					<send-fast-mail></send-fast-mail>
				</template>
			</view> -->
		<!-- 购物车栏 begin -->
		<view class="cart-box">
			<view class="mark-box">
				<view class="mark">应付 ￥ <text style="font-size: 31rpx;">{{orderPrice}}</text></view>
				<view class="tips">普通用户 | 查看明细 》</view>
			</view>
			<button type="primary" class="pay-btn" @tap="toPay">
				提交订单
			</button>
		</view>
		<!-- </view> -->
		<fast-mail-order v-if="isOrder" @onCancel="onCanCel"></fast-mail-order>
	</view>
</template>

<script>
	// +----------------------------------------------------------------------
	// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
	// +----------------------------------------------------------------------
	// | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
	// +----------------------------------------------------------------------
	// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
	// +----------------------------------------------------------------------
	// | Author: CRMEB Team <admin@crmeb.com>
	// +----------------------------------------------------------------------
	import navBar from '@/components/navBar';
	import animationType from '@/utils/animationType.js'
	import tuiSkeleton from '@/components/base/tui-skeleton.vue';
	import sendFastMail from '../components/send_fast_mail/index.vue'
	import fastMailOrder from '../components/fast_mail_order/index.vue'
	import {
		preExpressApi
	} from '@/api/fastMail.js';
	let app = getApp();
	export default {
		components: {
			tuiSkeleton,
			navBar,
			sendFastMail,
			fastMailOrder
		},
		data() {
			return {
				isOrder: false, // 提交快递订单弹窗
				winHeight: 0,
				isNodes: 0, //控制什么时候开始抓取元素节点,只要数值改变就重新抓取
				autoplay: true,
				navList: [{
					id: 1,
					name: '取快递',
					preOrderType: 'take'
				}, {
					id: 2,
					name: '寄快递',
					preOrderType: 'send'
				}],
				navListIndex: 0,
				active: 0,
				scrollLeft: 0,
				addressItem: {},
				orderPrice: 0,
				addressExpressItem: {}
			};
		},
		onLoad() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					that.winHeight = res.windowHeight
				},
			});
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
		},
		methods: {
			tabSelect(active, e) {
				this.active = active;
				this.navListIndex = e;
				this.scrollLeft = e * 60;
			},
			toPay() {
				const refTake = this.$refs.takeFastMailRef;
				// uni.showLoading({
				// 	title: '保存中',
				// 	mask: true
				// })
				this.orderPrice = +(refTake.fastMailObj.giveTips || 0) + +refTake.fastMailObj.sepec.fee || 0
				let value = {
					giveTips: refTake.fastMailObj.giveTips,
					orderDetails: [{
						expressInfo: refTake.fastMailObj.expressInfo || '',
						expressNum: 1,
						image: refTake.fastMailObj.figureArr ? refTake.fastMailObj.figureArr[0] : '',
						orderNo: "",
						price: this.orderPrice || 0,
						remark: refTake.fastMailObj.remark || '',
						sepec: +refTake.fastMailObj.sepec.fee || 0
					}],
					postAddressId: refTake.addressExpressObj.id,
					preOrderType: this.navList[this.navListIndex].preOrderType,
					userAddressId: refTake.addressObj.id
				}
				const tips = this.checkData(value)
				if (tips) {
					return this.$util.Tips({
						title: tips
					});
				}
				preExpressApi(value).then(res => {
					this.isOrder = true;
					console.log(res)
					// uni.hideLoading();
				}).catch(err => {
					uni.showToast({
						title: err,
						icon: 'none'
					})
				})
				console.log(value)
			},
			onCanCel(val) {
				this.isOrder = val
			},
			checkData(val) {
				if (!val.postAddressId) return '请填写取件地'
				if (!val.userAddressId) return '请填写收件人信息'
				if (!val.orderDetails[0].sepec) return '快递规格必选'
				if (!val.orderDetails[0].expressInfo) return '请填写快递信息'
			}
		}
	}
</script>

<style lang="scss">
	.courie {
		padding: 14rpx 24rpx 0 24rpx;
		font-weight: 500;
		font-size: 23rpx;
		color: $bg-color-primary;
		background-color: #fff;

		image {
			width: 46rpx;
			height: 46rpx;
			margin-right: 15rpx;
		}
	}

	.fast-top {
		width: 100%;
		height: 80rpx;
		padding: 0 30rpx;
		line-height: 80rpx;
		font-weight: 600;
		font-size: 27rpx;
		color: #141414;
		background-color: #fff;
		margin-bottom: 20rpx;
		border-radius: 20rpx;
	}

	.image2 {
		width: 42rpx;
		height: 42rpx;
		margin-right: 20rpx;
	}

	.fast-jia {
		width: 44rpx;
		height: 44rpx;
		color: #fff;
		font-size: 40rpx;
		border-radius: 50%;
		background-color: $bg-color-primary;
		margin-right: 20rpx;
	}

	.fast-box {
		padding: 30rpx;
		background-color: #fff;

		.fast-item {
			padding: 20rpx 0;
			background-color: #F8F9FB;
			margin-bottom: 10rpx;
		}

		.flex-between-center {
			margin-bottom: 20rpx;
		}

		.fast-yz {
			font-weight: 600;
			font-size: 27rpx;
			color: #141414;

			text {
				color: #FF0000;
			}
		}

		.fast-xx {
			font-weight: 500;
			font-size: 23rpx;
			color: #646464;
			margin-top: 10rpx;
		}

		.bg-color-cash {
			margin-top: 30rpx;
			color: $bg-color-primary;

			text {
				font-weight: 500;
				font-size: 25rpx;
			}
		}
	}

	.newsList .nav {
		padding: 0 24rpx;
		width: 100%;
		white-space: nowrap;
		box-sizing: border-box;
		padding-top: 43rpx;
		border-top-right-radius: 23rpx;
	}

	.newsList .nav .item {
		// max-width: 156rpx;
		display: inline-block;
		font-size: 32rpx;
		color: #999;
	}

	.newsList .nav .item.on {
		color: #282828;
	}

	.newsList .nav .item~.item {
		margin-left: 46rpx;
	}

	.newsList .nav .item .line {
		// width: 24rpx;
		height: 10rpx;
		border-radius: 6rpx;
		margin: 10rpx auto 0 auto;
		background-color: $bg-color-primary;
	}

	.newsList .nav .item .line1 {
		color: $bg-color-primary;
	}

	.cart-box {
		height: 96rpx;
		border-radius: 48rpx;
		box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.2);
		background-color: #000;
		display: flex;
		align-items: center;
		justify-content: space-between;
		z-index: 9999;

		.pay-btn {
			height: 100%;
			padding: 0 30rpx;
			color: #FFFFFF;
			border-radius: 0 50rpx 50rpx 0;
			display: flex;
			align-items: center;
			font-size: $font-size-base;
			background-color: $bg-color-primary;
		}

		.mark-box {
			padding-left: 46rpx;
			margin-right: 30rpx;
			position: relative;

			.mark {
				font-weight: 500;
				font-size: 23rpx;
				color: #FFFFFF;
			}

			.tips {
				font-weight: 500;
				font-size: 27rpx;
				color: #999999;
			}
		}
	}
</style>
