<template>
	<view :class="[AppTheme]" class="all_box" v-if="thflag==2">
		<u-navbar :titleStyle="{color:'#ffffff'}" :bgColor="primary" :autoBack="false" :fixed="true" :placeholder="true"
			:height="45">
			<view class="u-nav-slot" slot="left" @click="scancode">
				<u-icon name="scan" color="#ffffff" size="24"></u-icon>
			</view>
			<!-- #ifdef APP-PLUS || H5 -->
			<view class="u-nav-slot" slot="center" style="width: 580rpx;">
				<u-search actionText="" :showAction="false" placeholder="输入商品名称" bg-color="#fff" @search="doSearch"
					v-model="search"></u-search>
				</u-icon>
			</view>
			<!-- #endif -->
			<!-- #ifdef MP-WEIXIN -->
			<view class="u-nav-slot" slot="center" style="width: 580rpx;">
				<view class="u-nav-slot" slot="center" style="width: 460rpx;">
					<u-search actionText="" :showAction="false" placeholder="输入商品名称" bg-color="#fff" @search="doSearch"
						v-model="search"></u-search>
					</u-icon>
				</view>
			</view>
			<!-- #endif -->
			<!-- #ifdef APP-PLUS || H5 -->
			<view class="u-nav-slot" slot="right" @click="tocar">
				<u-icon name="shopping-cart" color="#ffffff" size="24"></u-icon>
			</view>
			<!-- #endif -->
		</u-navbar>
		<!-- 头部轮播 -->
		<view class="lunbo" :style="{background: primary}">
			<view class="carousel-section" v-if="lunbo&&lunbo.length>0">
				<u-swiper imgMode="aspectFill" :list="lunbo" keyName="ad_pic" showTitle :autoplay="false" circular
					@change="swiperChange">
				</u-swiper>
			</view>
		</view>

		<view class=" farm-block1">
			<u-notice-bar :text="announcetext" @click="goMessage" :color="primary" direction="column" mode="closable"
				speed="200"></u-notice-bar>
		</view>
		<view class="cate-section1" v-if="modular.length > 0">
			<view class="cate-section ">
				<view class="cate-item" v-for="(item, index) in modular" :key="index" @click="navTo(item.url)">
					<u--image :src="item.img" radius="10rpx" width="88rpx" height="88rpx" :lazyLoad="true" :fade="true"
						duration="450">
						<template v-slot:loading>
							<u-loading-icon color="#f7f7f7"></u-loading-icon>
						</template>
					</u--image>
					<text>{{ item.modularname }}</text>
				</view>
			</view>
		</view>
		<view class="coupon" v-if="couponlist&&couponlist.length > 0">
			<view class="coupon_title">
				<view class="cupin_left">
					<view class="cupin_left_p1">专享优惠卷</view>
				</view>
				<view class="cupin_right" @click="gogetactivity">查看全部></view>
			</view>
			<navigator url="/pagesB/pages/getcoupon/getcoupon" open-type="navigate" class="coupon_item"
				v-for="(item, index) in couponlist.slice(0,2)" :key="index">
				<view class="coupon_item_p1">
					<view class="coupon_item_p2_ti1_p1">￥</view>
					<view class="coupon_item_p2_ti1">{{ item.money }}</view>
					<view class="coupon_item_p2_ti2">
						<view class="describe">满{{ item.usemoney }}元可用</view>
						<view class="describe2">{{ item.type }}</view>
						<view class="describe3">使用时间:{{ item.stime }}-{{ item.etime }}</view>
					</view>
				</view>
				<view class="coupon_item_p2">
					<view>
						立即领取
					</view>
				</view>
			</navigator>
		</view>
		<Ugoods2 ref="goodlist" :datas="datas"></Ugoods2>
		<view class="leaveblank_bottom"></view>
	</view>
