<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> -->
		<navigator url="/pages/address/user_address_list/index">
			<view class="fast-top">
				<view>
					送至：{{addressItem.province}}{{addressItem.city}}{{addressItem.district}}{{addressItem.street}}{{addressItem.detail}}
				</view>
				<view style="margin-top: 10rpx;">
					<text>{{addressItem.realName}}</text> 收 {{addressItem.phone}}<text class="iconfont icon-jiantou"></text>
				</view>
			</view>
		</navigator>
		<!-- <navigator url="/pages/substitute_fast_mail/take_fast_mail/index"> -->
		<view class="flex-center fast-top" @tap="onAddFastMail">
			<view class="fast-jia">
				＋
			</view>
			<view>添加代取快递信息</view>
		</view>
		<!-- </navigator> -->
		<scroll-view scroll-y scroll-with-animation style="flex: 1;overflow: hidden;">
			<view class="fast-box" v-for="(item, index) in fastMailData.postOrderList || []" :key="index">
				<view class="flex-between-center">
					<view>
						<view class="fast-yz">{{item.postName}}</view>
						<view class="fast-xx">{{item.addressDetail}}</view>
					</view>
					<view class="flex-y-center">
						<image src="/static/img/phone.png" class="image2" /><text>联系驿站</text>
					</view>
				</view>
				<view class="fast-item" v-for="(value, index) in item.orderInfoList">
					<view class="flex-between-center">
						<radio class="radios" :checked="value.radio" color="#FF6702" @tap="value.radio = !value.radio" />
						<image style="width: 135rpx; height: 135rpx;border-radius: 30rpx;" src="/static/img/ic-qu-chengse.png"></image>
						<view>
							<view class="fast-yz">取件码 <text>{{value.pickUpCode}}</text></view>
							<view class="fast-xx">{{value.expressCompany}} {{value.expressNo}}</view>
							<view class="fast-yz">规格：{{value.spec}}</view>
						</view>
						<view>
							<!-- <view class="fast-yz">134m</view> -->
							<view class="bg-color-cash">￥<text class="fast-cash">{{value.price}}</text></view>
						</view>
					</view>
					<view class="fast-remark">
						<view v-if="value.remark">备注：{{value.remark}}</view>
						<view class="flex-y-center" v-if="value.image" @tap="lookImg(value.image)">
							<text>附图：</text>
							<image style="width: 38rpx; height: 38rpx;" src="/static/img/ic-figure.png"></image>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<!-- <view class='list' style="flex: 1;">
				<template v-if="active == 1">
				</template>
				<template v-if="active == 2">
					<send-fast-mail></send-fast-mail>
				</template>
			</view> -->
		<view class="fast-tip flex-y-center">
			<radio :checked="radioArr" color="#FF6702" @tap="onRadioChang()" />全选
			<view style="margin-left: 30rpx;">删除</view>
		</view>
		<view class="flex-between-center fast-tip" @tap="isTip = true">
			<view class="remark-name">小费</view>
			<view class="flex-y-center">
				<text style="font-weight: 400;font-size: 27rpx;color: #646464;">{{giveTips}}</text>
				<view class='iconfont icon-jiantou' style="font-size: 30rpx;margin: 0 19rpx;"></view>
			</view>
		</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>
		<take-fast-mail v-if="isTake" :orderNo="preOrderNo" :addressObj="addressItem" @onTakeFastOk="onTakeChang" @onCancel="onCanCel"></take-fast-mail>
		<fast-mail-tip v-if="isTip" :value="giveTips" @tipValue="onTipValue" @onCancel="onCanCel"></fast-mail-tip>
	</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 takeFastMail from '../take_fast_mail/index.vue'
	import fastMailOrder from '../components/fast_mail_order/index.vue'
	import fastMailTip from '../components/fast_mail_tip/index.vue'
	import {
		preExpressApi,
		loadPreExpressApi
	} from '@/api/fastMail.js';
	import {
		getAddressDefault,
		getAddressExpressDefault
	} from '@/api/user.js';
	let app = getApp();
	export default {
		components: {
			tuiSkeleton,
			navBar,
			sendFastMail,
			fastMailOrder,
			takeFastMail,
			fastMailTip
		},
		data() {
			return {
				isOrder: false, // 提交快递订单弹窗
				isTake: false, // 新增快递弹窗
				isTip: false, // 小费弹窗
				giveTips: '',
				winHeight: 0,
				isNodes: 0, //控制什么时候开始抓取元素节点,只要数值改变就重新抓取
				autoplay: true,
				radioArr: false,
				radioDel: false,
				preOrderNo: '',
				navList: [{
					id: 1,
					name: '取快递',
					preOrderType: 'take'
				}, {
					id: 2,
					name: '寄快递',
					preOrderType: 'send'
				}],
				fastMailData: {},
				navListIndex: 0,
				active: 0,
				scrollLeft: 0,
				addressItem: {},
				orderPrice: 0
			};
		},
		onLoad() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					that.winHeight = res.windowHeight
				},
			});
			getAddressDefault().then(res => {
				console.log('地址', res)
				this.addressItem = res.data || {}
			})
			// this.getPreExpressApi()
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			uni.$on('addressItem', function(res) {
				that.$set(this, 'addressItem', res);
				this.preOrderNo = ''
				this.fastMailData = {}
				this.orderPrice = 0
			})
		},
		methods: {
			lookImg(url) {
				uni.previewImage({
					urls: url
				});
			},
			getPreExpressApi(orderNo) {
				loadPreExpressApi(orderNo).then(res => {
					this.fastMailData = res.data
					this.orderPrice = res.data.payFee
				})
			},
			onAddFastMail() {
				if (Object.keys(this.addressItem).length == 0) return this.$util.Tips({
					title: '请选择地址'
				});
				this.isTake = true
			},
			tabSelect(active, e) {
				this.active = active;
				this.navListIndex = e;
				this.scrollLeft = e * 60;
			},
			toPay() {
				console.log(this.fastMailData)
				console.log('提交订单')
			},
			pay(item) {
				uni.showLoading({
					title: '加载中...'
				});
				this.getToPayment(item.secondType, item)
			},
			onTipValue(value) {
				this.giveTips = value
				this.isTip = false;
				console.log(value)
			},
			onTakeChang(data) {
				this.isTake = false
				this.preOrderNo = data.orderNo
				this.getPreExpressApi(data.orderNo)
			},
			onCanCel(val) {
				this.isOrder = val
				this.isTake = val
				this.isTip = val
			},
			onRadioChang() {
				this.radioArr = !this.radioArr
				if (!this.fastMailData.postOrderList) return
				this.fastMailData.postOrderList.forEach(item => {
					item.orderInfoList.forEach(val => {
						val.radar = this.radioArr
					})
				})
			}
		}
	}
