<template>
	<view>
		<u-navbar title="入驻" placeholder='true' :autoBack="true">
		</u-navbar>
		<view>
			<u-swiper :list="fileList" autoplay radius='0' :circular="true"
				@change="e => current = e.current" @click="click">
				<view slot="indicator" class="indicator">
					<view class="indicator__dot" v-for="(item, index) in fileList" :key="index"
						:class="[index === current && 'indicator__dot--active']">
					</view>
				</view>
			</u-swiper>
		</view>
		<view>
			<luyj-grid-link :list="list" @gridExc="clickGrid" @switchChange='switchChange'></luyj-grid-link>
		</view>
		<u-modal :show="editshow" @confirm="$u.debounce(confirm,500)" title="选择自动跳转内容" @cancel="editshow=false" closeOnClickOverlay showCancelButton>
			<view class="slot-content">
				<u-radio-group v-model="radiovalue1" placement="column" @change="groupChange">
					<u-radio :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist1" :key="index"
						:label="item.value" :name="item.value">
					</u-radio>
				</u-radio-group>
			</view>
		</u-modal>
		<u-tabbar :value="tabbarCheck" @change="tabbarChange" activeColor="#5F7DE9">
			<u-tabbar-item name="team" text="加入">
				<image class="u-page__item__slot-icon" slot="active-icon"
					src="@/static/image/nav-icon/antOutline-team Copy.png"></image>
				<image class="u-page__item__slot-icon" slot="inactive-icon"
					src="@/static/image/nav-icon/antOutline-team.png"></image>
			</u-tabbar-item>
			<u-tabbar-item name="notification" text="通知">
				<image class="u-page__item__slot-icon" slot="active-icon"
					src="@/static/image/nav-icon/md-notifications_none Copy.png"></image>
				<image class="u-page__item__slot-icon" slot="inactive-icon"
					src="@/static/image/nav-icon/md-notifications_none.png"></image>
			</u-tabbar-item>
			<u-tabbar-item name="user" text="我的">
				<image class="u-page__item__slot-icon" slot="active-icon"
					src="@/static/image/nav-icon/antOutline-user1 Copy.png"></image>
				<image class="u-page__item__slot-icon" slot="inactive-icon"
					src="@/static/image/nav-icon/antOutline-user1.png"></image>
			</u-tabbar-item>
		</u-tabbar>
	</view>
</template>

