<template>
	<view :class="[AppTheme]" class="all_box"> 
		<swiper class="swiper_item"  >
			<swiper-item v-for="(item, index) in swimglist" :key="index" @touchmove.stop="stopTouchMove">
				<scroll-view class="scroll_bar" :refresher-enabled="true" :refresher-triggered="triggered"
						@refresherrefresh="refresh" scroll-y @scrolltolower="expandbottom">
					<!-- 商品列表 -->
					<view class="commodity_list" v-if="commoditylist&&type==1">

						<view class="content_box" @click="goadopt(0,item)" v-for="(item,index2) in commoditylist"
							:key="index2">
							<u--image :src=" item.pic" radius="10rpx" width="355rpx" height="340rpx" :lazy-load="true"
								:fade="true" duration="450">
								<template v-slot:loading>
									<u-loading-icon color="red"></u-loading-icon>
								</template>
							</u--image>
							<view class="message">
								<p class="tltile">{{ item.name }}</p>
								<view class="message_bot">
									<view class="f_left">
										<p class="color_org  text-neutral">{{ item.price }}元/{{ item.unit }}</p>
										<p class="old_price">原价：{{ item.oprice }}元</p>
									</view>
									<view class="f_right"  >
										<u-icon size="40" :color="primary" name="shopping-cart-fill"></u-icon>
									</view>
								</view>
							</view>
						</view>
					</view>
					<!-- 土地列表 -->
					<view class="land_list" v-if="commoditylist&&type==2">
						<view class="land_item" @click="goadopt(1,item)" v-for="(item,index2) in commoditylist"
							:key="index2">
							<image class="land_item_thumbnail"  :src="item.soil_cover_pic"></image>
							<view class="commodity_item_title">{{item.soil_name}}</view>
							<view class="commodity_item_introduce">{{item.soil_desc}}</view>
							<view class="commodity_item_flex">
								<view class="commodity_item_flex_p1"><text
										class="side_text">价格:</text>￥{{item.show_price}}<text
										class="side_text">元起</text></view>
								<button class="commodity_item_flex_btn bg-linear-gradient" type="default">选择土地</button>
							</view>
						</view>
					</view>
					<!-- 认养列表 -->
					<view class="adopt_list" v-if="commoditylist&&type==3">
						<view class="adopt" @click="goadopt(2,item)" v-for="(item,index2) in commoditylist"
							:key="index2">
							<image class="adopt_img" :src="item.pic">
							</image>
							<view class="adopt_content">
								<view class="adopt_content_title">{{item.name}}</view>
								<view class="adopt_content_reward">收获:{{item.bonusway}}</view>
								<view class="adopt_content_p1">
									<view class="adopt_content_sold">已售:
										<text class="adopt_content_sold_text text-primary">{{item.sells}}%</text>
									</view>
									<view class="">剩余:
										<text class="adopt_content_sold_text text-primary">{{item.num}}</text>
									</view>
								</view>
								<u-line-progress :percentage="item.sells" :active-color="primary"></u-line-progress>
								<!-- 	<u-line-progress  :active-color="primary" :percent="30">
								</u-line-progress> -->
								<view class="adopt_content_p2">
									<view class="price text-neutral">¥{{item.copies_price}}</view>
									<view v-if="item.status==1" class="btn bg-linear-gradient">销售中</view>
									<view v-if="item.status==2" class="btn3">卖完了</view>
									<view v-if="item.status==3" class="btn3">已到期</view>
								</view>
							</view>
						</view>
					</view>
					<!-- 监控列表 -->
					<view class="monitor_list" v-if="commoditylist&&type==4">
						<view class="monitor" @click="goadopt(3,item)" v-for="(item,index2) in commoditylist"
							:key="index2">
							<view class="playimage">
								<image class="monitor_img" :src="item.pic"></image>
								<image :src="settingFile.root_img+'/static/app/yfs-video/play.png'" class="play_circle"
									mode=""></image>
							</view>
							<view class="monitor_title">{{item.title}}</view>
						</view>
					</view>
					<!-- 活动列表 -->
					<view class="land_list" v-if="commoditylist&&type==5">
						<view class="land_item" @click="goadopt(4,item)" v-for="(item,index2) in commoditylist"
							:key="index2">
							<image class="land_item_thumbnail" mode="scaleToFill" :src="item.activity_img"></image>
							<view class="commodity_item_title">{{item.activity_title}}</view>
							<view class="activity_information_p0 text-neutral">¥{{item.child_fares}} ~
								¥{{item.adult_fares}}</view>
							<view class="activity_information_p1">{{item.start_time}} - {{item.end_time}}</view>
							  <view class="activity_information_p2">活动人数:已报名18人</view>
					 	</view>
					</view>  
					<u-loadmore v-if="commoditylist&&commoditylist.length!==0" margin-bottom="20" :line="true"
						:status="loadmore" />
					<view class="bottom_hint" v-if="!commoditylist||commoditylist.length==0">
						<u-empty text="暂无记录" mode="data"></u-empty>
					</view>
				</scroll-view>
			</swiper-item>
		</swiper>
		<!-- 分享 -->
		<sharebox ref="sbox" v-if="sharedata" :data="sharedata"></sharebox>
	</view>
