<template>
	<view class="">
	<view class="index container" v-if="$store.state.is_kg == 1">

		<view class="top_img">
			<view class="">
				<view class="">
					<image src="@/static/logo.png" mode=""></image>
				</view>
				<view class="">
					鲑鱼数藏
				</view>
			</view>
			<view class="" @click="href('/pages/my/rank/rank')">
				<image src="@/static/index/1.png" mode="widthFix" style="width: 40rpx;"></image>
			</view>
		</view>

		<!-- 广告图 -->
		<view class="banner">
			<u-swiper circular :indicatorInactiveColor="'#fff'" :list="banner" :keyName="'img'" :bgColor="'#111111'"
				@click="onHref" :height="'256rpx'">
			</u-swiper>
		</view>



		<!-- 通知栏 -->
		<view class="noticebar">

			<view class="left logo">
				<image src="/static/index/2.png" mode="widthFix" style="width: 60rpx;"></image>
			</view>
			<view class="notice_text">
				<u-notice-bar :color="'#fff'" :text="notice_new" :icon="''"
					@click="href('/pages/news/details/details?id='+new_id)">
				</u-notice-bar>
			</view>
			<view class="right logo" @click="totabar('/pages/find/find')">
				<image src="/static/index/03.png" mode="" style="width: 40rpx;height: 40rpx;"></image>
			</view>
		</view>


		<!-- 菜单 -->
		<view class="head_bar">
			<view class="" v-for="(item,index) in list1" :key="index" :class="index==i?'syColor':''" @click="i=index">
				{{item.name}}
				<view class="" :class="index==i?'syColor1':''">
				</view>
			</view>
		</view>


		<view class="good-list" v-if="i==0 || i ==1 || i ==2">
			<view class="list-item" @click="href(item.url + item.id)" v-for="(item, index) in recommend" :key="index">
				<view class="" style="background: #000;width: 100rpx;">
				</view>
				<view class="list-img">
					<view class="back-bott" v-if="i==0">
						<view class="hot1" v-if="item.sell_num>0&&item.status=='未开始'">
							<view class="">
								<view class="">
									<image src="/static/index/08.png" mode="widthFix"
										style="width: 36rpx;margin-top: 10rpx;"></image>
								</view>
								<view class="" style="margin-left: 10rpx;">
									即将开售
								</view>
							</view>
							<u-count-down style="font-weight: 800;margin-top: -10rpx;" :time="item.time*1000"
								format="HH:mm:ss">
							</u-count-down>
						</view>
						<view class="hot1" v-if="item.sell_num>0 &&item.status == '抢购中'">
							<view class="">
								<image src="/static/index/07.png" mode="widthFix" style="width: 36rpx;"></image>
							</view>
							<view class="">
								热卖中
							</view>
						</view>
						<view class="hot1" v-if="item.sell_num<=0">
							<view class="">
								<image src="/static/index/08.png" mode="widthFix" style="width: 36rpx;"></image>
							</view>
							<view class="">
								已售罄
							</view>
						</view>
					</view>
					<image :src="item.cover" style="width: 686rpx;border-radius: 24rpx;" mode="widthFix" />
				</view>

				<view class="item-bot">
					<view class="list-ctx">
						{{ item.title }}
					</view>
					<view class="list-gx">
						<view class="">
							<view class="">
								限量
							</view>
							<view class="">
								{{ item.num }}份
							</view>
						</view>
						<view class="price" v-if="i==1">
							<view>￥</view>
							<view>{{ item.price }}</view>
						</view>
					</view>
					<view class="list-prc" v-if="item.type==2">
						<view class="">
							<view class="">
								<image src="/static/logo.png" mode=""
									style="width: 32rpx;height: 32rpx;border-radius: 50%;"></image>
							</view>
							<view class="list-pirce">{{ item.writer }}</view>
						</view>

						<view class="">
							<text>￥</text>
							<text>{{ item.price }}</text>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="" style="font-size: 24rpx;color: #999;text-align: center;">
			没有数据了
		</view>
	</view>
	<view class="" v-else>
		<image src="@/static/index/04.png" mode="widthFix" style="width: 750rpx;"></image>
	</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list1: [{
						name: '藏品',
					},
					{
						name: '盲盒',
					},
					{
						name: '抽签',
					}
				],
				bannerList: [{
						img: '/static/index/04.png'
					},
					{
						img: '/static/index/05.png',
						e: '/pages/Shopping/index'
					},
					{
						img: '/static/index/06.png'
					}
				],
				recommend: [], //推荐列表  
				box_list: [], //盲盒专区
				banner: [], //轮播图
				i: 0, //头部导航索引
				pages: 0, //热门推荐数量
				ms: 0, //即将开售时间倒计时
				current: 0,
				notice_new: "", //滚动最新公告
				Subtxt: "订阅",
				new_id: '',
				value: '',
				activity: [],
				activity1: []
			}
		},
		watch: {
			//头部索引发生变化触发渲染哪个列表
			i(val) {
				uni.showToast({
					title: "加载中",
					icon: "loading"
				})
				this.init()
				this.activity = []
				this.activity1 = []
				if (val == 0) {
					this.get_recommend_list()
				} else if (val == 1) {
					this.get_box_list()
				} else if (val == 2) {
					this.getHot()
					uni.hideLoading()
				}
			}
		},
		onLoad() {
			// 公告栏
			this.get_notcie()
			// 盲盒专区
			this.get_recommend_list()
			this.get_banner()
		},
		onReachBottom() {
			uni.showToast({
				title: "加载中",
				icon: "loading"
			})

			if (this.i == 0) {
				this.get_recommend_list()
			} else if (this.i == 1) {
				this.get_box_list()
			} else if (this.i == 2) {
				this.getHot()
			}
		},
		// onHide() {
		// 	this.init()
		// },
		methods: {
			aa() {
				this.value = ''
				this.init()
				this.get_recommend_list()
			},
			search() {
				this.init()
				this.get_recommend_list()
			},

			init() {
				//初始化 列表数据
				this.recommend = []
				this.box_list = []
				//页数清0
				this.pages = 0
			},
			click(e) {
				this.i = e.index;
			},
			get_notcie() {
				this.api.get_notice_list().then(res => {
					if (res.code == 1) {
						this.notice = res.data.data;
						this.notice_new = res.data.data[0].name
						this.new_id = res.data.data[0].id
					}
				})
			},

			get_banner() {
				this.api.banner().then(res => {
					this.banner = res.data
				})
			},
			onHref(e) {
				console.log(this.banner[e].type)
				if (this.banner[e].type == "LK") {
					// this.href('./webView/webView?path=' + this.banner[e].url)
					this.href(this.banner[e].url)
				}
			},
			baseMode() {
				this.api.baseMode().then(res => {
					res.data.forEach(ele => {
						this.activity.push({
							name: ele.name,
							pic1: ele.pic1,
							pic2: ele.pic2,
							create_at: ele.create_at,
							url: ele.url
						})
					})
				})
			},
			get_recommend_list() {
				this.api.popular(30, ++this.pages, this.value).then(res => {
					if (res.code == 1) {
						res.data.data.forEach(ele => {
							this.recommend.push({
								id: ele.id,
								img: ele.img, //藏品图
								status: ele.sell_status == 1 ? '抢购中' : '未开始', //1.售卖中 2.待开始
								writer: ele.user.nickname, //创作者名称
								writer_img: ele.user.headimg, //创作者头像
								price: ele.price, //加个
								num: ele.num, //限量
								title: ele.name, //藏品名称
								cover: ele.cover, //封面
								time: parseInt(ele.sell_at - (new Date().getTime() /
									1000)), //倒计时
								bls: this.getTime(ele.create_at, true),
								sell_num: ele.sell_num, // 剩余数量
								type: 2,
								url: '/pages/index/Details/Details?id='
							})
						})
					}
					uni.hideToast() //关闭加载
				})
			},

			getHot() {
				this.api.getHot(30, ++this.pages, this.value).then(res => {
					if (res.code == 1) {
						res.data.data.forEach(ele => {
							this.recommend.push({
								id: ele.id,
								img: ele.img, //藏品图
								status: ele.sell_status == 1 ? '抢购中' : '未开始', //1.售卖中 2.待开始
								writer: ele.user.nickname, //创作者名称
								writer_img: ele.user.headimg, //创作者头像
								price: ele.price, //加个
								num: ele.num, //限量
								title: ele.name, //藏品名称
								cover: ele.cover, //封面
								time: parseInt(ele.sell_at - (new Date().getTime() /
									1000)), //倒计时
								bls: this.getTime(ele.create_at, true),
								sell_num: ele.sell_num, // 剩余数量
								type: 2,
								url: '/pages/index/Details/Details?id='
							})
						})
					}
					uni.hideToast() //关闭加载
				})
			},
			getTime(time) {
				var date = new Date(time);
				return `${this.getT(date.getMonth() + 1)}-${this.getT(date.getDate())}  ${this.getT(date.getHours())}:${this.getT(date.getMinutes())}`
			},
			getT(n) {
				return n < 10 ? '0' + n : n
			},
			//获取盲盒列表
			get_box_list() {
				this.api.box_list(30, ++this.pages).then(res => {
					if (res.code == 1) {
						res.data.data.forEach(ele => {
							this.recommend.push({
								id: ele.id,
								cover: ele.box_img, //封面
								price: ele.price, //加个
								num: ele.num, //数量
								title: ele.box_name, //名称
								time_start: ele.date_start, //开始时间
								time_end: ele.date_end, //结束时间
								bls: this.getTime(ele.create_at, true),
								type: 1,
								url: '/pages/index/boxDetails/boxDetails?id=',
								sell_num: ele.sell_num
							})
						})
						uni.hideToast()
					}
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.index {
		width: 750rpx;
		overflow-y: scroll;
		box-sizing: border-box;
		height: calc(100vh - 120rpx);

		.top_img {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 32rpx;
			height: 88rpx;
			margin-bottom: 24rpx;

			>view:first-child {
				display: flex;

				image {
					width: 48rpx;
					height: 42rpx;
					margin-right: 20rpx;
				}
			}

			>view:last-child {
				width: 40rpx;
				height: 40rpx;
			}
		}

		.banner {
			width: 686rpx;
			height: 256rpx;
			margin: 0 auto;
		}

		.noticebar {
			padding-left: 20rpx;
			width: 682rpx;
			height: 104rpx;
			margin: 24rpx auto 0;
			display: flex;
			align-items: center;
			justify-content: space-between;
			box-sizing: border-box;
			border-radius: 24rpx;
			z-index: 66;
			position: relative;
			box-sizing: border-box;
			background: #1D1F1E;


			.left {
				width: 100rpx;
				text-align: center;

				image {
					width: 54rpx;
				}
			}

			.right {
				text-align: center;
				margin-right: 32rpx;
			}

			.u-notice-bar {
				width: 450rpx;
			}

		}

		.good-list {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			padding: 0 20rpx;
			box-sizing: border-box;
			padding-bottom: 50rpx;
			overflow: hidden;

			.list-item {
				width: 686rpx;
				background: #1D1F1E;
				box-sizing: border-box;
				overflow: hidden;
				z-index: 1;
				margin: 0 auto 24rpx;
				border-radius: 24rpx;

				.list-img {
					position: relative;
					overflow: hidden;
				}



				.back-bott {
					bottom: 0;
					margin: 0 auto;


					>view {
						display: flex;
						justify-content: center;
						text-align: center;
						background: rgba(0, 0, 0, .6);
						border-radius: 12rpx;
						color: #FFDEB3;
						font-size: 24rpx;
						display: inline-block;
						position: absolute;
						z-index: 99;
						margin: 32rpx;
						align-items: center;
						height: 72rpx;
						padding: 0 28rpx;
					}

					.hot {
						height: 88rpx;
						background: url(/static/index/016.png) no-repeat;
						background-size: 100% 100%;
						display: flex;
						flex-direction: column;
						align-items: center;
						color: #DFB9AE;
						letter-spacing: 2rpx;

						>view:first-child {
							margin-top: -10rpx;
							display: flex;
							align-items: center;
						}

						>view:last-child {
							margin-left: 12rpx;

						}

						/deep/.u-count-down span {
							font-weight: normal !important;
						}
					}

					.hot1,
					.hot1 {
						height: 72rpx;
						display: flex;
						align-items: center;
						color: #fff;
						font-size: 24rpx;

						>view:first-child {
							margin-top: -10rpx;
							display: flex;
							align-items: center;
						}

						>view:last-child {
							margin-left: 12rpx;
						}
					}
				}

				.item-bot {
					padding: 0 24rpx;

					.list-ctx {
						font-size: 32rpx;
						font-weight: 600;
						color: #fff;
						margin-top: 24rpx;
					}

					.list-gx {
						color: #fff;
						display: flex;
						justify-content: space-between;
						align-items: center;
						margin-top: 24rpx;
						margin-bottom: 30rpx;

						>view:first-child {
							display: flex;
							align-items: center;
							line-height: 48rpx;
							font-size: 22rpx;

							>view:first-child {
								background: #F4E0BD;
								padding: 0 10rpx;
								border-radius: 8rpx;
								color: #000;
							}

							>view:last-child {
								color: #F4E0BD;
								border-radius: 48rpx;
								background: #4B4B4B;
								border-radius: 8rpx;
								padding: 0 10rpx;
								margin-left: 8rpx;
							}
						}

						.price {
							display: flex;
							align-items: center;
							font-family: Tahoma-Bold, Tahoma;
							font-weight: bold;
							background: linear-gradient(180deg, #69FF60 0%, #0C9D5B 100%);
							-webkit-background-clip: text;
							-webkit-text-fill-color: transparent;

							>view:first-child {
								font-size: 40rpx;
							}

							>view:last-child {
								font-size: 40rpx;
								font-weight: bold;
							}
						}
					}

					.list-prc {
						color: #fff;
						font-size: 24rpx;
						display: flex;
						justify-content: space-between;
						align-items: flex-end;
						padding-bottom: 30rpx;

						>view:first-child {
							font-weight: 500;
							display: flex;

							>view:last-child {
								margin-left: 8rpx;

							}
						}

						>view:last-child {
							font-size: 40rpx;
							font-family: Tahoma-Bold, Tahoma;
							font-weight: bold;
							background: linear-gradient(180deg, #69FF60 0%, #0C9D5B 100%);
							-webkit-background-clip: text;
							-webkit-text-fill-color: transparent;

						}

					}

				}
			}
		}
	}



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

	.sell {
		.title {
			margin: 40rpx 25rpx;

			image {
				width: 268rpx;
				height: 54rpx;
			}

			view {
				font-size: 28rpx;
				color: #000;
				// width: 100rpx;
				height: 52rpx;
				background: #21E4F0;
				border-radius: 74rpx;
				text-align: center;
				line-height: 52rpx;
				padding: 0 20rpx;
			}
		}

		.item {
			// margin: 0 25rpx;
			width: 686rpx;
			margin: auto;


			.hed {
				height: 80rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #000000;
				background: #fff;
				border-radius: 20rpx 20rpx 0 0;
				padding: 0 20rpx;

				view:last-child {
					display: flex;
					align-items: center;

					image {
						width: 28rpx;
						height: 28rpx;
						margin-right: 10rpx;
					}
				}

			}

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

			.ctx {
				display: flex;
				flex-direction: column;
				background: #fff;
				margin-bottom: 30rpx;
				margin-top: 48rpx;
				border: 1px solid #EFEFEF;
				border-radius: 48rpx;
				width: 686rpx;
				overflow: hidden;

				.ctx-img {
					image {
						width: 686rpx;
						height: 268rpx;
						border-radius: 48rpx;
					}
				}

				.ctx-txt {
					width: 100%;
					padding-left: 30rpx;
					background: url(/static/index/024.png) no-repeat;
					background-size: 100% 100%;
					width: 686rpx;
					padding-bottom: 32rpx;


					view:nth-child(1) {
						font-size: 36rpx;
						color: #000000;
						margin-top: 32rpx;
						font-weight: 600;
					}

					view:nth-child(2) {
						font-size: 24rpx;
						color: #353535;
						margin-top: 24rpx;
					}
				}

			}
		}

	}

	.head_bar {
		display: flex;
		height: 88rpx;
		font-weight: 400;
		color: #999999;
		font-size: 32rpx;
		padding: 0 32rpx;
		align-items: center;
		margin: 32rpx 0 16rpx;

		.syColor {
			color: #fff;
			font-weight: bold;
			font-size: 32rpx;
		}
	}





	.imageji {
		// width: 100%;
		margin: 34rpx 0 0 32rpx;

		image {
			width: 290rpx;
			height: 182rpx;
		}
	}

	.sw-dot {
		margin-top: 30rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-bottom: 10rpx;
	}

	.sw-dot .dot {
		width: 16rpx;
		height: 16rpx;
		border-radius: 50%;
		background: #21E4F0;
		margin-left: 10rpx;
		opacity: 0.4;
	}

	.sw-dot .active {
		background: #21E4F0;
		opacity: 1;
	}

	.menu {
		width: 650rpx;
		margin-top: 20rpx;
	}




	.head_bar>view {
		margin-left: 56rpx;
	}

	.head_bar>view:first-child {
		margin-left: 20rpx;
	}

	/* 	.head_bar>view:last-child{
		margin-left: auto;
		margin-right: 20rpx;
		align-self: center;
	} */


	.checked_text {
		font-size: 52rpx;
		color: #000;
	}

	.magnifierbox {
		display: flex;
	}

	.magnifierbox>image {
		display: block;
		align-self: center;
	}






	.invite {
		display: flex;
		justify-content: space-between;
		padding: 0 10rpx;

		.inv {
			width: 54%;
			height: 106rpx;
			margin: 0 10rpx;
			border-radius: 16rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			background: #29D0DC;

			image {
				width: 80rpx;
				height: 80rpx;

			}

			view {
				font-size: 32rpx;
				color: #fff;
			}
		}

		.inv:last-child {
			background: #FD9F59;

		}

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


	.list_content {
		padding: 0 20rpx;
		margin: 24rpx auto;
		margin-bottom: 0;
	}

	.list {
		background: #fff;
		border-radius: 16rpx;
		box-sizing: border-box;
		margin: 28rpx auto;
		margin-bottom: 0;
		overflow: hidden;
		z-index: 6666;
		padding-bottom: 20rpx;
		box-shadow: 0px 1px 6px 1px rgba(0, 0, 0, 0.09803921568627451);
	}

	.img {
		width: 100%;
		position: relative;
		box-sizing: border-box;
		overflow: hidden;
	}

	.img image {
		width: 100%;
		height: 940rpx;
		border-radius: 16rpx;
		overflow: hidden;
	}

	.status {
		/* width: 124rpx; */
		height: 50rpx;
		background: rgba(0, 0, 0, .6);
		border-radius: 40rpx;
		position: absolute;
		left: 30rpx;
		top: 30rpx;
		z-index: 1;
		letter-spacing: 4rpx;
		font-size: 24rpx;
		line-height: 50rpx;
		text-align: center;
		display: flex;
		align-items: center;
		padding: 0 20rpx;
		color: #F2E0BC;

		&::before {
			content: "";
			width: 20rpx;
			height: 20rpx;
			border-radius: 50%;
			background: #F2E0BC;
			display: inline-block;
			z-index: 666;
			margin-right: 15rpx;
		}
	}

	.list_title {
		margin-top: 32rpx;
		letter-spacing: 4rpx;
		font-size: 32rpx;
		font-family: Segoe UI-Semibold, Segoe UI;
		font-weight: 600;
		color: #000000;
		padding: 0 20rpx;
	}

	.num_box {
		margin-top: 25rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 20rpx;
	}

	.num {
		height: 40rpx;
		display: flex;
		font-size: 26rpx;
		text-align: center;
		line-height: 46rpx;

	}

	.num>view:first-child {
		background: #000;
		width: 72rpx;
		height: 40rpx;
		line-height: 40rpx;
		font-size: 26rpx;
		border-radius: 5rpx;
		overflow: hidden;
	}

	.num>view:last-child {
		height: 40rpx;
		line-height: 40rpx;
		background: #fcf8f2;
		color: #fff;
		padding: 0 15rpx;
		border-radius: 5rpx;
		overflow: hidden;
	}






	.boxList {
		margin: 44rpx auto;
	}

	.boxItem {
		width: 710rpx;
		height: 910rpx;
		/* background: linear-gradient(134deg, #FFFFFF 0%, #2B2B2B 100%); */
		border-radius: 16rpx;
		margin: 0 auto 28rpx auto;
		display: flex;
		justify-content: flex-end;
		background: #fff;
	}

	.boxItem>view {
		align-self: center;
		width: 706rpx;
		height: 902rpx;
		/* background: #1c1c1e; */
		border-radius: 16rpx;
	}

	.boxItem>view {
		display: flex;
		flex-direction: column;
	}

	.boxItem>view>view:last-child {
		box-sizing: border-box;
		padding-left: 30rpx;
		padding-top: 22rpx;
		width: 100%;
	}

	.boxItem>view>view>view:first-child {
		font-size: 32rpx;
		color: #000000;
		font-weight: bold;
	}

	/* 	.boxItem>view>view>view:nth-child(2) {
		width: 64rpx;
		height: 44rpx;
		background: #000;
		text-align: center;
		line-height: 44rpx;
		font-size: 24rpx;
		font-weight: 400;
		border: 1px solid #FFFFFF;
		margin-top: 24rpx;
	} */

	.boxItem>view>view>view:nth-child(3) {
		letter-spacing: 2rpx;
		font-size: 24rpx;
		margin-top: 22rpx;
	}

	.box_price {
		width: 100%;
		text-align: right;
		/* color: #000000; */
		box-sizing: border-box;
		padding-right: 30rpx;
		font-size: 50rpx;
	}


	.statAs {
		height: 60rpx;
		position: absolute;
		left: 80rpx;
		top: 180rpx;
		z-index: 1;
		letter-spacing: 4rpx;
		font-size: 36rpx;
		line-height: 50rpx;
		text-align: center;
		display: flex;
		padding: 0 40rpx;
		background: rgba(0, 0, 0, .5);
		color: #fff;
		transform: rotate(-20deg);
	}
</style>