</template>
<script>
	import Ugoods2 from '@/components/ui-component/U_goods2/m/index.vue';
	import homeApi from '@/api/home/index.js'
	export default {
		name: "themes2",
		props: ['primary2', 'thflag'],
		components: {
			Ugoods2
		},
		data() {
			return {
				datas: {
					"title": "商品列表B",
					"text_size": 15,
					"show_title": false,
					"goods": [],
					"margin_top": 0,
					"margin_bottom": 10,
					"bg_color": "#f7f7f8",
					"text_color": "#333333",
					"good_text_size": 15,
					"good_text_color": "#333333",
					"shop_price_color": "#FC0404",
					"market_price_color": "#999999",
					"buynow_bg_color": this.$theme.primary,
					"show_num": 0
				},
				primary: this.primary2,
				config: {
					site_info: {
						index_logo: ''
					},
					home: [],
				},
				title: '',
				list: [],
				bodymodular1: '',
				dlsetting: [],
				search: '',
				settingFile: [],
				titleNViewBackground: '',
				swiperCurrent: 0,
				swiperLength: 0,
				carouselList: [],
				newsList: [],
				goodsList: [],
				sellList: [],
				sysname: '',
				ischar: false,
				city: '获取中...',
				key: '',
				loadingImg: '',
				errorImg: '',
				weather: {
					tem: '-4',
					tem1: 2,
					tem2: -5,
					win_speed: 3,
					air_pm25: 8,
					humidity: 0
				},
				lunbo: [],
				announce: [],
				announcetext: [],
				isShow: true,
				ifhavehead: false,
				isnone: 'block',
				isshow: false,
				navHeight: 125,
				heig: 20,
				placeMargin: -155,
				addressName: '',
				district: '',
				marTop: 90,
				marTops: 70,
				searchTop: 110, //123
				placeHeig: 439,
				placeHeig2: 370,
				isSearch: false,
				temlist: '',
				modular: [],
				couponlist: [],
				carnum: 0
			}
		},
		onPageScroll: function(e) {
			if (!this.ifhavehead) {
				if (e.scrollTop > 45) {
					this.ifhavehead = true
				}
			} else {
				if (e.scrollTop < 45) {
					this.ifhavehead = false
				}
			}
		},
		methods: {
			//打开扫一扫
			scancode() {
				uni.scanCode({
					scanType: ['qrCode'],
					success: function(res) {
						uni.navigateTo({
							url: '/pagesB/pages/activorderdails/writeoffdetails/writeoffdetails?code=' +
								res.result
						})
					}
				})
			},
			//打开购物车
			tocar() {
				uni.navigateTo({
					url: '/pagesE/pages/cart/cart'
				})
			},
			toBottom(type) {
				let that = this
				that.$refs.goodlist.toBottom(type)
			},
			init() {
				let that = this
				if (that.$config) {
					if (that.primary == '' || that.primary != that.$theme.primary) {
						that.primary = that.$theme.primary;
					}
					that.sysname = that.$config.shop.name;
					that.addressName = that.$config.shop.name;
					// #ifdef H5
					uni.setNavigationBarTitle({
						title: that.$config.shop.name
					})
					// #endif
					that.goodsList = that.$config.cache1
					that.newsList = that.$config.cache3
					that.sellList = that.$config.cache5
					that.temlist = that.$config.temlist
					that.modular = that.$config.modular
					if (that.$config.app && that.$config.app.gaodekey) {
						that.key = that.$config.app.gaodekey
						uni.setStorageSync('mapkey', that.key)
					}
					that.ischar = that.$config.app.ischar
					that.couponlist = that.$config.card
					that.district = that.$config.shop.name;

					// 缓存订阅消息id
					uni.setStorageSync('temlist', that.temlist)
					if (that.$config.app.position == 1) {
						that.getAuthorizeInfo()
					} else {
						that.addressName = that.$config.shop.name;
					}

					this.homeInit();
				}
			},
			goMessage(index) {
				uni.navigateTo({
					url: '/pagesC/pages/index/message/message?id=' + this.announce[index].id
				})
			},
			getCity() {

			},
			getCityInfo() {

			},
			doSearch() {
				uni.navigateTo({
					url: `/pagesA/pages/search/search?value=${this.search}`
				})
			},
			async homeInit() {
				let that = this;
				let res = await homeApi.index()
				if (res.data.lunbo) {
					var list = res.data.lunbo.filter(item => item.pid == 14)
					if (list.length) {
						that.lunbo = list
					}
				}
				that.announce = res.data.announce;
				if (res.data.announce) {
					res.data.announce.forEach(item => {
						that.announcetext.push(item.title);
					});
				}
			},

			// 位置授权
			getAuthorizeInfo() {
				const that = this
				// #ifndef MP-WEIXIN
				that.getLocationInfo()
				// #endif
				// #ifdef MP-WEIXIN
				uni.authorize({
					scope: 'scope.userLocation',
					success() {
						// 允许授权
						that.getLocationInfo()
					},
					fail(err) {
						console.log(err)
						// 拒绝授权
						that.openConfirm()
					}
				})
				// #endif
			},
			// 获取地理位置
			getLocationInfo() {
				let that = this
				this.getCity()
			},
			// 再次获取授权
			// 当用户第一次拒绝后再次请求授权
			openConfirm() {
				let that = this
				uni.showModal({
					title: '请求授权当前位置',
					content: '需要获取您的地理位置，请确认授权',
					success: res => {
						if (res.confirm) {
							uni.openSetting({
								success: function(data) {
									if (data.authSetting['scope.userLocation'] ===
										true) {
										that.getCity()
										uni.showToast({
											title: '授权成功',
											icon: 'success',
											duration: 1000,
											success() {}
										})
									} else {
										uni.showToast({
											title: '授权失败',
											icon: 'success',
											duration: 1000
										})
									}
								}
							})
						} else if (res.cancel) {
							uni.showToast({
								title: '你拒绝了授权，无法获得周边信息',
								icon: 'none',
								duration: 1000
							})
						}
					}
				})
			},

			navTo(url) {
				if (url == '#') {
					this.$api.msg('暂未开放')
					return
				}
				this.$until.toUrl(url)
			},
			switchTo(url) {
				uni.switchTab({
					url
				})
			},
			noOpen() {
				this.$api.msg('暂未开放')
			},
			/**
			 * 请求静态数据只是为了代码不那么乱
			 * 分次请求未作整合
			 */
			// //轮播图切换修改背景色
			swiperChange(e) {
				const index = e.detail.current
				this.swiperCurrent = index
				// this.titleNViewBackground = this.carouselList[index].background;
			},
			navtopage(index) {
				var item = lunbo[index]
				homeApi.navtopage(item)
			},

			switchTabPage() {
				uni.switchTab({
					url: '/pagesE/pages/broadcast/broadcast'
				})
			},
			//跳转活动链接
			gogetactivity() {
				uni.navigateTo({
					url: '/pagesB/pages/getcoupon/getcoupon'
				})
			}
		}
	}
