<template>
	<view class="" v-if="show">
		<view class="moveCar">
			<view class="move_car__content">
				<view class="menu__top" @click="goUrl({url: '/pagesB/pages/move-car/loveCar',})">
					<view>
						<image src="@/static/move-car/move-car1.png" />
					</view>
					<view>
						爱车管理
					</view>
				</view>

				<view class="menu__list">
					<view class="list__items" v-for="(vo,inx) in items" :key="inx" @click="goUrl(vo)">
						<view>
							<image :src="vo.icon" />
						</view>
						<view>
							{{vo.title}}
						</view>
					</view>
				</view>
			</view>
            
            <view v-if="carouselFlag" style="width: 700rpx;margin: 0 auto;position: relative;">
                <u-swiper radius="12rpx" :height="120" :list="list5" circular @change="e => current = e.current"
                    :autoplay="true" keyName="imageUrl" @click="goOtherLink">
                </u-swiper>
                
                <view style="position: absolute;right: 10rpx; top:10rpx;z-index: 99999;">
                    <u--image src="/static/my/close.png" width="12px" height="12px" @click="closeCarouselFlag"></u--image>
                </view>
            </view>
		</view>
	</view>
</template>

<script>
    import util from '@/pages/login/util.js'
	export default {
		data() {
			return {
				show: false,
				items: [{
						icon: require("@/static/move-car/move-car6.png"),
						url: "/pagesB/pages/move-car/oneMoveCar",
						title: "扫一扫联系车主"
					},
					{
						icon: require("@/static/move-car/move-car3.png"),
						url: "/pagesB/pages/move-car/myCall",
						title: "我的呼叫记录"
					}, {
						icon: require("@/static/move-car/move-car2.png"),
						url: "/pagesB/pages/move-car/myMoveCar",
						title: "我的挪车牌"
					}, {
						icon: require("@/static/move-car/move-car4.png"),
						url: "/pagesB/pages/move-car/myRecord",
						title: "我的挪车记录"
					},
				],
				scanClick: true, //扫一扫节流
                list5: [],
                current: 0,
                carouselFlag:false,
			}
		},
		methods: {
            closeCarouselFlag() {
                this.carouselFlag = false
            },
            getRotationList() {
            	let opts = {
            		url: '/app/index/adv/1',
            		method: 'get'
            	};
            	this.http.httpTokenRequest(opts, {}).then(res => {
            		if (res.data.code == 200 && res.data.data && res.data.data.length > 0) {
            			let data = []
            			data = res.data.data
            			let imgList = []
            			data.forEach(e => {
            				imgList.push(e)
            			})
            			this.list5 = imgList
                        this.carouselFlag = true
            		}
            	})
            },
            // 轮播跳转其他页面
            goOtherLink(index) {
            	let item = this.list5[index]
            	this.$goToLocation(item)
            },
			goUrl(vo) {
                uni.removeStorageSync('routerLogin')
                uni.setStorageSync('routerLogin',vo.url)
				let token = uni.getStorageSync('userToken');
				if (!token) {
					// uni.navigateTo({
					//     url: '/pages/binding/index?url=/pages/main&index=1'
					// })
					uni.navigateTo({
						url: '/pages/login/index/index'
					})
					return;
				}
				const that = this
				if (vo.title != "扫一扫联系车主") {
					uni.navigateTo({
						url: vo.url
					})
				} else {
					//跳转绑定页面
					// uni.navigateTo({
					//     url: vo.url
					// })
					//扫码
					if (this.scanClick) {
						this.scanClick = false;
						setTimeout(() => {
							uni.scanCode({
						 	success: (res) => {
									this.scanClick = true
                                    if(res.errMsg === 'scanCode:ok') {
                                        let scanType = res.scanType
                                        let path = ''
                                        //扫的小程序码
                                        if(scanType === 'WX_CODE') {
                                            path = res.path
                                        }
                                        //扫的二维码
                                        if(scanType === 'QR_CODE') {
                                            path = res.result
                                        }
                                        if (path) {
                                        	let paths = path.split('?')[1]
                                        	let scene = paths.split("=")[1]
                                        	this.$http.request({
                                        		url:'/app/user/c/m/c',
                                        		method:'post',
                                        		data:{
                                        			code: scene
                                        		},
                                        	}).then(res => {
                                        		console.log(res, "扫码通知车主")
                                        		if (res.bindFlag) {
                                        			that.gotoMoveCar(scene)
                                        		} else {
                                        			that.gotoBindMoveCar(scene)
                                        		}
                                        	})
                                        } else {
                                            uni.showToast({
                                                title: "扫码失败!",
                                                icon: 'error',
                                            })
                                        }
                                    } else {
                                        uni.showToast({
                                        	title: "扫码失败!",
                                        	icon: 'error',
                                        })
                                    }
                                    
									 
								},
								fail: () => {
									this.scanClick = true
								}
							});
						}, 300)
					}
				}
			},
			//跳转到挪车页面
			gotoMoveCar(s) {
				let that = this;
				uni.navigateTo({
					url: '/pagesB/pages/move-car/oneMoveCar?scene=' + s
				});
			},
			//跳转到绑定页面
			gotoBindMoveCar(s) {
				let that = this;
				uni.navigateTo({
					url: '/pagesB/pages/move-car/scan?moveCode=' + s
				});
			},
		},
		onReady: function() {
			uni.setNavigationBarTitle({
				title: '我要挪车'
			});
		},
		mounted() {
			setTimeout(() => {
				this.show = true
			}, 100);
            
            this.getRotationList()
		},
	};
