<template>
	<view class="main pageBg">
		<view class="status_bar"></view>
		<view class="TopCon pad" >
			<!-- 地址、扫一扫 -->
			<view class="flex-b">
				<view class="adrsCon">
					<view class="adrsIcon">
						<image src="@/static/images/index/dingwei.png" mode=""></image>
					</view>
					<view class="adr">{{ vuex_cityInfo.city || '杭州' }} </view>
				</view>
				<!-- 搜索 -->
				<view class="searchCon"  @click.capture="$goPage('/pages/indexEntry/findShcool/searchShcool/searchShcool')">
					<searchRow placeholder="搜索驾校、教练…" :disable="true"></searchRow>
				</view>
				<view class="scan" @click="scanCodeFn">
					<image src="@/static/images/index/scan.png" mode="aspectFill"></image>
				</view>
			</view>	
		</view>
		
		<!-- 海报 -->
		<view class="banner">
			<uni-swiper-dot class="uni-swiper-dot-box" @clickItem=clickItem :info="swiperInfo" v-if="swiperInfo.length"
				:current="current" :mode="mode" :dots-styles="dotsStyles"
				field="content">
				<swiper class="swiper-box" @change="change" :current="swiperDotIndex" >
					<swiper-item v-for="(item, index) in swiperInfo" :key="index"  @click="$goPage('/pages/indexEntry/iIndustryInfo/detail/detail?id='+ item.id)">
						<view class="swiper-item" :class="'swiper-item' + index">
							<view class="imgBox">
								<image :src="item.picture" mode="widthFix"></image>
							</view>
						</view>
					</swiper-item>
				</swiper>
			</uni-swiper-dot>
		</view>
		
		<view class="pad">
			<!-- 精钢区 -->
			<view class="card traTop">
				<view class="ul">
					<view class="li" v-for="(item,index) in entrySection" :key="index" @tap="entrySectionClick(item)">
						<view class="icon">
							<image :src="item.icon" mode=""></image>
						</view>
						<view class="name">{{ item.text }}</view>
					</view>
				</view>
			</view>
			
			<!-- 优质驾校 -->
			<view class="schoolCon">
				<view class="h1" style="margin: 28rpx 0;">优质驾校</view>
				<view class="li" v-for="(item,index) in 3" :key="index">
					<schoolItem/>
				</view>
			</view>
			
			<!-- 行业资讯，政策法规 -->
			<view class="information">
				<view class="tabs">
					<view class="tab active">行业资讯</view>
					<view class="tab">政策法规</view>
				</view>
				<view class="ul">
					<view class="li" v-for="(item,index) in 3" :key="index">
						<informaItem/>
					</view>
				</view>
			</view>
		</view>
		
		<u-popup :show="showPrivacy" mode="center" :round="20" >
			<privacyPopup   @disagree="showPrivacy=false" @agree="showPrivacy=false"></privacyPopup>
		</u-popup>
	</view>
</template>