</template>
<script>
	import mineApi from "@/api/mine/index.js"
	export default {
		components: {},
		data() {
			return {
				_freshing: false,
				triggered: true,
				primary: this.$theme.primary,
				sharedata: null,
				settingFile: getApp().globalData.siteinfo,
				// settingFile: this.$siteinfo,
				btnstatus: 2,
				loadmore: '',
			  
				// 因为内部的滑动机制限制，请将tabs组件和swiper组件的current用不同变量赋值
				couponlist: [],
				// tabs组件的current值，表示当前活动的tab选项
				current: 0,
				// swiper组件的current值，表示当前那个swiper-item是活动的
				swiperCurrent: 0,
				//轮播图数组
				swimglist: [1, 2, 3, 4, 5],
				farm_id: '', //农场id
				page: 1, //列表分页
				commoditylist: [], //列表
				timename: '',
				farm_info: {}, //农场信息
				type:'',
			}
		},
		onLoad(options) {
			this.type=options.type
			this.farm_id = options.farm_id
			this.getshopdetails()
		},
		onShareAppMessage(res) {
			let that = this
			let data = {
				title: that.sharedata.title,
				imageUrl: that.sharedata.imageUrl,
				path: that.sharedata.path
			};
			return data;
		},
		onShareTimeline(res) {
			let that = this
			return {
				title: that.sharedata.title,
				imageUrl: that.sharedata.imageUrl,
				path: that.sharedata.path
			}
		},
		methods: {
			 
			goadopt(type, item) { //跳转详情
				if (type == 0) {
					uni.navigateTo({
						url: "/pagesD/pages/product/product?id=" + item.id
					})
				} else if (type == 1) {
					uni.navigateTo({
						url: "/pagesB/pages/chooseland/chooseland?landid=" + item.id
					})
				} else if (type == 2) {
					uni.navigateTo({
						url: "/pagesA/pages/adopt/adopt?id=" + item.id
					})
				} else if (type == 3) {
					console.log(item, "shipin")
					if (item.jumptype == 'webview') {
						let ad_link = encodeURIComponent(JSON.stringify(item.src));
						uni.navigateTo({
							url: '/pagesE/pages/showhfive/showhfive?url=' + ad_link
						})
					} else {
						uni.navigateTo({
							url: `/pagesE/pages/broadcast/transmit?id=${item.id}`
						})
					}
				} else if (type == 4) {
					uni.navigateTo({
						url: "/pagesB/pages/activitydetails/activitydetails?id=" + item.id
					})
				}
			},
			getshopdetails() { //获取店铺详情
				this.loadmore = 'loading'
				mineApi.farmshoplist({
						farm_id: this.farm_id,
						item_type:this.type,
						p: this.page
					})
					.then(res => {
						if (res.status == 1) {
							console.log(res, "商家详情")
							res.data.forEach(ele => {
								this.commoditylist.push(ele)
								console.log(ele, "ele")
							})
							if (res.data.length < 10) {
								this.loadmore = "nomore"
							} else {
								this.loadmore = "loadmore"
							}
						 
						} else {
							this.page--
							this.loadmore = "nomore"
						}
					})
			},
			expandbottom() { //上拉加载分页
				this.page++
				this.getshopdetails()
			},
			 refresh() { //自定义下拉刷新
			 	console.log('下拉刷新了')
			 	if (this._freshing) return;
			 	this._freshing = true;
			 
			 	//调用获取数据的函数
			 	// this.getData();
			 	if (!this.triggered)
			 		//界面下拉触发，triggered可能不是true，要设为true
			 		this.triggered = true;
			 	setTimeout(() => {
			 		this.triggered = false;
			 		this._freshing = false;
			 		uni.stopPullDownRefresh()
			 	}, 2000);
			 },
			 
		}
	}
