<template>
	<view class="selected-services">
		<!-- 头部 -->
		<navbar :config="config" backColor="#666"></navbar>
		<view class="shopCard">
			<view class="shop-info">
				<image :src="shop.logo" mode=""></image>
				<view class="shopNamebox">
					<view class="phone-btn" @click="goPhone(shop.customer_service_phone)">售后电话</view>
					<view class="shopName">{{ shop.shop_name }}</view>
					<view class="shopName_rate">
						<rate :value="shop.averageCopy"></rate> {{ shop.average }}分
					</view>
				</view>
			</view>
			<template v-if="false">
				<view class="shop_item mt30" style="alignItems: flex-start;">
					<image src="/static/convenienceService/location2.png" mode=""></image>
					<view>{{shop.province_name+shop.city_name+shop.area_name+shop.address}}</view>
				</view>
				<view class="shop_item" style="alignItems: flex-start;">
					<text class="iconfont2">&#xe651;</text>
					<view>营业时间：{{ shop.business_hours }}{{ shop.time_quantum }}</view>
				</view>
			</template>
			<view class="searchBox">
				<image src="/static/convenienceService/search.png" mode=""></image>
				<input @click="searchClick" v-model="value" type="text" placeholder-style="color:#B3B3B3;fontSize:28rpx"
					placeholder="可搜索本店商品" />
			</view>
		</view>
		<!-- 限时秒杀 -->
		<view class="seckill" v-if="currSeckill && currSeckill.length > 0">
			<view class="seckill-flex">
				<view class="seckill-top" @click="goProductDetails('/pages/research/nearby/timeLimit?shopid='+shopId)">
					<view class="seckill-left"> 限时秒杀 </view>
					<view class="seckill-line" v-if="currTime"> </view>
					<view class="seckill-time" v-if="currTime">{{ currTime }}点场 剩余
					</view>
					<view class="time-item">
						<uni-countdown :backgroundColor="'none'" @timeup="overDown2" :color="'#fff'"
							:splitorColor="'#fff'" :show-day="time2[0] > 0" :day="time2[0]" :hour="time2[1]"
							:minute="time2[2]" :second="time2[3]"></uni-countdown>
					</view>
				</view>
				<view class="commodity" v-if="currSeckill && currSeckill.length > 0">
					<swiper :indicator-dots="false" :autoplay="false" :display-multiple-items="itemsDis2"
						@change="imgActiveFun2" style="height: 220rpx" circular="true">
						<!-- 						<swiper-item class="option-item" @click="
                goProductDetails(
                  '/pages/product/goods/seckillGoods?id=' + item.id
                )
              " v-for="item in currSeckill" :key="item.id">
							<image v-if="item && item.cover" :src="item.cover" mode=""></image>
							<view class="number">
								<rich-text :nodes="$mUtil.priceBigSmall(item.min_price)"></rich-text>
							</view>
						</swiper-item> -->
						<swiper-item v-for="(item,key) in currSeckill" :key="key">
							<div class="fa-item">
								<view class="option-item" v-for="itemSon in item"
									@click="goProductDetails('/pages/product/goods/seckillGoods?id=' + itemSon.id)"
									:key="item.id">
									<image v-if="itemSon && itemSon.cover" :src="itemSon.cover" mode=""></image>
									<view class="number">
										<rich-text :nodes="$mUtil.priceBigSmall(itemSon.min_price)"></rich-text>
									</view>
								</view>
							</div>
						</swiper-item>
					</swiper>
					<!-- <view class="slide-box">
						<view class="dotBox" v-if="currSeckill.length > 1">
							<view class="dotBox_item" v-for="(v, i) in currSeckill" :key="i"
								:class="{ active_dotBox: activeBannerIndex2 == i }"></view>
						</view>
					</view> -->
					<view class="dotBox" v-if="currSeckill.length > 1">
						<view class="dotBox_item" v-for="(v, i) in currSeckill" :key="i"
							:class="{ active_dotBox: activeBannerIndex2 == i }"></view>
					</view>
				</view>

				<nodata v-else :config="{ top: 1, content: '暂无商品~' }"></nodata>
			</view>
		</view>

		<!-- 拼团购 -->
		<view class="group-work" v-if="groupList && groupList.length > 0">
			<view class="group-item">
				<view class="group-top" @click="goProductDetails('/pages/research/homepage/groupList?shopid='+shopId)">
					<view class="group-left"> 拼团购 </view>
					<view class="group-right">
						查看更多<text class="iconfont u-font24 u-999">&#xe6c7;</text>
					</view>
				</view>
				<view v-if="groupList && groupList.length > 0">
					<view class="work-item" v-for="(item, index) in groupList" :key="index" @click="
            goProductDetails('/pages/product/goods/puzzleGoods?id=' + item.id)
          ">
						<view class="work-left">
							<image :src="item.cover" class="work-image" mode=""></image>
						</view>
						<view class="work-title">
							<view class="u-text2 u-mt10">
								{{ item.title }}
							</view>

							<view class="go-group-work">
								<view class="work-number">
									<view class="num">
										<view class="large">
											<rich-text :nodes="$mUtil.priceBigSmall(item.min_price)"></rich-text>
										</view>
										<view class="small">
											<text class="pintuanc6">¥ {{ item.min_sale_price }}</text>
										</view>
									</view>

									<view class="how-many-people">
										{{ item.group_people_num }}人团，已拼<text class="number">{{
                      item.result_sale_num
                    }}</text>件
									</view>
								</view>
								<view class="go-btn">去拼团</view>
							</view>
						</view>
					</view>
				</view>
				<nodata v-else :config="{ top: 1, content: '暂无商品~' }"></nodata>
			</view>
		</view>
		<!-- 拼团购 -->
		<!-- 精品服务 -->

		<view class="boutique">
			<view class="item" :class="{ itemswitch: isActive == index }" v-for="(item, index) in service"
				:key="item.id" @click="switchAssembly(index)">
				{{ item.name }}
			</view>
		</view>

		<!-- <view class="transformation" :is="currentView"> </view> -->
		<!-- <service  v-if="isActive==0" :cate='serviceCate' :good='serviceGood' @typeChange='serviceTypeChange'></service> -->
		<commodity :cate="commCate" :good="commGood" :isActive='isActive' @typeChange="commTypeChange"></commodity>
	</view>