<script>
	import { imgUrl } from '@/config/site.config'
	import { getarticleList } from '@/config/api.js'
	import schoolItem from './comp/schoolItem'
	import informaItem from './comp/informaItem'
	export default {
		components: { schoolItem, informaItem },
		data() {
			return {
				showPrivacy: false,
				imgUrl: imgUrl+'banner.png',
				backgroundSize: '100% 100%',
				keywords: '',
				entrySection: [{
						text: '学车报名',
						icon: require('../../../static/images/index/ic_baoming.png'),
						url: '/pages/indexEntry/enroll/enroll',
						goPage: function (){
							console.log(666)
							// this.$goPage(item.url)
						}
					},
					{
						text: '找驾校',
						icon: require('../../../static/images/index/ic_jiaxiao.png'),
						url: '/pages/indexEntry/findShcool/findShcool',
						goPage: (item)=>{
							this.$goPage(item.url)
						}
					},
					{
						text: '找教练',
						icon: require('../../../static/images/index/ic_kaochang.png'),
						url: '/pages/indexEntry/examines/examines',
						goPage: ((item)=>{
							this.$goPage(item.url)
						})
					},
					{
						text: '理论学习',
						icon: require('../../../static/images/index/ic_jsg.png'),
						url: '/pages/carEntry/simulateAppointment/simulateAppointment',
						goPage: ((item)=>{
							this.$goPage(item.url)
						})
					},
					{
						text: '签到签退',
						icon: require('../../../static/images/index/ic_peilian.png'),
						goPage: ((item)=>{
							this.$u.toast('正在开发中，敬请期待...')
						})
					}
				],
				serviceSector: [{
						text: '学车指南',
						tps: '政府平台 一站服务',
						icon: require('../../../static/images/index/img_1@2x.png'),
						url: '/pages/indexEntry/parse/parse'
					},
					{
						text: '公益视频',
						tps: '立体呈现 学驾无忧',
						icon: require('../../../static/images/index/img_2@2x.png'),
						url: '/pages/indexEntry/publicVideo/publicVideo'
					},
					{
						text: '合格率排行',
						tps: '官方数据 阳光透明',
						icon: require('../../../static/images/index/img_3@2x.png'),
						url: '/pages/indexEntry/credit/credit?type=1'
					},
					{
						text: '行业政策',
						tps: '权威发布 精准解读',
						icon: require('../../../static/images/index/img_4@2x.png'),
						url: '/pages/indexEntry/industryPolicy/industryPolicy'
					},
					{
						text: '质量信誉排行',
						tps: '官方数据 阳光透明',
						icon: require('../../../static/images/index/img_5@2x.png'),
						url: '/pages/indexEntry/credit/credit'
					},
					{
						text: '咨询投诉',
						tps: '畅达沟通 听取民声',
						icon: require('../../../static/images/index/img_6@2x.png'),
						url: '/pages/indexEntry/consult/consult'
					},
					{
						text: '满分学习考试',
						tps: '网络教育 数据联网',
						icon: require('../../../static/images/index/img_7@2x.png'),
						url: ''
					},
					{
						text: '送考卷下乡',
						tps: '便民利民 就近考试',
						icon: require('../../../static/images/index/img_8@2x.png'),
						url: ''
					},
				],
				swiperDotIndex: 0,
				current: 1,
				mode: 'default',
				swiperInfo: [],
				dotsStyles: {
					backgroundColor: '#E8E9EC',
					border: '1px #E8E9EC solid',
					color: '#fff',
					selectedBackgroundColor: '#1989FA',
					selectedBorder: '1px #1989FA solid'
				},
				bgColor: 'transparent'
			}
		},
		async onLoad() {
			// this.getarticleListFn()
			// uni.getLocation({
			// 	type: 'wgs84',
			// 	success: function (res) {
			// 		console.log('当前位置的经度：' + res.longitude);
			// 		console.log('当前位置的纬度：' + res.latitude);
			// 	},
			// 	fail(err) {
			// 		console.log(err)
			// 	}
			// });
			if(!this.$store.state.user.vuex_cityInfo.lat) {
				await this.$store.dispatch('getCity')
			}
			// console.log(this.$store.state.user.vuex_cityInfo)
		},
		onPullDownRefresh() {
			this.getarticleListFn()
		},
		onShow() {
			this.$store.dispatch('getUserInfo')
			if(!this.swiperInfo.length) {
				this.getarticleListFn()
			}
		},
		computed: {
			
		},
		methods: {
			async entrySectionClick(item) {
				if(item.text=='我要报名') {
				  return this.$u.utils.clickSignUp()
				}
				if(item.text=='找驾驶馆') {
					const res = await this.$store.dispatch('checkLogin')
					if(!res) return
					if(!this.vuex_userInfo.schoolId) return this.$u.toast('您不是平台学员')
				}
				this.$goPage(item.url)
			},
			
			async getarticleListFn() {
				const {data: res} = await getarticleList(this.params)
				this.swiperInfo = res.list[0].articleManagementDO
			},
			async refereshFn() {
				const res = await this.$store.dispatch('refreshToken')
				console.log(res)
				uni.$u.http.setConfig((config) => {
					config.header.Authorization = 'Bearer ' + this.$store.state.user.vuex_loginInfo.accessToken
					console.log(111)
				    return config
				})
				console.log(222)
				// this.$store.dispatch('getUserInfo')
			},
			close() {
				
			},
			goPageSection(item) {
				uni.navigateTo({
					url:item.url
				})
			},
			// 扫码
			scanCodeFn() {
				let _this = this
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容6：' + res.result);
						let obj = JSON.parse(res.result)
						// 扫教练码去报名的
						if(obj.coachId) {
							obj.nickname = decodeURIComponent(obj.nickname)
							obj.schoolName = decodeURIComponent(obj.schoolName)
							let item = {
								schoolName:  obj.schoolName,
								schoolId:  obj.schoolId,
								name:  obj.nickname,
								id:  obj.coachId
							}
							console.log('***********')
							console.log(item)
							_this.$store.commit('upDateSchoolClass', {})
							_this.$store.commit('upDateSchoolCoach', item)
							_this.$goPage('/pages/indexEntry/enroll/enroll')
						}
						
						// _this.$store.commit('updateWebVeiwUrl', res.result)
						// uni.navigateTo({
						// 	url: '/pages/other/webView/webView'
						// })
					}
				});
			},
			clickItem(e) {
				this.swiperDotIndex = e
			},
			change(e) {
				this.current = e.detail.current
			},
			goPage() {
				uni.navigateTo({
					url: '/pages/userCenter/login/loginByPhone'
				})
			},
			initFn() {
				uni.requestSubscribeMessage({
					tmplIds: ['0yaIdyI9NlHvGYwb3IIaIQq6uBhulYGN-rGVnJk4hZ4'],
					success(res) {
						console.log('消息是否有权限呢')
						console.log(res)
					}
				})
			}
		}
	}
</script>


<style lang="scss" scoped>
	.main {
		width: 100%;

		.scan {
			width: 64rpx;
			height: 64rpx;
		}

		.TopCon {
			width: 100%;
			height: 120rpx;
			.flex-b {
				display: flex;
				height: 100%;
			}
			.adrsCon {
				display: flex;
				align-items: center;
				width: 180rpx;
				height: 100%;
				.adrsIcon {
					width: 26rpx;
					height: 38rpx;
					margin-top: 4rpx;
				}
				
				.adr {
					padding-left: 14rpx;
					font-size: 28rpx;
					color: #333;
				}
			}
			
			.searchCon {
				flex:1;
			}
			.scan {
				width: 100rpx;
				background-color: #ddd;
				height: 100%;
				display: flex;
				justify-content: flex-end;
				align-items: center;
				image {
					width: 90rpx;
					height: 90rpx;
				}
			}
		}



		.card {
			background: #FFFFFF;
			border-radius: 16rpx;
			margin-bottom: 20rpx;

			.ul {
				height: 236rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 20rpx;

				.li {
					flex: 1;
					display: flex;
					align-items: center;
					flex-direction: column;

					.icon {
						width: 92rpx;
						height: 92rpx;
					}

					.name {
						font-size: 26rpx;
						color: #333;
						padding-top: 20rpx;
						text-align: center;
					}
				}
			}
		}
	}
	
	.tabs {
		display: flex;
		padding: 20rpx 0 10rpx 0;
		.tab {
			font-size: 30rpx;
			color: #333;
			margin-right: 20rpx;
			&.active {
				border-bottom: 4px solid $themC
			}
		}
	}
</style>