<template>
	<view class="container">
		<view class="jx-box-content" v-for="(item, index) in list">
			<view class="content-left"><image :src="item.image" mode=""></image></view>
			<view class="content-right">
				<view class="shop-name">{{ item.store_name }}</view>
				<view class="shop-content">
					<view class="shop-content-left">
						<view class="price-box">
							<view class="yuan-price">￥{{ item.ot_price * 1 }}</view>
							<image src="../../static/sy/sy06.png" mode=""></image>
							<view class="j-price">直降{{ (item.ot_price - item.price).toFixed(2) * 1 }}元</view>
						</view>
						<view class="price-x">￥{{ item.price * 1 }}</view>
					</view>
					<view class="shop-content-right" @click="navToDetailPage(item)">购买</view>
				</view>
			</view>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>
	</view>
</template>

<script>
import { getProducts } from '@/api/product.js';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
import empty from '@/components/empty';
export default {
	data() {
		return {
			list: [],
			page: 1,
			limit: 10,
			loadingType: 'more'
		};
	},
	components: {
		empty,
		uniLoadMore
	},
	onLoad(option) {
		// 获取查询对象
		this.type = option.type;
		// 加载基础数据
		this.loadData();
	},
	onReachBottom() {
		this.loadData();
	},
	methods: {
		navTo: function(ls) {
			uni.navigateTo({
				url: '/pages/product/product?id=' + ls.id
			});
		},
		// 请求载入数据
		async loadData() {
			let obj = this;
			if (this.loadingType == 'noMore' || this.loadingType == 'loading') {
				return;
			}
			this.loadingType = 'loading';
			getProducts({
				page: obj.page,
				limit: obj.limit,
				cid: 52
			})
				.then(({ data }) => {
					// 保存商品信息
					this.list = data;
					if (data.limit == obj.limit) {
						obj.loadingType = 'more';
						obj.page++;
					} else {
						obj.loadingType = 'noMore';
					}
				})
				.catch(e => {
					console.log(e);
				});
		},
		navToDetailPage(item) {
			let id = item.id;
			uni.navigateTo({
				url: '/pages/product/product?id=' + id + '&isVip=1'
			});
		},
		// 轮播图跳转
		bannerNavToUrl(item) {
			// #ifdef H5
			if (item.wap_link.indexOf('http') > 0) {
				window.location.href = item.wap_link;
			}
			// #endif
			if (item.wap_link) {
				uni.navigateTo({
					url: item.wap_link
				});
			}
		}
	}
};
</script>

<style lang="scss">
page {
	background: #fff;
}
.jx-box-content {
	margin: 20rpx auto 0;
	display: flex;
	width: 710rpx;
	background: #ffffff;
	box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
	border-radius: 10rpx;
	padding: 20rpx 30rpx 20rpx 14rpx;
	.content-left {
		flex-shrink: 0;
		width: 236rpx;
		height: 236rpx;
		background: #e2e2e2;
		border-radius: 10rpx;
		image {
			width: 100%;
			height: 100%;
		}
	}

	.content-right {
		width: 100%;
		margin-left: 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-around;

		.shop-name {
			width: 382rpx;
			font-size: 32rpx;
			font-weight: bold;
			color: #333333;

			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 2;
		}

		.shop-content {
			display: flex;
			justify-content: space-between;

			.shop-content-left {
				display: flex;
				flex-direction: column;

				.price-box {
					display: flex;
					align-items: center;
					.yuan-price {
						font-size: 26rpx;
						font-weight: 500;
						text-decoration: line-through;
						color: #999999;
					}

					image {
						margin-left: 8rpx;
						width: 16rpx;
						height: 18rpx;
					}

					.j-price {
						margin-left: 8rpx;
						font-size: 24rpx;
						font-weight: bold;
						color: #b59467;
					}
				}

				.price-x {
					font-size: 36rpx;
					font-weight: bold;
					color: #ff4c4c;
				}
			}

			.shop-content-right {
				margin-top: 20rpx;
				align-items: center;
				text-align: center;
				width: 137rpx;
				height: 52rpx;
				font-size: 26rpx;
				font-weight: 500;
				color: #ffffff;
				background: linear-gradient(90deg, #bb9159, #e6c79d);
				border-radius: 26rpx;
				line-height: 52rpx;
			}
		}
	}
}
</style>
