<template>
	<view class="">
		<empty v-if="loaded && goodList.length == 0"></empty>
		<view class="hot-list">
			<view class="hotgoods-item" v-for="jfitem in goodList" :key="jfitem.id"
				@click="navto('/pages/product/product?id=' + jfitem.id)" style="height: 490rpx;">
				<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: 120rpx;">
					<view class="title clamp">{{jfitem.store_name}}</view>
					<view class="hot-price">
						<view class="price">
							<text>￥{{ jfitem.price * 1 }}</text>
							<text class="ot-pirce" v-if="jfitem.ot_price*1 >jfitem.price * 1 ">￥{{jfitem.ot_price}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-load-more :status="loadingType" v-if="!(loaded && goodList.length == 0)"></uni-load-more>
	</view>
</template>

<script>
	// #ifdef H5
	import {
		weixindata,
		shareLoad
	} from '@/utils/wxAuthorized';
	// #endif
	import empty from '@/components/empty.vue'
	import {
		getBargainList,
		getProducts,
		goodsDetail,
		poster,
		getBd,
		getGp,
		groomList
	} from '@/api/product.js';
	export default {
		components: {
			empty
		},
		data() {
			return {
				goodList: [], //商品列表
				loadingType: 'more',
				page: 1,
				limit: 10,
				type: 0,
				loaded: false,
				cid: 0
			}
		},
		onLoad(opt) {
			if (opt.id) {
				this.cid = opt.id
				uni.setNavigationBarTitle({
					title: opt.tit
				})
			}
			this.getGoodList()
			// #ifdef H5
			this.shareDate()
			// #endif
		},
		onShow() {

		},
		onReachBottom() {
			this.getGoodList()
		},
		onPullDownRefresh() {
			this.getGoodList('down')
		},
		methods: {
			// #ifdef H5
			// 加载微信html5页面分享方法
			shareDate() {
				// let obj = this;
				// 保存分享人id链接
				// let url = window.location.href + '&spread=' + this.userInfo.uid;
				// 判断是否微信浏览器
				// let bool = uni.getStorageSync('weichatBrowser') || '';
				// if (bool) {
				// 	// 过滤微信强制添加的链接地址
				// 	url = url.replace(/[\?,&]from=singlemessage/g, '');
				// }
				shareLoad();
			},
			// #endif
			navto(url) {
				uni.navigateTo({
					url,
					fail() {
						uni.switchTab({
							url
						})
					}
				})

			},
			getGoodList(type) {
				let obj = this
				if (type == 'down') {
					obj.loadingType = 'more'
					obj.page = 1
				}
				if (obj.loadingType == 'loading' || obj.loadingType == 'noMore') {
					return
				}
				obj.loadingType = 'loading'
				getProducts({
					page: obj.page,
					limit: obj.limit,
					cid: obj.cid
				}).then(res => {
					if (type == 'down') {
						obj.goodList = []
						uni.stopPullDownRefresh();
					}
					obj.goodList = obj.goodList.concat(res.data)
					if (obj.limit == res.data.length) {
						obj.loadingType = 'more'
						obj.page++
					} else {
						obj.loadingType = 'noMore'
					}
					obj.loaded = true

				}).catch(err => {
					obj.loadingType = 'more'
					uni.stopPullDownRefresh();
				})

			},
		}
	}
</script>

<style lang="scss" scoped>
	.hot-list {
		// 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: flex-start;
					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;
					}
				}
			}
		}
	}

	.goodss {
		border-radius: 0rpx 0rpx 20rpx 20rpx;
		box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
		margin-bottom: 20rpx;
		padding-bottom: 20rpx;

		&:last-of-type {
			margin-bottom: 0;
		}

		.goods-img {
			position: relative;
			width: 702rpx;
			height: 303rpx;

			image {
				width: 702rpx;
				height: 303rpx;
			}

			.img-bg {
				position: absolute;
				top: 0;
				left: 0;
			}

		}

		.goods-tit {
			font-weight: 500;
			font-size: 32rpx;
			color: #333333;
			padding: 15rpx 20rpx;
		}

		.goods-price {
			display: flex;
			padding: 0 20rpx;

			.new-price {
				font-weight: bold;
				font-size: 32rpx;
				color: #FF4C4C;
			}

			.tc {
				flex-grow: 1;
			}

			.ot-pirce {
				font-weight: 500;
				font-size: 26rpx;
				color: #999999;
				text-decoration-line: line-through;
			}

			.gobuy {
				display: inline-block;
				width: 170rpx;
				line-height: 53rpx;
				background: linear-gradient(30deg, #FF4C4C, #FE6238);
				border-radius: 27rpx;
				text-align: center;
				font-weight: bold;
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}
	}
</style>