</script>
<style lang="scss">
	.all_box {

		.left {
			display: flex;
			justify-content: center;
			justify-items: center;
			width: 10%
		}

		.right {
			display: flex;
			justify-content: center;
			justify-items: center;
			width: 10%
		}

		.leaveblank_bottom {
			height: 120rpx;
		}

		.coupon {
			padding: 20rpx 5% 10rpx 5%;
			background-color: #ffffff;
			width: 95%;
			margin: 15rpx 2.5%;
			border-radius: 5%;

			.coupon_title {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;
				padding: 10rpx 0;

				.cupin_left {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.coupon_icon {
						width: 70rpx;
						height: 70rpx;
					}

					.cupin_left_p1 {
						font-size: 28rpx;
						color: #56ab2f;
					}
				}

				.cupin_right {
					font-size: 26rpx;
					color: #666;
				}
			}

			.center {
				display: flex;
				justify-content: center;
				align-items: center;
				margin: 7.5rpx 0;

				.tttle {

					width: 180rpx;
					text-align: center;
					font-weight: 700;
				}

				.line1,
				.line2 {
					height: 2rpx;

					width: 45%;
				}
			}

			.coupon_item {
				margin: 15rpx 0;
				position: relative;
				width: 100%;
				height: 137rpx;
				background: #ffffff;
				justify-content: space-between;
				display: inline-flex;
				color: #CF8201;
				align-items: center;

				.coupon_item_p1 {
					height: 100%;
					font-size: 35rpx;
					display: flex;
					justify-content: flex-start;
					align-items: center;
					width: calc(100% - 100rpx);
					background-color: #FDD48D;
					border-radius: 15rpx 0 0 15rpx;

					.coupon_item_p2_ti1_p1 {
						font-size: 55rpx;
					}

					.coupon_item_p2_ti1 {
						font-size: 80rpx;
						font-family: fantasy;
					}

					.coupon_item_p2_ti2 {
						margin-left: 15rpx;

						.describe {
							font-size: 28rpx;
							color: #8F5D25;
							font-weight: 600;
						}

						.describe2 {
							font-size: 22rpx;
							color: #8F5D25;
							font-weight: 600;
							margin: 15rpx 0;
						}

						.describe3 {
							font-size: 22rpx;
							color: #EE992A;
						}
					}
				}

				.coupon_item_p2 {
					display: flex;
					align-items: center;
					width: 100rpx;
					padding: 0 20rpx;
					height: 100%;
					text-align: center;
					background-color: #3D5479;
					color: #FFFFFF;
					border-radius: 0 15rpx 15rpx 0;
				}
			}
		}

		.place {
			width: 100%;
			height: 100px;

			.place_location {
				margin-left: 23rpx;
				font-size: 32rpx;
				color: #ffffff;
			}

			.flex {
				margin-top: 28rpx;
				display: flex;
				justify-content: flex-start;

				.fff {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #ffffff;
					margin-left: 37rpx;
				}

				.weather {
					margin-left: 34rpx;
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #fff;
				}
			}
		}

		.cate-section1 {
			padding: 15rpx;
		}

		.cate-section {
			position: relative;
			border-radius: 16upx 16upx 16upx 16upx;
		}

		.cate-section.mt0 {
			margin-top: 0;
		}

		.lunbo {
			padding-bottom: 30rpx;
			height: 150rpx;
			padding-top: 10rpx;

			/* 头部 轮播图 */
			.carousel-section {
				width: calc(100% - 30rpx);
				margin: 0 auto;

				.titleNview-placing {
					padding-top: 0;
					height: 0;
				}

				.carousel {
					.carousel-item {
						padding: 0;
						border-radius: 10rpx;
					}
				}

				.swiper-dots {
					left: 45upx;
					bottom: 40upx;
				}

				.titleNview-placing {
					height: var(--status-bar-height);
					padding-top: 44px;
					box-sizing: content-box;
				}

				.titleNview-background {
					position: absolute;
					top: 0;
					left: 0;
					width: 100%;
					height: 426upx;
					transition: 0.4s;
				}
			}


		}

		.farm-block1 {
			padding-left: 15rpx;
			padding-top: 15rpx;
			padding-right: 15rpx;
			margin-top: 60rpx;
		}

		.farm-block {
			position: relative;
			z-index: 5;
			border-radius: 16upx 16upx 16upx 16upx;
			display: flex;
			margin-top: 50rpx;
			justify-content: flex-start;
			align-items: center;
			flex-wrap: wrap;
			padding: 10upx 30upx;
			background: #fff;

			.farm {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				padding: 12rpx 0;
				width: 100%;

				.farm-img {
					width: 36rpx;
					height: 26rpx;

					.img {
						width: 36rpx;
						height: 26rpx;
					}
				}

				.ml35 {
					margin-left: 25rpx;
					border: 0.5rpx solid #f5f5f5;
					height: 20rpx;

					.dynamic,
					.news {
						width: 85rpx;
						height: 40rpx;
						background: #42c998;
						border-radius: 10rpx;
						line-height: 40rpx;
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #ffffff;
						text-align: center;
					}

					.news {
						margin-top: 16rpx;
						background: #ffa92e;
					}
				}

				.flex {
					display: flex;
					flex-wrap: wrap;
					margin-left: 26rpx;

					.swiper-block {
						height: 40rpx;

						swiper {
							height: 100%;
							width: 580rpx;
						}
					}

					.swiper-block2 {
						margin-top: 15rpx;
					}

					.swiper-item {
						text-overflow: ellipsis;
						overflow: hidden;
						white-space: nowrap;
						line-height: 40rpx;
						font-size: 25rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #56ab2f;
						display: flex;
						justify-content: space-between;

						.detail {
							font-weight: bold;
							margin-right: 0rpx;
							color: #100c0f;
						}

						.item-l {
							width: 490rpx;
							text-overflow: ellipsis;
							overflow: hidden;
							white-space: nowrap;
						}
					}
				}
			}
		}

		.carousel {
			width: 100%;
			height: 350upx;

			.carousel-item {
				width: 100%;
				height: 100%;
				padding: 0 28upx;
				overflow: hidden;
			}

			image {
				width: 100%;
				height: 100%;
				max-width: 100%;
				max-height: 100%;
				// border-radius: 10upx;
			}
		}

		.swiper-dots {
			display: flex;
			position: absolute;
			left: 60upx;
			bottom: 15upx;
			width: 72upx;
			height: 36upx;
			background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCA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rjg0OUQwOEUiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz4Gh5BPAAACTUlEQVR42uzcQW7jQAwFUdN306l1uWwNww5kqdsmm6/2MwtVCp8CosQtP9vg/2+/gY+DRAMBgqnjIp2PaCxCLLldpPARRIiFj1yBbMV+cHZh9PURRLQNhY8kgWyL/WDtwujjI8hoE8rKLqb5CDJaRMJHokC6yKgSCR9JAukmokIknCQJpLOIrJFwMsBJELFcKHwM9BFkLBMKFxNcBCHlQ+FhoocgpVwwnv0Xn30QBJGMC0QcaBVJiAMiec/dcwKuL4j1QMsVCXFAJE4s4NQA3K/8Y6DzO4g40P7UcmIBJxbEesCKWBDg8wWxHrAiFgT4fEGsB/CwIhYE+AeBAAdPLOcV8HRmWRDAiQVcO7GcV8CLM8uCAE4sQCDAlHcQ7x+ABQEEAggEEAggEEAggEAAgQACASAQQCCAQACBAAIBBAIIBBAIIBBAIABe4e9iAe/xd7EAJxYgEGDeO4j3EODp/cOCAE4sYMyJ5cwCHs4rCwI4sYBxJ5YzC84rCwKcXxArAuthQYDzC2JF0H49LAhwYUGsCFqvx5EF2T07dMaJBetx4cRyaqFtHJ8EIhK0i8OJBQxcECuCVutxJhCRoE0cZwMRyRcFefa/ffZBVPogePihhyCnbBhcfMFFEFM+DD4m+ghSlgmDkwlOgpAl4+BkkJMgZdk4+EgaSCcpVX7bmY9kgXQQU+1TgE0c+QJZUUz1b2T4SBbIKmJW+3iMj2SBVBWz+leVfCQLpIqYbp8b85EskIxyfIOfK5Sf+wiCRJEsllQ+oqEkQfBxmD8BBgA5hVjXyrBNUQAAAABJRU5ErkJggg==);
			background-size: 100% 100%;

			.num {
				width: 36upx;
				height: 36upx;
				border-radius: 50px;
				font-size: 24upx;
				color: #fff;
				text-align: center;
				line-height: 36upx;
			}

			.sign {
				position: absolute;
				top: 0;
				left: 50%;
				line-height: 36upx;
				font-size: 12upx;
				color: #fff;
				transform: translateX(-50%);
			}
		}

		/* 分类 */
		.cate-section {
			display: flex;
			justify-content: space-between;
			align-items: center;
			flex-wrap: wrap;
			padding: 30rpx 20rpx 5rpx 20rpx;
			background: #fff;

			.cate-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				font-size: $font-sm + 2upx;
				color: $font-color-dark;
				width: 19%;
				background: #fff;
				padding-bottom: 30rpx;
				float: left;
			}

			/* 原图标颜色太深,不想改图了,所以加了透明度 */
			text {
				margin-top: 14upx;
			}
		}

		.ad-1 {
			width: 100%;
			height: 210upx;
			padding: 10upx 0;
			background: #fff;

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



		.btn1 {
			background-color: transparent;
			position: fixed;
			right: 0;
			top: 77.5%;
			z-index: 11;
			width: 200rpx;
			height: 100rpx;
			outline: none;
			border: none;
		}

		.btnImg {
			width: 100%;
			height: 100%;
		}

		.btn1::after {
			outline: none;
			border: none;
		}



		.tag {
			display: flex;
			justify-content: space-around;
			margin-top: 20rpx;

			.tag-box {
				width: 200rpx;
				height: 113rpx;
				border: 1px solid $tab-color-1;
				color: $tab-color-1;
				border-radius: 10rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				flex-direction: column;
				font-size: 24rpx;

				.tag-img {
					width: 60rpx;
					height: 60rpx;
				}
			}
		}

		.updatepage {
			position: fixed;
		}
	}
</style>