</template>

<script>
	import commodity from "../../../components/selected/commodity.vue";
	import rate from "@/components/rate.vue"
	export default {
		components: {

			commodity,
			rate
		},
		data() {
			return {
				service: [
					// {
					// 	id: 1,
					// 	name: "精品服务",
					// },
					{
						id: 2,
						name: "精选商品",
					},
				],

				isActive: 0,
				config: {
					back: true, //false是tolbar页面 是则不写
					title: "店铺信息",
					color: "#1a1a1a",
					//背景颜色;参数一：透明度（0-1）;参数二：背景颜色（array则为线性渐变，string为单色背景）
					backgroundColor: [1, "#fff"],
				},
				username: 123,
				scrollTop: 0,
				old: {
					scrollTop: 0,
				},
				shop: {}, //店铺信息
				currTime: null, //秒杀当前场
				currSeckill: [], //秒杀列表
				ml2: -22, //小红点偏移
				itemsDis2: 1, //当前小红点位置
				keyList2: 0, //一共几个点
				time2: [0, 0, 0, 0], //秒杀倒计时
				groupList: [],
				activeBannerIndex2: 0,

				shopId: null,
				commCate: [], //商品分类
				commGood: [], //商品列表
				commParams: {
					limit: 100000,
				},
				value: ""


			};
		},
		onLoad(options) {
			if (options.shopId) {
				this.shopId = options.shopId;
				this.getCommCate(options.shopId);
				this.getIndexList(options.shopId);
				this.seckillList(options.shopId);
				this.getgroupList(options.shopId);
				this.getCommGood(this.shopId);
			}
		},
		methods: {
			searchClick() {
				uni.navigateTo({
					url: "/pages/research/homepage/search",
				});
			},
			callPhone() {
				uni.makePhoneCall({
					phoneNumber: this.shop.customer_service_phone
				});
			},
			switchAssembly(index) {
				this.isActive = index;
				delete this.commParams.group_id;
				delete this.commParams.type;

				this.getCommCate(this.shopId);

				this.getCommGood(this.shopId);


			},



			commTypeChange(e) {
				if (e.type == undefined) {
					delete this.commParams.type;
					this.commParams.group_id = e.groupId;
					console.log(e)
					console.log('参数')
				} else {
					delete this.commParams.group_id;
					this.commParams.type = e.type;
				}
				this.getCommGood(this.shopId);
			},


			/**商品列表 */
			getCommGood(shopId) {
				this.$http
					.get(this.isActive == 0 ? `/service/goods/list/${shopId}` : `/goods/list/${shopId}`, this.commParams,
						false)
					.then((res) => {
						if (res && res.code == 200) {
							this.commGood = res.list;
						}
					});
			},

			/**商品分类 */
			getCommCate(shopId) {

				this.$http
					.get(this.isActive == 0 ? `/servicegoods/group/all/${shopId}` : `/goods_group/all/${shopId}`, {},
						false)
					.then((res) => {
						if (res && res.code == 200) {
							this.commCate = res.list;
						}
					});


			},
			imgActiveFun2(e) {
				this.activeBannerIndex2 = e.detail.current;
			},
			goProductDetails(url) {
				uni.navigateTo({
					url: url,
				});
			},
			/**限时秒杀 */
			seckillList(shopId) {
				this.$http
					.get(
						`/marketing/seckillActivityGoods/flash-sale?shop_id=${shopId}`, {
							limit: 10,
							page: 1
						},
						false
					)
					.then((res) => {
						if (res && res.code == 200) {
							this.currTime = res.data.start_hour;
							this.currSeckill = this.oneArrToTwoArr(res.data.list)

							// if (this.currSeckill && res.data.list.length <= 4) {
							// 	this.keyList2 = 1;
							// 	this.itemsDis2 = res.data.list.length;
							// }
							// if (
							// 	this.currSeckill &&
							// 	res.data.list.length > 4 &&
							// 	res.data.list.length <= 8
							// ) {
							// 	this.keyList2 = 2;
							// 	this.ml2 = -45;
							// 	this.itemsDis2 = 3;
							// }
							// if (
							// 	this.currSeckill &&
							// 	res.data.list.length > 8 &&
							// 	res.data.list.length <= 12
							// ) {
							// 	this.keyList2 = 3;
							// 	this.ml2 = -68;
							// 	this.itemsDis2 = 3;
							// }
							// if (
							// 	this.currSeckill &&
							// 	res.data.list.length > 12 &&
							// 	res.data.list.length <= 16
							// ) {
							// 	this.keyList2 = 4;
							// 	this.ml2 = -90;
							// 	this.itemsDis2 = 3;
							// }
							if (res.data.finish_time) {
								this.time2 = this.$mUtil
									.countDown(Math.floor(res.data.finish_time / 1000))
									.split(":")
									.map((val) => Number(val));
							}
						}
					});
			},
			oneArrToTwoArr(data) {
				let newData = [];
				let zyf = 4; //一维数组转二维数组长度(此处是二维数组每一个长度控制)
				for (var i = 0; i < Math.ceil(data.length / zyf); i++) {
					newData[i] = [];
					newData[i].push(data[i * zyf]);
					for (var j = 1; j < zyf; j++) {
						if (data[i * zyf + j] == undefined) {
							//超出长度控住
							return newData;
						} else {
							newData[i].push(data[i * zyf + j]);
						}
					}
				}
				return newData;
			},
			/**团购 */
			getgroupList(shopId) {
				this.$http
					.get(
						`/groupbuy/activitygoods/will-you-spell?shop_id=${shopId}`, {
							limit: 10,
							page: 1
						},
						false
					)
					.then((res) => {
						if (res && res.code == 200) {
							this.groupList = res.list;
						}
					});
			},
			/**查看地图 */
			openMap(shop) {
				uni.openLocation({
					latitude: Number(shop.tx_latitude),
					longitude: Number(shop.tx_longitude),
					name: shop.name,
					address: shop.address,
					success: function() {
						console.log("success");
					},
				});
			},
			/**获取店铺基本信息 */
			getIndexList(shopid) {
				this.$http.get("/yxt/shop/info/" + shopid).then((res) => {
					uni.stopPullDownRefresh();
					this.loading = false;
					if (res.data && res.code == 200) {
						this.shop = res.data;
						this.shop.averageCopy = Math.round(res.data.average)
					}
				});
			},
			scroll: function(e) {
				// console.log(e)
				this.old.scrollTop = e.detail.scrollTop;
			},
		},
	};