</script>

<style lang="scss">
	.moveCar {
		height:100vh;
		background-color: #fff;
		.move_car__content {
			padding: 40rpx;

			.menu__top {
				height: 220rpx;
				// background: #FFFFFF;
				// border: 1rpx solid #EFE7E7;
				box-shadow: 0rpx 0rpx 28rpx 1rpx rgba(232, 232, 232, 0.16);
				border-radius: 20rpx;
				margin-bottom: 30rpx;
				display: flex;
				flex-wrap: wrap;
				align-items: center;
				justify-content: center;
				box-sizing: border-box;
				padding: 45rpx 0;
				background: url('@/static/move-car/move-car-bg.png') no-repeat  center;
				background-size:100% 100%;
				>view {
					width: 100%;
					text-align: center;
				}

				>view:nth-of-type(1) {
					image {
						width: 58rpx;
						height: 50rpx;
					}
				}

				>view:nth-of-type(2) {
					font-size: 40rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
					line-height: 42rpx;
				}
			}

			.menu__list {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;

				.list__items {
					width: 325rpx;
					height: 220rpx;
					// background: #FFFFFF;
					// border: 1rpx solid #EFE7E7;
					box-shadow: 0rpx 0rpx 28rpx 1rpx rgba(232, 232, 232, 0.16);
					border-radius: 20rpx;
					display: flex;
					flex-wrap: wrap;
					align-items: center;
					justify-content: center;
					box-sizing: border-box;
					padding: 45rpx 0;
					margin-bottom: 30rpx;
					background: url('@/static/move-car/move-car-bg2.png') no-repeat  center;
					background-size:100% 100%;

					>view {
						width: 100%;
						text-align: center;
					}

					>view:nth-of-type(1) {
						image {
							width: 58rpx;
							height: 58rpx;
						}
					}

					>view:nth-of-type(2) {
						font-size: 40rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #333333;
						line-height: 42rpx;
					}
				}

				.list__items:nth-of-type(2) {
					background: url('@/static/move-car/move-car-bg3.png') no-repeat  center;
					background-size:100% 100%;
					>view:nth-of-type(1) {
						image {
							width: 55rpx;
							height: 58rpx;
						}
					}
				}

				.list__items:nth-of-type(3) {
					background: url('@/static/move-car/move-car-bg4.png') no-repeat  center;
					background-size:100% 100%;
					>view:nth-of-type(1) {
						image {
							width: 58rpx;
							height: 58rpx;
						}
					}

				}

				.list__items:nth-of-type(4) {
					background: url('@/static/move-car/move-car-bg5.png') no-repeat  center;
					background-size:100% 100%;
					>view:nth-of-type(1) {
						image {
							width: 54rpx;
							height: 58rpx;
						}
					}

				}
			}
		}
	}
</style>
