<template>
	<view class="container">
		<view v-if="isshow == 1">
			<view class="top">
				<view class="vheight"></view>
				<view class="input-box flex">
					<view class="input-content flex">
						<view class="iconfont iconsearch"></view>
						<view class="input"><input type="text" v-model="keyword" placeholder="请输入搜索内容" /></view>
					</view>
					<view class="input-button flex" @click="searchNew"><text>搜索</text></view>
				</view>
			</view>
			<view class="navbar">
				<view class="nav-item" :class="{ current: filterIndex === 0 }" @click="tabClick(0)">综合排序</view>
				<view class="nav-item" :class="{ current: filterIndex === 2 }" @click="tabClick(2)">
					<text>价格</text>
					<view class="p-box">
						<text :class="{ active: priceOrder === 1 && filterIndex === 2 }" class="iconfont iconfold"></text>
						<text :class="{ active: priceOrder === 2 && filterIndex === 2 }" class="iconfont iconfold xia"></text>
					</view>
				</view>
			</view>
			<view class="box">
				<view class="box-title">
					<view class="left">艺绘</view>
					<view class="right" @click="navTo('/pages/index/cangp')">查看更多 ></view>
				</view>
				<view class="box-content" v-for="(item, index) in list" @click="buy(item)">
					<view class="img"><image :src="item.class_info.uri" mode=""></image></view>
					<view class="content-title">
						<view class="title">{{ item.class_info.name }}</view>
						<view class="text">持有者:{{ item.user.nickname }}</view>
						<view class="text">
							价格:
							<span style="font-size: 32rpx; color:#A581FF">￥{{ item.price }}</span>
						</view>
					</view>
				</view>
			</view>
			<view class="btm" style="height: 44px;"></view>
		</view>
		<view class="jqqd" v-else>敬请期待</view>
	</view>
</template>

<script>
import { getBargainList, getProducts } from '@/api/product.js';
import { nftmall, nftDetail } from '@/api/order.js';
// import {mapState} from 'vuex'
import { loadIndexs } from '@/api/index.js';
import { mapState, mapMutations } from 'vuex';
// #ifdef H5
import { weixindata, shareLoad } from '@/utils/wxAuthorized';
// #endif
export default {
	data() {
		return {
			list: [], //卡片信息
			page: 1,
			limit: 10,
			loadType: 'more',
			headerPosition: 'fixed',
			headerTop: '0px',
			filterIndex: 0, //查询类型
			priceOrder: 0, //1 价格从低到高 2价格从高到低
			text: [],
			article: [],
			page: 1,
			limit: 10,
			isshow: 1, //是否显示1显示2敬请期待
			keyword: '' //搜索内容
		};
	},
	computed: {
		...mapState(['loginInterceptor', 'baseURL']),
		...mapState('user', ['hasLogin', 'userInfo'])
	},
	onLoad: function(option) {
		if (this.hasLogin) {
			this.loadIndex();
			// this.getProduct();
		}
	},
	onShow: function() {
		if (this.hasLogin) {
			this.pdshow();
			this.loadIndex();
			// this.getProduct();
		}
	},
	// onReachBottom() {
	// 	this.getproducts();

	// },
	methods: {
		...mapMutations(['setLat', 'setLon']),
		// 判断是否显示
		pdshow() {
			loadIndexs().then(e => {
				if (e.data.market_switch == '1') {
					this.isshow = 1;
				} else {
					this.isshow = 2;
				}
			});
		},
		//市场列表
		loadIndex() {
			let obj = this;
			let data = {
				page: obj.page,
				limit: obj.limit,
				key_word: obj.keyword
			};
			if (obj.filterIndex == 2) {
				if (obj.priceOrder == 1) {
					data.order = 'price_asc';
				} else {
					data.order = 'price_desc';
				}
			}
			nftmall(data).then(res => {
				// console.log(res, 'res');
				obj.list = res.data.list;
				// obj.carouselList = res.data.banner
				// console.log(res,'res');
				// obj.list = res.data.info.fastList
			});
		},
		// 搜索
		searchNew() {
			this.page = 1;
			this.loadIndex();
		},
		getProduct() {
			let obj = this;
			getProducts().then(res => {
				// obj.carouselList = res.data.banner
				// console.log(res,'rrrrrrrrr')
				// 	obj.list = res.list
				// 	console.log(obj.list, 'res');
			});
		},
		buy(item) {
			console.log(item, 'res');
			uni.navigateTo({
				url: '/pages/product/product?id=' + item.id + '&isSc=1'
			});
		},
		navTo(url) {
			uni.switchTab({
				url
			});
		},

		// 點擊搜索框
		clickSearch() {
			uni.navigateTo({
				url: '/pages/product/search'
			});
		},
		//筛选点击
		tabClick(index) {
			// 防止重复点击综合排序
			if (this.filterIndex === 0 && this.filterIndex === index) {
				return;
			}
			this.filterIndex = index;
			// 判断是否为销量优先
			if (index === 1) {
				this.numberOrder = this.numberOrder === 1 ? 2 : 1;
			}
			// 判断是否为价格优先
			if (index === 2) {
				this.priceOrder = this.priceOrder === 1 ? 2 : 1;
			}
			// 初始化页数
			this.page = 1;
			// 初始化数组
			uni.pageScrollTo({
				duration: 300,
				scrollTop: 0
			});
			this.loadIndex();
		},
		swiperChange() {}
	}
};
</script>