</script>
<style lang="scss" scoped>
	.all_box {
		width: auto;
		background-color: #FFFFFF;
		min-height: 100vh;

		.shop_name {
			height: 120rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 15rpx;
			background-color: #FFFFFF;

			.shop_thumbnail {
				width: 90rpx;
				height: 90rpx;
				border-radius: 7.5%;
			}

			.right_shop_mess {
				width: calc(100% - 100rpx);

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

					.shop_one {
						display: flex;
					}

					.shop_line_p1 {
						margin-top: 25rpx;
						color: #000;
						padding-left: 5rpx;
						font-size: 32rpx;
						font-weight: 700;
					}

					.shop_line_p2 {
						display: flex;
						align-items: center;
						width: 100%;
						// margin-top: 20rpx;

						.address {
							color: #333;
							font-size: 26rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
					}

					.right_shop_mess_p2 {
						// padding: 10rpx ;
						height: 50rpx;
						line-height: 50rpx;
						font-size: 30rpx;
						border-radius: 30rpx 0 0 30rpx;
						color: #fff;
					}
				}

				.shop_line_fl {
					display: flex;
					justify-content: flex-start;
					align-items: center;
					margin: 20rpx 0 15rpx 0;
					font-size: 26rpx;
					color: #999999;

					.shop_one_1 {}

					.shop_one_2 {
						padding: 0 0 0 20rpx;
					}

					.shop_one_3 {
						padding: 0 0 0 20rpx;
					}
				}

			}
		}

		.swiper_item {
			height: calc(100vh - 0px);

			.scroll_bar {
				height: 100%;
				background-color: #fff;

				.commodity_list {
					display: flex;
					flex-wrap: wrap;
					padding: 0 15upx;
					background: #fff;
					padding: 15rpx;
					justify-content: space-between;

					.commodity_item {
						width: 330rpx;
						border-radius: 40rpx;
						margin: 20rpx calc(25% - 170rpx);
						padding: 0 0 25rpx 0;
						background-color: #FFFFFF;
						overflow: hidden;

						.commodity_item_thumbnail {
							width: 340rpx;
							height: 365rpx;
							// border-radius: 20rpx  20rpx 0 0;
						}
					}
				}

				.land_list {
					.land_item {
						margin: 25rpx 35rpx;
						box-shadow: 2px 4px 12px rgba(0, 0, 0, 0.08);
						padding: 0 0 25rpx 0;
						border-radius: 3.5%;
						background-color: #FFFFFF;
                        
						.land_item_thumbnail {
							width: 100%;
							height: 26vh;
						 
							border-radius: 3.5% 3.5% 0 0;
						}
					}
				}

				.bottom_hint {
					margin-top: 100rpx;
				}

				.monitor_list {
					display: flex;
					justify-content: space-around;
					align-items: center;

					.monitor {
						margin: 20rpx 10rpx;
						text-align: center;

						.playimage {
							position: relative;
							width: 230rpx;
							height: 230rpx;

							.monitor_img {
								width: 230rpx;
								height: 200rpx;
							}

							.play_circle {
								width: 55rpx;
								height: 55rpx;
								position: absolute;
								top: 50%;
								left: 50%;
								transform: translate(-50%, -50%);
							}
						}

						.monitor_title {
							margin-top: 20rpx;
						}
					}
				}

				.adopt_list {
					.adopt {
						display: flex;
						justify-content: flex-start;
						align-items: center;
						margin: 20rpx;
						border-bottom: 2rpx solid #C0C4CC;

						.adopt_img {
							width: 300rpx;
							height: 200rpx;
						}

						.adopt_content {
							width: 100%;
							margin-left: 30rpx;

							.adopt_content_title {
								font-size: 30rpx;
								line-height: 50rpx;
							}

							.adopt_content_reward {
								font-size: 24rpx;
								color: red;
								line-height: 35rpx;
							}

							.adopt_content_p1 {
								margin: 15rpx 0;
								font-size: 27rpx;
								display: flex;
								justify-content: flex-start;
								align-items: center;

								.adopt_content_sold {
									margin-right: 50rpx;
								}
							}

							.adopt_content_p2 {
								display: flex;
								justify-content: space-between;
								align-items: center;
								margin: 15rpx 0;
								font-size: 30rpx;
								color: #56ab2f;

								.btn {
									color: #fff;
									padding: 10rpx 20rpx;
									border-radius: 20rpx;
									font-size: 20rpx;
								}

								.btn2 {
									color: #fff;
									padding: 10rpx 20rpx;
									border-radius: 20rpx;
									font-size: 20rpx;
								}

								.btn3 {
									color: #fff;
									background-color: #999999;
									padding: 10rpx 20rpx;
									border-radius: 20rpx;
									font-size: 20rpx;
								}

							}

						}
					}
				}

				.commodity_item_title {
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					font-size: 28rpx;
					color: #000000;
					line-height: 60rpx;
					padding: 0 20rpx;
				}

				.commodity_item_introduce {
					font-size: 26rpx;
					color: #666;
					padding: 0 20rpx;
					margin-bottom: 25rpx;
				}

				.commodity_item_flex {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 0 20rpx;

					.commodity_item_flex_p1 {
						font-size: 28rpx;
						font-weight: 700;
						color: red;

						text {
							display: inline-block;
						}

						.side_text {
							font-size: 25rpx;
							color: #222;
						}

						.discount_price {
							font-size: 24rpx;
							color: #666;
							font-style: oblique;
							text-decoration: line-through;
						}
					}

					.commodity_item_flex_p2 {
						font-size: 26rpx;
						color: #666;
					}

					.commodity_item_image {
						width: 50rpx;
						height: 50rpx;
					}

					.commodity_item_flex_btn {
						margin-left: 260rpx;
						height: 50rpx;
						border-radius: 25rpx;
						font-size: 25rpx;
						line-height: 50rpx;
						color: #fff;
					}
				}

				.activity_information_p0 {
					margin: 0 20rpx;
				}

				.activity_information_p1 {
					margin: 20rpx 0;
				}

				.activity_information_p1,
				.activity_information_p2 {
					font-size: 26rpx;
					color: #999999;
					padding: 0 20rpx;
				}

				.content_box {
					box-shadow: $box-shadow;
					border-radius: 15rpx;
					width: 355rpx;
					padding-bottom: 10rpx;
					margin-bottom: 10rpx;

					.new-img {
						width: 100%;
						height: 355rpx;
					}

					.message {
						box-sizing: border-box;
						padding: 10rpx;
						line-height: 35rpx;

						.message_bot {
							height: 84rpx;
							margin-top: 20rpx;
							border-top: 0.5rpx solid #fafafa;
							display: flex;
							justify-content: space-between;
							align-items: center;

							.f_left {
								margin-top: 10rpx;
								font-size: 24rpx;

								.color_org {
									margin-top: 10rpx;

								}

								.old_price {
									color: #999;
									margin-top: 10rpx;
									text-decoration: line-through;
								}
							}

							.f_right {
								width: 56rpx;
								height: 56rpx;

								margin-right: 10rpx;
							}
						}
					}
				}
			}
		}
	}

	.yinye {
		display: flex;
		justify-content: flex-end;
		padding: 0 20rpx 10rpx 0;
	}

	.cover-container {
		background: $page-color-base;
		/* #ifdef H5 */
		margin-top: 70rpx;
		/* #endif */
		/* #ifndef H5 */
		margin-top: 50rpx;
		/* #endif */
		padding: 20rpx;
		position: relative;
		background: #f5f5f5;
		padding-bottom: 20upx;

		.arc {
			width: 100%;
			height: 36upx;
		}
	}




	.order-section {
		display: flex;
		padding: 28upx 0;
		justify-content: space-evenly;
		align-items: center;

		.order-item {
			display: flex;
			flex-direction: column;
			align-items: center;

			width: 120upx;
			height: 120upx;
			border-radius: 10upx;
			font-size: $font-sm;
			color: $font-color-dark;

			.yticon {
				width: 90rpx;
				height: 90rpx;
			}
		}

		.yticon {

			margin-bottom: 18upx;
			color: #fa436a;
		}

		.icon-shouhoutuikuan {
			font-size: 44upx;
		}
	}

	.u-page__tag-item {
		margin-right: 20px;

	}

	.warning {
		margin: 10rpx 0;
		// width: 90%;
		border-radius: 20rpx;
		// margin-left: 2.5%;
		display: flex;
		// padding: 20rpx;
	}
</style>
