<template>
	<view class="wrap">
		<view class="banner">
			<u-swiper :list="imgList" name='url' mode="number" height="350"></u-swiper>
		</view>
		<view class="middle">
			<view class="tabbar">
				<text v-for="(item,index) in tabbar" :key='index' @click="tabbarChange(index)" :class="{'on':active==index}">
					{{item}}
				</text>
			</view>
			<swiper :current="active"  @animationfinish="animationfinish" class="swiper-box">
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height:100%;width: 100%;">
					<view class="merchant" v-for="(item,index) in scenicList" :key='index'>
						<view class="merchant-title">
							<view class="title-left">
								<text >{{item.name}}</text>
								<image src="../../../static/img/scenic/coupon.png" ></image>
								<text class="title-coupon">
									劵惠
								</text>
							</view>
							
							<view v-if="showDistance" class="title-right">
								距您{{item.distance?parseFloat((item.distance/1000).toFixed(2)):0}}km
							</view>							
						</view>
						<label v-for="(items,a) in item.productList" :key='a'>
							<view class="product">
								<view class="product-left">
									<checkbox class="blue" />
								</view>
								
								<view class="product-right">
									<view class="product-name">
										<text>{{items.name}}</text>
										<!-- <text class="product-status">已售罄</text> -->
									</view>
									
									<view class="product-price">
										<view style="font-size: 24rpx;">
											<text class="product-rule" v-if="items.productRefundRuleVo">
												<text v-if="items.productRefundRuleVo.refundType==0">不可退</text>
												<text v-if="items.productRefundRuleVo.refundType==1">规定时间退</text>
												<text v-if="items.productRefundRuleVo.refundType==2">随时可退</text>
											</text>
											
											<text class="product-rule">
												无需取票
											</text>
											<text>购买须知</text> 
											<u-icon name="arrow-right"></u-icon>
										</view>
										<view>
											<text class="product-orange">
												¥{{items.originalPrice}}
											</text>
											<text class="product-sell">
												<text style="font-size: 28rpx;">¥</text>{{items.sellingPrice}}
											</text>
										</view>
									</view>
								</view>
							</view>
						</label>
					</view>
					<u-empty text="空空如也..." mode="list" v-if="scenicList.length==0"></u-empty>
					</scroll-view>
				</swiper-item>
				
				<swiper-item class="swiper-item">
					<u-empty text="空空如也2..." mode="list"></u-empty>
				</swiper-item>
				
				<swiper-item class="swiper-item">
					<u-empty text="空空如也3..." mode="list"></u-empty>
				</swiper-item>
				<swiper-item class="swiper-item">
					<u-empty text="空空如也4..." mode="list"></u-empty>
				</swiper-item>
			</swiper>
		</view>
		<view class="bottom">
			<view class="bottom-left" @click="showCustomer()">
				<u-icon name='chat' size='36' style="margin-right: 8rpx;position: relative;top: 2rpx;"></u-icon>
				客服
			</view>
			<view class="bottom-middle">
				<view class="bottom-more">
					组合购更优惠
					<text class="bottom-three"></text>
				</view>
				
				<view class="bottom-detail">
					<text>
						明细
					</text>
					<u-icon name='arrow-up' size='32' style="margin: 0 8rpx;"></u-icon>
					<text class="bottom-number">
						1
					</text>
				</view>
			</view>
			<view class="bottom-right">
				<text class="btn">去预定</text>
			</view>
		</view>
		<!-- 客服组件 -->
		<customer :scenicList='scenicList' ref='customer'></customer>
	</view>
</template>

<script>
import customer from '@/components/customer.vue'//客服
export default {
  components:{
    customer
  },
  data() {
    return {
      merchantId:'z0015605022691a5945bbe463141668c',//商户Id
      tabbar:['热门景点','一日游','摄影/旅拍','文创DIY'],//tabbar标题列表
      active:0,//导航栏下标
      imgList:[],//图片列表
      scenicList:[],//景区数据
      showDistance:false,//定位成功显示距离
    }
  },
  onLoad(option){
    let token = uni.getStorageSync('token')
    if(token){
		  uni.getLocation({
			 type: 'wgs84',
			 success:res=> {
			   let latitude = res.latitude//纬度 
			   let longitude = res.longitude//经度
          this.showDistance=true
			  this.initList(latitude,longitude)
			  },
			  fail:res=>{
			    let latitude=''
			    let longitude=''
			    this.initList(latitude,longitude)
			  }
		  })
    }
  },
  methods:{
    //---导航栏切换
    tabbarChange(index){
      this.active=index
    },
    //---swiper滑动结束，分别设置tabs和swiper的状态
    animationfinish(e) {
		  let current = e.detail.current
		  this.active = current
    },
    //---展示客服组件
    showCustomer(){
      this.$refs.customer.showPop=true
    },
    //---商品列表
    initList(latitude,longitude) {
		  let data = {
		    merchantId: this.merchantId, //商户id
        latitude,
        longitude
		  }
		  this.$request('/scenic/groupGood/getGroupProducts', data).then(res => {
		    if (res.code == '00') {
		      this.scenicList = res.data.merchantList
          this.scenicList.forEach((item,index)=>{
            if(item.id==this.merchantId){
              this.imgList=item.imgList
              console.log(this.imgList)
            }
          })
		    } else {
		      uni.showToast({
		        title: res.message,
		        icon: 'none'
		      })
		    }
		  })
    },
  }
}
</script>