<style lang="scss">
page {
	width: 750rpx;
	height: 100%;
	background: #111111;
}
.container {
	/* #ifdef H5 */
	padding-top: 100rpx;
	/* #endif */
	/* #ifdef APP */
	padding-top: calc(100rpx + var(--status-bar-height));
	/* #endif */
}
.top {
	position: fixed;
	z-index: 9999;
	top: 0;
	left: 0;
	width: 100%;
	.top-bg {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		width: 100%;
		height: 100%;
	}

	.top-main {
		position: relative;
		z-index: 2;
		padding: 30rpx;

		.search-box {
			justify-content: center;
			width: 698rpx;
			height: 60rpx;
			background: #191919;

			// box-shadow: 0px 10rpx 20rpx 0px rgba(4, 114, 69, 0.22);
			border-radius: 30rpx;

			.search {
				width: 34rpx;
				height: 34rpx;
			}

			.search-font {
				margin-left: 14rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #a4a4a4;
			}
		}
	}
}

.box {
	margin: 0 30rpx;

	.box-title {
		display: flex;
		justify-content: space-between;

		.left {
			font-size: 38rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #ffffff;
			line-height: 120rpx;
		}

		.right {
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
			line-height: 120rpx;
		}
	}

	.box-content {
		width: 690rpx;
		height: 915rpx;
		margin: 50rpx 0;

		.img {
			width: 690rpx;
			height: 690rpx;

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

		.content-title {
			margin-top: -10rpx;
			padding: 30rpx 20rpx;

			border-bottom-left-radius: 10rpx;
			border-bottom-right-radius: 10rpx;
			border: 2rpx solid #533a6a;
			// box-shadow: 0px 0px 20rpx 0px rgba(79,59,103,0.0600);

			.title {
				font-size: 39rpx;
				font-weight: bold;
				color: #ffffff;
				margin-bottom: 20rpx;
			}

			.text {
				margin: 10rpx 0;
				color: #ffffff;
				font-size: 26rpx;
			}
		}
	}
}

.popup-box {
	width: 522rpx;
	height: 605rpx;
	background-color: #ffffff;
	border-radius: 20rpx;
	position: relative;

	.img {
		position: relative;
		top: -56rpx;
		left: 0;
		width: 522rpx;
		height: 132rpx;
		display: flex;
		justify-content: center;

		image {
			border-radius: 20rpx 20rpx 0 0;
			width: 450rpx;
			height: 132rpx;
		}
	}

	.mian {
		margin-top: -44rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		// padding: 32rpx 32rpx;
		background-color: #ffffff;
		border-radius: 0 0 20rpx 20rpx;
		text-align: center;

		.delivery {
			font-size: 40rpx;
			color: #333333;
			display: flex;
			align-items: center;
			flex-direction: column;

			.title {
			}

			image {
				margin-top: 48rpx;
				width: 172rpx;
				height: 160rpx;
			}
		}

		.nocancel {
			font-size: 32rpx;
			color: #333333;
			margin-top: 14rpx;
		}

		.comfirm-box {
			margin-top: 52rpx;
			display: flex;
			// margin-bottom: 32rpx;

			// justify-content: space-around;
			.cancel {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 197rpx;
				height: 74rpx;
				border: 1px solid #dcc786;
				border-radius: 38rpx;

				font-size: 32rpx;
				color: #605128;
			}

			.comfirm {
				margin-left: 32rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				width: 197rpx;
				height: 74rpx;
				background: linear-gradient(-90deg, #d1ba77 0%, #f7e8ad 100%);
				border-radius: 38px;
				font-size: 32rpx;
				color: #605128;
			}
		}
	}
}

.tongz {
	width: 690rpx;
	height: 70rpx;
	margin: 32rpx auto 0;
	padding: 18rpx 30rpx 18rpx 24rpx;
	align-items: center;
	position: relative;

	.tongz-bg {
		position: absolute;
		top: 0;
		right: 0;
		left: 0;
		width: 690rpx;
		height: 70rpx;

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

	.tongz-left {
		width: 640rpx;

		.image-left {
			width: 28rpx;
			height: 34rpx;
		}

		.tongz-font {
			margin-left: 22rpx;
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #0f253a;
		}
	}

	.tongz-right {
		position: relative;
		z-index: 11;
		width: 12rpx;
		height: 26rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}
}
.vheight {
	height: var(--status-bar-height);
	background-color: #111111;
}
.input-box {
	padding: 25rpx;
	background-color: #111111;
	height: 44px;
	.iconsearch {
		font-size: 50rpx;
	}
	.leftIcon {
		padding-right: 10px;
		.icon {
			width: 20px;
		}
	}
	.input-content {
		border-radius: 99rpx;
		flex-grow: 1;
		padding: 10rpx 30rpx;
		background-color: rgba(231, 231, 231, 0.7);
		.input {
			flex-grow: 1;
			input {
				font-size: $font-lg;
			}
		}
	}
	.input-button {
		padding-left: 20rpx;
		font-size: $font-lg;
		height: 100%;
		color: #ffffff;
	}
}
.navbar {
	display: flex;
	width: 100%;
	height: 80rpx;
	box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.06);
	z-index: 10;
	.nav-item {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
		height: 100%;
		font-size: 30rpx;
		color: #fff;
		position: relative;
		&.current {
			color: #FDD58A;
			&:after {
				content: '';
				position: absolute;
				left: 50%;
				bottom: 0;
				transform: translateX(-50%);
				width: 120rpx;
				height: 0;
				border-bottom: 4rpx solid #FDD58A;
			}
		}
	}
	.p-box {
		display: flex;
		flex-direction: column;
		.iconfont {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 30rpx;
			height: 14rpx;
			line-height: 1;
			margin-left: 4rpx;
			font-size: 26rpx;
			color: #888;
			&.active {
				color: #917bf6;
			}
		}
		.xia {
			transform: scaleY(-1);
		}
	}
	.cate-item {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 100%;
		width: 80rpx;
		position: relative;
		font-size: 44rpx;
		&:after {
			content: '';
			position: absolute;
			left: 0;
			top: 50%;
			transform: translateY(-50%);
			border-left: 1px solid #ddd;
			width: 0;
			height: 36rpx;
		}
	}
}
.jqqd {
	color: #fff;
	text-align: center;
	font-size: 40rpx;
}
</style>
