<template>
	<view class="" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd">
		<u-navbar title="个人中心" :safeAreaInsetTop="true" leftIconSize="45" :titleStyle="{'font-size':'28rpx'}"
			@leftClick="backBtn()">

		</u-navbar>
		<view class="successbox flex1">
			<view class="flex1">
				<view class="imgbox">
					<image src="../../static/success.png" mode="aspectFill"></image>
				</view>
				<text style="padding-top: 20rpx;">订单提交成功</text>
			</view>

			<view class="chabtn">
				<text class="backhome" @click="gobackinHome">回到首页</text>
				<text class="backhome pd" @click="goDetails">查看订单</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				startX: 0, //滑动开始x轴位置
						startY: 0, //滑动开始y轴位置
						moveX: 0, //滑动的x轴距离
						moveY: 0, //滑动的y轴距离
						like_state: 0, //-1：左滑，0：没滑动，1：右滑
			}
		},
		onLoad(o) {
			if (o.id) {
				this.id = o.id
			}

		},
		onBackPress(options) {
			if (options.from == 'navigateBack') {
				return false
			}
			uni.switchTab({
				url: "/pages/index/index"
			})
			return true;
			
		},
		methods: {
			backBtn() {
				uni.redirectTo({
					url: "/pages/travel"
				})
			},
			gobackinHome() {
				uni.switchTab({
					url: "/pages/index/index"
				})
			},
			goDetails() {
				uni.redirectTo({
					url: "/pages/order/orderDetails?id=" + this.id
				})
			},
			touchStart(event) {
					this.startX = event.touches[0].pageX;
					this.startY = event.touches[0].pageY;
					console.log('开始触摸：', this.startX, this.startY);
				},
				touchMove(event) {
					var currentX = event.touches[0].pageX;
					var currentY = event.touches[0].pageY;
					var moveX = currentX - this.startX;
					var moveY = currentY - this.startY;
					var text = '';
					var state = 0; //-1：左滑，0：没滑动，1：右滑
					// //左右方向滑动
					if (Math.abs(moveX) > Math.abs(moveY)) {
						if (moveX < -10) {
							text = '左滑';
							state = 1;
						} else if (moveX > 10) {
							text = '右滑';
							state = -1;
						}
					} else { //上下方向滑动
						if (moveY < 0) {
							text = '上滑';
						} else if (moveY > 0) text = '下滑';
					}
					this.like_state = state;
					this.moveX = moveX;
					this.moveY = moveY;
					console.log('开始滑动：', this.moveX, this.moveY, this.like_state);
				},
				touchEnd(event) {
					console.log(`移动距离:${Math.abs(this.moveX)}`)
					if (Math.abs(this.moveX) > 60 && this.like_state != -100) {
						var state = this.like_state
						this.like_state = -100//设置这个数是为了避免滑动之后点击不走touchMove而产生的不正常滑动
						uni.switchTab({
							url: "/pages/index/index"
						})//这里放需要进行的业务逻辑
					}
				},
		
		}
	}
</script>

<style lang="less">
	page {
		font-family: PingFang-SC-Heavy, PingFang-SC;
		background: #ffffff;
	}

	.flex1 {
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: center;
	}

	.successbox {
		padding:40rpx 0;
		background-color: #FCFCFC;
		// margin: 20rpx;
		// border-radius: 10rpx;
		margin-top: 240rpx;

		.imgbox {
			width: 120rpx;
			height: 120rpx;

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

	.chabtn {
		padding-top: 120rpx;
		display: flex;

		.backhome {
			display: block;
			font-size: 30rpx;
			color: rgba(30, 159, 106, 1);
			padding: 10rpx 30rpx;
			border: 1rpx solid rgba(30, 159, 106, 1);
			border-radius: 30rpx;
		}

		.pd {

			margin-left: 100rpx;
		}
	}
</style>