<script>
	var that
	import {
		pathToBase64,
		base64ToPath
	} from 'image-tools'
	import luyjGridLink from '@/uni_modules/lxm-fold-link/luyj-grid-link/components/luyj-grid-link/luyj-grid-link.vue'
	export default {
		components: {
			"luyjGridLink": luyjGridLink
		},
		data() {
			return {
				fileList: [],
				editshow: false,
				tabbarCheck: 'team',
				showAuthorizePhone: false,
				showAuthorizeUser: false,
				radiolist1: [],
				radiovalue1: '',
				userInfo: {
					head: '',
					nickname: '',
					phone: '',
				},
				customStyleUnOk: {
					marginTop: '20rpx',
					color: '#5F7DE9',
					border: '2px solid #5F7DE9',
					"border-radius": "10px",
					fontSize: "32rpx"
				},
				customStyleOk: {
					marginTop: '20rpx',
					color: '#fff',
					border: '2px solid #5F7DE9',
					"border-radius": "10px",
					fontSize: "32rpx",
					background: "#5F7DE9"
				},
				list: [{
						title: '全部分类',
						// cur: 'basic',
						bgColor: '', // 背景颜色
						color: 'blue',
						title_show: true,
						showAll: false,
						colNumber: 4, // 显示的列数
						iconsList: [{
								cuIcon: '1_canyin-35',
								color: 'blue',
								name: '餐饮',
								status: true,
								url: '/pageA/enter/cateringindustry'
							},
							{
								cuIcon: 'zufang',
								color: 'blue',
								name: '民宿',
								status: true,
								url: '/pageA/enter/homestay'
							},
							{
								cuIcon: 'jiudian-38',
								color: 'blue',
								name: '酒店',
								status: true,
								url: '/pageA/enter/hotel'
							}
						]
					},
					{
						title: '我的入驻',
						// cur: 'basic',
						bgColor: '', // 背景颜色
						color: 'blue',
						title_show: true,
						foodEntry: 0,
						homeEntry: 0,
						hotelEntry: 0,
						switch: true,
						showAll: false,
						switch_status: true,
						colNumber: 4, // 显示的列数
						iconsList: [{
								cuIcon: '1_canyin-35',
								color: 'blue',
								name: '餐饮',
								status: true,
								url: '/pageA/enter/myCateringdustry/index'
							},
							{
								cuIcon: 'zufang',
								color: 'blue',
								name: '民宿',
								status: true,
								url: '/pageA/enter/myHomestay/index'
							},
							{
								cuIcon: 'jiudian-38',
								color: 'blue',
								name: '酒店',
								status: true,
								url: '/pageA/enter/hotel'
							}
						]
					},
				],
			}
		},
		onLoad() {
			that = this
			this.userInfo = uni.getStorageSync("userInfo")
			if (uni.getStorageSync("userInfo").phone && uni.getStorageSync("userInfo").automaticSkip) {
				if (uni.getStorageSync("userInfo").autoModule == 'foodEntry') {
					uni.navigateTo({
						url: '/pageA/enter/myCateringdustry/index'
					})
				} else if (uni.getStorageSync("userInfo").autoModule == 'homeEntry') {
					uni.navigateTo({
						url: '/pageA/enter/myHomestay/index'
					})
				} else if (uni.getStorageSync("userInfo").autoModule == 'hotelEntry') {
					uni.navigateTo({
						url: '/pageA/enter/hotel'
					})
				}
			}
			this.getList()
		},
		onShow: function() {
			let _isLoad = uni.getStorageSync("scanAddCardToIndex")
			if (uni.getStorageSync("userInfo").phone) {
				if (uni.getStorageSync("userInfo").foodEntry == 0 && uni.getStorageSync("userInfo").homeEntry == 0 &&
					uni.getStorageSync("userInfo").hotelEntry == 0) {
					this.list[1].switch_status = false
				} else {
					this.list[1].switch_status = uni.getStorageSync("userInfo").automaticSkip ? true : false
				}
				if (uni.getStorageSync("userInfo").foodEntry > 0) {
					this.list[1].iconsList[0].status = true
				} else {
					this.list[1].iconsList[0].status = false
				}
				if (uni.getStorageSync("userInfo").homeEntry > 0) {
					this.list[1].iconsList[1].status = true
					this.list[0].iconsList[1].status = false
				} else {
					this.list[1].iconsList[1].status = false
					this.list[0].iconsList[1].status = true
				}
				if (uni.getStorageSync("userInfo").hotelEntry > 0) {
					this.list[1].iconsList[2].status = true
					this.list[0].iconsList[2].status = false
				} else {
					this.list[1].iconsList[2].status = false
					this.list[0].iconsList[2].status = true
				}
			} else {}

		},
		methods: {
			tabbarChange(e) {
				console.log(e)
				if (e == 'notification') {
					uni.navigateTo({
						url: '/pageA/notice/index'
					})
				} else if (e == 'user') {
					uni.navigateTo({
						url: '/pageA/my/my'
					})
				}
				// name => tabbarCheck = name
			},
			async confirm() {
				var data1 = await this.updateUser()
				if (data1.errno == 200) {
					uni.setStorageSync("userInfo", this.userInfo)
					this.editshow = false
				}
			},

			groupChange(e) {
				console.log(e)
				if (e == '餐饮') {
					this.userInfo.autoModule = 'foodEntry'
				} else if (e == '民宿') {
					this.userInfo.autoModule = 'homeEntry'
				} else if (e == '酒店') {
					this.userInfo.autoModule = 'hotelEntry'
				}

			},

			async switchChange(e) {debugger
				var status = e ? 1 : 0
				console.log(e, 111111)
				// this.userInfo.automaticSkip = status
				// var data = await this.updateUser()
				// console.log(data)
				// if (data.errno == 200) {
				// 	uni.setStorageSync("userInfo", this.userInfo)
				// 	uni.showToast({
				// 		icon: "none",
				// 		title: '已开启自动跳转',
				// 		duration: 3000
				// 	});
				// 	if (uni.getStorageSync("userInfo").foodEntry != 0 && uni.getStorageSync("userInfo").homeEntry ==
				// 		0 && uni.getStorageSync("userInfo").hotelEntry == 0) {
				// 		this.userInfo.autoModule = 'foodEntry'
				// 		var data1 = await this.updateUser()
				// 		if (data1.errno == 200) {
				// 			uni.setStorageSync("userInfo", this.userInfo)
				// 			return
				// 		}
				// 	}
				// 	if (uni.getStorageSync("userInfo").foodEntry == 0 && uni.getStorageSync("userInfo").homeEntry !=
				// 		0 && uni.getStorageSync("userInfo").hotelEntry == 0) {
				// 		this.userInfo.autoModule = 'homeEntry'
				// 		var data1 = await this.updateUser()
				// 		if (data1.errno == 200) {
				// 			uni.setStorageSync("userInfo", this.userInfo)
				// 			return
				// 		}
				// 	}
				// 	if (uni.getStorageSync("userInfo").foodEntry == 0 && uni.getStorageSync("userInfo").homeEntry ==
				// 		0 && uni.getStorageSync("userInfo").hotelEntry != 0) {
				// 		this.userInfo.autoModule = 'hotelEntry'
				// 		var data1 = await this.updateUser()
				// 		if (data1.errno == 200) {
				// 			uni.setStorageSync("userInfo", this.userInfo)
				// 			return
				// 		}
				// 	}
				// 	this.radiolist1 = []
				// 	if (uni.getStorageSync("userInfo").foodEntry != 0) {
				// 		this.radiolist1.push({
				// 			value: '餐饮'
				// 		})
				// 	}
				// 	if (uni.getStorageSync("userInfo").homeEntry != 0) {
				// 		this.radiolist1.push({
				// 			value: '民宿'
				// 		})
				// 	}
				// 	if (uni.getStorageSync("userInfo").hotelEntry != 0) {
				// 		this.radiolist1.push({
				// 			value: '酒店'
				// 		})
				// 	}
					if (e) {
						if (uni.getStorageSync("userInfo").foodEntry != 0 && uni.getStorageSync("userInfo").homeEntry ==
							0 && uni.getStorageSync("userInfo").hotelEntry == 0) {
							this.userInfo.autoModule = 'foodEntry'
							var data1 = await this.updateUser()
							if (data1.errno == 200) {
								uni.setStorageSync("userInfo", this.userInfo)
								return
							}
						}
						if (uni.getStorageSync("userInfo").foodEntry == 0 && uni.getStorageSync("userInfo").homeEntry !=
							0 && uni.getStorageSync("userInfo").hotelEntry == 0) {
							this.userInfo.autoModule = 'homeEntry'
							var data1 = await this.updateUser()
							if (data1.errno == 200) {
								uni.setStorageSync("userInfo", this.userInfo)
								return
							}
						}
						if (uni.getStorageSync("userInfo").foodEntry == 0 && uni.getStorageSync("userInfo").homeEntry ==
							0 && uni.getStorageSync("userInfo").hotelEntry != 0) {
							this.userInfo.autoModule = 'hotelEntry'
							var data1 = await this.updateUser()
							if (data1.errno == 200) {
								uni.setStorageSync("userInfo", this.userInfo)
								return
							}
						}
						this.radiolist1 = []
						if (uni.getStorageSync("userInfo").foodEntry != 0) {
							this.radiolist1.push({
								value: '餐饮'
							})
						}
						if (uni.getStorageSync("userInfo").homeEntry != 0) {
							this.radiolist1.push({
								value: '民宿'
							})
						}
						if (uni.getStorageSync("userInfo").hotelEntry != 0) {
							this.radiolist1.push({
								value: '酒店'
							})
						}
						this.editshow = true
					}else{
						this.userInfo.automaticSkip = status
						var data = await this.updateUser()
						console.log(data)
						if (data.errno == 200) {
							uni.setStorageSync("userInfo", this.userInfo)
							uni.showToast({
								icon: "none",
								title: '已开关闭动跳转',
								duration: 3000
							});
						} 
						else {
							uni.showToast({
								icon: "none",
								title: '自动跳转关闭失败',
								duration: 3000
							});
							this.userInfo.automaticSkip = status == 0 ? false : true
						}
						
						
						
						
						
						
						
						
						
						
					}
			
			},
			getList() {
				this.$request.baseRequest('admin.tourism.carouselManagement', 'list', {
					page: 1,
					limit: 9999,
					classify: '商家版首页'
				}, failres => {
					uni.showToast({
						icon: "none",
						title: failres.errmsg,
						duration: 3000
					});
				}).then(res => {
					this.fileList = res.data.items
				})
			},
			toDetail(url) {
				uni.navigateTo({
					url: url
				})
			},
			updateUser() {
				return new Promise((resolve, reject) => {
					that.$request.baseRequest('admin.unimall.commonUserInfo', 'update', {
						commonUserInfo: JSON.stringify(this.userInfo)
					}, failres => {
						reject(failres)
					}).then(res => {
						resolve(res)
					})
				})
			},
			async getPhoneNumber(e) {
				that.userInfo = await this.$request.wxlogin()
				that.userInfo.phone = await this.$request.getPhone(e, that.userInfo)
				this.showAuthorizePhone = false
				this.showAuthorizeUser = true

			},
			async authUser(type) {
				//同步信息，没有头像和昵称自动生成
				this.userInfo = await this.$request.syncInfo(this.userInfo)
				if (this.userInfo.openId) {
					uni.setStorageSync("userInfo", that.userInfo)
					that.showAuthorizeUser = false
					// that.mescroll.resetUpScroll()
				}
			},
			//获取昵称输入内容
			userNameInput(e) {
				this.userInfo.nickname = e.detail.value
			},
			async onChooseAvatar(e) {
				this.$set(this.userInfo, "head", await this.toBase64(e.detail.avatarUrl))
			},
			toBase64(url) {
				return new Promise(resolve => {
					pathToBase64(url).then(path => {
						resolve(path);
					}).catch(error => {
						console.log(error)
					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.slot-content {
		width: 100%;
	}



	/deep/.u-checkbox-group {

		position: absolute;
		right: 20px;
		z-index: 99;
		top: 30px;
	}

	/deep/.u-checkbox__icon-wrap.u-checkbox__icon-wrap--square {
		border-color: #D7DEEB !important;
	}



	/deep/.mescroll-body {
		min-height: 558px !important;
		height: 558px !important;
		background-color: green;
		overflow: scroll !important;
	}

	.auth-btncard {
		display: flex !important;
		justify-content: space-between !important;

		.btn-unok {
			width: 40%;
		}

		.btn-ok {
			width: 40%;
		}
	}

	.auth-card {
		text-align: center;

		.avatar-img {
			width: 200rpx;
		}

		.title {
			font-size: 20rpx;
		}

		.content {
			font-size: 32rpx;
			font-weight: bold;
			color: #1A1A1A;
			margin-bottom: 30rpx;
		}
	}

	.avatar-wrapper {
		color: #333 !important;
		border: none !important;
		border-radius: 0 !important;
		background-color: transparent !important;
		padding: 0;
	}

	.avatar-wrapper::after {
		border: none !important;
	}

	.avatar {
		width: 100rpx;
		height: 100rpx;
		overflow: hidden;
		border-radius: 100%;
	}

	/deep/.u-popup__content {
		border-radius: 20rpx !important;
	}

	/deep/.u-tabbar-item image {
		width: 40rpx;
		height: 40rpx;
	}
</style>