</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%;
		padding: 28rpx 30rpx;
		font-weight: 600;
		font-size: 27rpx;
		color: #141414;
		background-color: #fff;
		margin-bottom: 20rpx;
		border-radius: 20rpx;
	}

	.remark-name {
		font-weight: 600;
		font-size: 27rpx;
		color: #141414;
	}

	.fast-tip {
		background-color: #fff;
		margin-top: 20rpx;
		padding: 20rpx;
	}

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

	.fast-jia {
		width: 44rpx;
		height: 44rpx;
		line-height: 44rpx;
		text-align: center;
		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 20rpx 20rpx 84rpx;
			background-color: #F8F9FB;
			margin-bottom: 10rpx;
		}

		.radios {
			position: absolute;
			left: 38rpx;
		}

		.fast-remark {
			font-weight: 400;
			font-size: 21rpx;
			color: #999999;
		}

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

		.fast-yz {
			font-weight: 500;
			font-size: 21rpx;
			color: #141414;

			text {
				color: #FF0202;
				margin-left: 20rpx;
			}
		}

		.fast-xx {
			font-weight: 400;
			font-size: 21rpx;
			color: #646464;
			margin: 10rpx 0;
		}

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

			.fast-cash {
				font-weight: 600;
				font-size: 27rpx;
				color: #FF6702;
			}
		}
	}

	.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>
