<template>
	<view class="content">
		<!-- <view class="status_bar"></view> -->
		<view class="hotgoods">
			<view class="hotgoods-item" v-for="jfitem in list" :key="jfitem.id"
				@click="navto('/pages/product/product?id=' + jfitem.id )" style="height: 520rpx;">
				<view class="image-wrapper">
					<image class="image" :src="jfitem.image" mode="scaleToFill"></image>
				</view>
				<view class="flex" style="flex-direction: column;justify-content: space-between;align-items: flex-start;height: 170rpx;">
					<view class="title clamp2">{{jfitem.store_name}}</view>
					<view class="hot-price">
						<view class="price">
							<text>￥{{ jfitem.price * 1 }}</text>
							<text class="ot-pirce" >销量：{{jfitem.sales}}</text>
						</view>
					</view>
				</view>
				
			</view>
		</view>
		<empty v-if="loaded && list.length == 0"></empty>
		<uni-load-more :status="loadingType" v-if="!(loaded && list.length == 0)"></uni-load-more>
	</view>
</template>

<script>
	import empty from '@/components/empty.vue'
	import { getCate,getGoodList} from '@/api/three.js'
	import { getProducts } from '@/api/product.js'
	
	export default {
		components: {
			empty
		},
		data() {
			return {
				cid: '',
				sid: '',
				list: [],
				page:1,
				limit: 10,
				loaded:false,
				loadingType: 'more',
				keyword: '',
				is_one: 0,
			}
		},
		onLoad(opt) {
			if(opt.is_one) {
				this.is_one = opt.is_one
			}
			if(opt.cid) {
				this.cid = opt.cid
			}
			if(opt.sid) {
				this.sid = opt.sid
			}
			this.getGoodList()
		},
		onShow() {
		},
		onReachBottom() {
			this.getGoodList()
		},
		onReady() {
			
		},
		methods: {
			navto(url) {
				uni.navigateTo({
					url,
					fail() {
						uni.switchTab({
							url
						})
					}
				})
			},
			goIndex() {
				uni.switchTab({
					url:'/pages/index/index'
				})
			},
			clickSearch() {
				
			},
			getCate() {
				getCate({
				id: 0
			}).then(res => {
					
				})
			},
			getGoodList(type) {
				let that = this
				if(type == 're') {
					that.list = []
					that.page = 1
					that.loadingType = 'more'
				}
				if(that.loadingType == 'loading' || that.loadingType == 'noMore') {
					return
				}
				that.loadingType = 'loading'
				getProducts({
					is_level: that.is_level,
					page: that.page,
					limit: that.limit,
					is_one: that.is_one,
					cid: that.cid,
					sid: that.sid
				}).then(res => {
					console.log(res)
					let arr =res.data
					if(arr) {
						that.list = that.list.concat(arr)
						if(arr.length == that.limit) {
							that.loadingType = 'more'
							that.page++
						}else {
							that.loadingType = 'noMore'
						}
					}else {
						that.loadingType = 'noMore'
					}
					
					that.loaded = true
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.hotgoods {
		// margin-top: 38rpx;
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		padding: 20rpx 20rpx 30rpx;
		justify-content: space-between;
	
		.hotgoods-item {
			width: 345rpx;
			background-color: #ffffff;
			border-radius: 12rpx;
			box-shadow: 0 0 15rpx rgba(0, 0, 0, 0.2);
			margin-bottom: 15rpx;
	
			.image-wrapper {
				width: 345rpx;
				height: 345rpx;
				border-radius: 3px;
				overflow: hidden;
				position: relative;
	
				.image-bg {
					position: absolute;
					top: 0;
					left: 0;
					right: 0;
					bottom: 0;
					width: 100%;
					height: 100%;
					opacity: 1;
					border-radius: 12rpx 12rpx 0 0;
					z-index: 2;
				}
	
				.image {
					width: 100%;
					height: 100%;
					opacity: 1;
					border-radius: 12rpx 12rpx 0 0;
				}
			}
	
			.title {
				margin-top: 24rpx;
				padding: 0 20rpx;
				font-size: 32rpx;
				font-weight: 500;
				color: #333333;
			}
	
			.hot-price {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				width: 100%;
				padding: 0 10rpx;
				// padding: 14rpx 0 30rpx;
	
				.hotPrice-box {
					padding: 2rpx 6rpx;
	
					background: linear-gradient(90deg, #c79a4c, #f9df7f);
					border-radius: 5rpx;
					text-align: center;
					line-height: 28rpx;
					font-size: 20rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #ffffff;
				}
	
				.price {
					margin-left: 10rpx;
					font-size: 36rpx;
					color: #ff0000;
					font-weight: 500;
					display: flex;
					width: 100%;
					justify-content: space-between !important;
					align-items: center;
					.jf {
						font-size: 20rpx;
					}
					.give-jf {
						display: inline-block;
						padding: 8rpx;
						
						background: linear-gradient(90deg, #FF834D, #FF2600);
						border-radius: 12rpx 0px 12rpx 0px;
						
						font-size: 22rpx;
						font-weight: 500;
						color: #FFFFFF;
						margin-left: 22rpx;
					}
					.ot-pirce {
						margin-left: 7rpx;
						font-size: 26rpx;
						font-weight: 500;
						// text-decoration: line-through;
						color: #999999;
						align-self: flex-end;
					}
					
				}
	
				.yuanPrice {
					margin-left: 10rpx;
					font-size: 20rpx;
					font-family: PingFang SC;
					font-weight: 500;
					text-decoration: line-through;
					color: #999999;
				}
	
				.cart-icon {
					image {
						width: 44rpx;
						height: 44rpx;
					}
				}
			}
		}
	}
	.status_bar {
	        height: var(--status-bar-height);
			background-color: #fff;
	        width: 100%;
			position: fixed;
			top: 0;
			z-index: 999;
	    }
</style>