<style lang="scss" scoped>
.wrap{
	height: 100%;
	display: flex;
	flex-direction: column;
	background: #fff;
}
.middle{
	position: relative;
	top: -40rpx;
	padding: 0 24rpx;
	display: flex;
	flex-direction: column;
	flex: 1;
}
.swiper-box{
	flex: 1;
}
.tabbar{
	background: #fff;
	border-radius: 16rpx;
	display: flex;
	justify-content: space-between;
	font-size: 32rpx;
	text{
		padding:24rpx 32rpx 24rpx 20rpx;
		border-radius: 16rpx;
	}
}
.tabbar .on{
	background: url('../../../static/img/scenic/tabbar.png') no-repeat;
	background-size: 100% 100%;
	color: #fff;
	font-weight: bold;
}
.merchant{
	border-radius: 16rpx;
	background: #FFFFFF;
	box-shadow: 0px 0px 8px 2px rgba(0,0,0,0.08);
	margin-top: 24rpx;
	padding: 24rpx;
}
.merchant-title{
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding-bottom: 16rpx;
}
.title-left{
	font-size: 32rpx;
	margin-right: 10rpx;
	font-weight: bold;
	image{
		width: 36rpx;
		height: 36rpx;
		position: relative;
		top: 6rpx;
		margin:0 8rpx;
	}
}
.title-coupon{
	color: $red;
	font-size: 24rpx;
}
.title-right{
	color: $grey;
	font-size: 24rpx;
}
.product{
	padding: 16rpx;
	background: #ffffff;
	border-radius: 8rpx;
	display: flex;
	align-items: center;
}
.product.on{
	background: #E2EEFF;
}
.product-left{
	margin-right: 10rpx;
}
.product-right{
	flex: 1;
}
.product-name{
	font-size: 28rpx;
	font-weight: bold;
	color: #191919;
	display: flex;
	justify-content: space-between;
}
.product-status{
	padding: 6rpx 12rpx;
	border: 2px solid #F40000;
	background: #ffffff;
	color: #F40000;
	font-size: 24rpx;
	border-radius: 4rpx;
	transform: rotate(-25deg);
	position: relative;
	top: 30rpx;
	right: 80rpx;
}
.product-price{
	display: flex;
	justify-content: space-between;
	align-items: center;
}
.product-rule{
	color: $blue;
}
.product-rule::after{
	display: inline-block;
	content: '';
	height: 22rpx;
	margin: 0 10rpx;
	background: #ccc;
	width: 1px;
}
.product-orange{
	font-size: 20rpx;
	color:$grey;
	text-decoration:line-through;
}
.product-sell{
	font-size: 40rpx;
	color: $red;
	font-weight: bold;
	margin-left: 10rpx;
}


.bottom{
	position: fixed;
	bottom: 0;
	width: 100%;
	height: 100rpx;
	background: #fff;
	box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.16);
	z-index: 10;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 32rpx;
}
.bottom-middle{
	position: relative;
	padding: 0 40rpx;
}
.bottom-more{
	position: relative;
	top: -40rpx;
	background: #F40000;
	border-radius: 28px;
	opacity: 0.64;
	padding: 10rpx 20rpx;
	color: #ffffff;
}
.bottom-three{
	width: 14rpx;
	height: 14rpx;
	display: inline-block;
	background: #F40000;
	opacity: 0.64;
	position: absolute;
	right: 42rpx;
	bottom: -7rpx;
	transform:rotate(45deg);
}
.bottom-detail{
	position: relative;
	top: -28rpx;
	text-align: center;
}
.bottom-number{
	display: inline-block;
	width: 36rpx;
	height: 36rpx;
	border-radius: 50%;
	text-align: center;
	background: #F40000;
	color: #ffffff;
	font-weight: bold;
}
.btn{
	padding: 16rpx 48rpx;
	border-radius: 20rpx;
	font-size: 32rpx;
}
</style>