</script>

<style lang="scss" scoped>
	.itemswitch {
		border-bottom: 4px solid #FA6138;
		color: #FA6138;
		font-weight: 700;
	}

	.boutique {
		display: flex;
		justify-content: space-around;
		margin: 0 30rpx;
		background-color: #fff;
		font-weight: 500;
		line-height: 30rpx;
		// color: #FA6138;

		.item {
			padding: 50rpx 0 20rpx 0;
			margin-bottom: 26rpx;
		}
	}

	// .work-title:last-child{
	// 	border: none;
	// }

	.work-item {
		padding: 0 20rpx;
		display: flex;
		position: relative;

		.work-title {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			padding-top: 59rpx;
			padding-left: 25rpx;
			font-size: 28rpx;
			font-weight: Regular;
			color: rgba(24, 24, 24, 1);
			flex: 1;

			.how-many-people {
				margin-top: 8rpx;
				height: 33rpx;
				opacity: 1;
				font-size: 24rpx;
				font-weight: 400;
				text-align: left;
				color: #333333;
				line-height: 24rpx;

				.number {
					color: red;
					font-weight: Regular;
				}
			}
		}

		.work-image {
			border-radius: 16rpx;
			width: 226rpx;
			height: 226rpx;
			background-color: red;
			margin-top: 50rpx;
			flex: 1;
		}

		.go-group-work {
			display: flex;
			align-items: flex-end;
			justify-content: space-between;

			.work-number {
				margin-top: 46rpx;
				font-weight: Bold;
				font-size: 20rpx;
				color: red;

				.num {
					display: flex;
					align-items: center;
				}

				.small {
					color: #cccccc;
					font-size: 22rpx;
					font-weight: 500;
					text-decoration: line-through;
					margin-left: 17rpx;
				}

				.work-red {
					font-size: 36rpx;
					font-weight: Bold;
					margin-left: 5rpx;
				}
			}

			.go-btn {
				background-color: #FA6138;
				color: #ffffff;
				padding: 11rpx 27rpx 11rpx 27rpx;
				border-radius: 32rpx;
				font-size: 28rpx;
				font-weight: 500;
			}
		}
	}

	.group-work {
		margin: 0 30rpx;

		.group-item {
			margin-bottom: 20rpx;
			background-color: #ffffff;
			margin-top: 50rpx;
			border-radius: 20rpx;

			.group-top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 0 30rpx 0 30rpx;
				padding: 30rpx 0;
				border-bottom: 1rpx solid rgba(230, 230, 230, 1);

				.group-left {
					color: #000000;
					font-size: 36rpx;
					font-weight: Bold;
				}

				.group-right {
					font-size: 24rpx;
					font-weight: 400;
					color: rgba(51, 51, 51, 1);

					.iconfont {
						// font-size: 10rpx;
						color: #666666;
						margin-left: 10rpx;
					}
				}
			}
		}
	}

	.commodity {
		//   display: flex;
		position: relative;
		//   padding: 12rpx 20rpx;
		margin: 20rpx 0;

		/deep/ .uni-swiper-slide-frame {
			width: 26% !important;
		}

		.fa-item {
			display: flex;
		}

		.option-item:first-child {
			margin-left: 0;
		}

		.option-item {
			margin-left: 24rpx;

			image {
				width: 140rpx;
				height: 140rpx;
			}

			.number {
				margin-top: 4rpx;
				text-align: center;
				font-size: 36rpx;
				font-weight: Bold;
				line-height: 24rpx;
				color: #333333;
				width: 140rpx;

				text {
					font-size: 28rpx;
					font-weight: Medium;
				}
			}
		}
	}

	.dotBox {
		position: absolute;
		bottom: 0rpx;
		left: 50%;
		transform: translateX(-50%);
		height: 14rpx;
		overflow: hidden;
		border-radius: 14rpx;
		background-color: #ccc;
		display: flex;
		justify-content: center;

		.dotBox_item {
			width: 45rpx;
			height: 14rpx;
			border-radius: 2rpx;
			background-color: #ccc;
			transition: all 0.5s;
		}

		.active_dotBox {
			width: 45rpx;
			background: rgba(254, 70, 3, 1);
			transition: all 0.5s;
		}
	}

	.seckill {
		color: #fefefe;
		margin-top: 45rpx;
		margin: 45rpx 30rpx;

		.seckill-flex {
			overflow: hidden;
			// margin: auto;
			background-color: rgba(255, 255, 255, 1);
			border-radius: 20rpx;
			padding: 0 29rpx;

			.seckill-top {
				display: flex;
				align-items: center;
				margin: 0;
				padding: 30rpx 0;
				border-bottom: 1rpx solid #e6e6e6;

				.seckill-left {
					color: black;
					font-size: 36rpx;
					font-weight: 700;
					font-weight: Bold;
					padding-right: 16rpx;
				}

				.seckill-line {
					margin: 0 16rpx;
					width: 1rpx;
					height: 33rpx;
					background-color: #707070;
				}

				.seckill-time {
					font-size: 24rpx;
					font-weight: 400;
					color: #666;
				}

				.time-item {
					background: #FF0000;
					padding: 0 15rpx;
					font-size: 24rpx;
					margin-left: 30rpx;
					border-radius: 17rpx;
					font-weight: 700;
				}
			}
		}
	}

	.shop {
		position: relative;
		box-shadow: 1rpx 1rpx 1rpx #f7f7f7;
		margin: -105rpx 30rpx 0 30rpx;
		background-color: white;
		border-radius: 25rpx;
		z-index: 10;

		.map {
			display: flex;
			padding: 0 20rpx;
			margin-top: 24rpx;
			font-weight: 400;
			font-size: 24rpx;
			font-weight: 400;

			.iconfont {
				color: #163c2a;
				margin-right: 12rpx;
			}

			.name {
				font-size: 24rpx;
				color: #333333;
				font-weight: 400;
				width: 440rpx;
			}

			.see {
				color: #fe9000;
				margin-left: 20rpx;
			}
		}

		.do-business {
			display: flex;
			align-items: center;
			font-style: 24rpx;
			font-weight: 400;
			color: #333333;
			margin-top: 26rpx;
			padding: 0 20rpx 34rpx 20rpx;

			.iconfont {
				color: #163c2a;
				margin-right: 12rpx;
			}
		}

		.item {
			display: flex;

			.img {
				width: 200rpx;
				height: 200rpx;
				background-color: #fff;
				margin-top: -75rpx;
				border-radius: 20rpx;
				margin-left: 15rpx;
				/* display: none; */
			}

			.item-right {
				margin-top: 30rpx;

				.name {
					font-size: 32rpx;
					color: #333333;
					font-weight: Bold;
					margin-left: 21rpx;
					font-size: 32rpx;
				}

				.comment {
					margin-top: 10rpx;
					padding-left: 16rpx;
					align-items: center;
					display: flex;

					.iconfont {
						color: #ff4e15;
						padding-left: 10rpx;
					}

					.five-stars {
						margin-left: 16rpx;
						font-size: 28rpx;
						font-weight: Medium;
						color: #ff4e15;
					}
				}
			}
		}
	}




	.searchBox {
		display: flex;
		padding: 10rpx 35rpx;
		border: 1rpx solid #CCCCCC;
		border-radius: 36rpx;
		margin: 30rpx 0 0;
		display: flex;
		align-items: center;
		margin-top: 10rpx;
		background: #fff;

		image {
			width: 35rpx;
			height: 35rpx;
			margin-right: 15rpx;
			flex-shrink: 0;
		}

		input {
			text-align: left;
		}
	}

	.shopCard {
		// margin: 100rpx auto 0;
		width: 720rpx;
		// min-height: 320rpx;
		padding: 30rpx;
		// background: url('/static/convenienceService/cardBg.png')0 0 no-repeat;
		// background-size: 720rpx 320rpx;
		box-shadow: 0rpx 4rpx 8rpx 0rpx #f1f1f1;
		background: #ffffff;
		border-radius: 20rpx;
		position: relative;

		.shop-info {
			display: flex;
			align-items: center;

			>image {
				// position: absolute;
				// top: -70rpx;
				// left: 30rpx;
				width: 120rpx;
				height: 120rpx;
				border-radius: 20rpx;
				background: #fff;
				flex-shrink: 0;
			}
		}

		.shopNamebox {
			flex: 1;
			margin-left: 20rpx;
			position: relative;

			.phone-btn {
				width: 150rpx;
				margin-left: auto;
				padding: 6rpx 10rpx;
				text-align: center;
				color: #666;
				border-radius: 8rpx;
				background-color: #fff;
				border: 1rpx solid #666;
				position: absolute;
				right: 0;
				bottom: 0;
			}

			.shopName {
				font-size: 32rpx;
				color: #333333;
				font-weight: 700;
				// margin-top: 30rpx;
			}

			.shopName_rate {
				font-size: 28rpx;
				color: #333333;
				display: flex;
				margin-top: 15rpx;
			}
		}

		.shop_item {
			font-size: 24rpx;
			color: #333333;
			display: flex;
			align-items: center;
			margin-top: 22rpx;
			padding: 0 10rpx;

			text {
				color: #108948;
				font-size: 34rpx;
			}

			view {
				margin-left: 20rpx;
			}

			image {
				width: 34rpx;
				height: 37rpx;
				flex-shrink: 0;
			}

			.blueicon {
				color: #FA6138;
			}
		}
	}
</style>