<template>
	<view :class="[AppTheme]" class="all_box">

		<view class="shop_names ">
			<view class="shop_name">
				<image :src="farm_info.farm_logo" :lazy-load="true" class="shop_thumbnail"></image>
				<view class="right_shop_mess">
					<view class="shop_line">
						<view class="shop_line_p1">
							{{farm_info.farm_name||''}}
						</view>
						<view class="shop_one">
							<view style="padding: 0 20rpx 0 0;">
								<u-icon :name="settingFile.root_img+'/static/app/imgs/shop/phone.png'"
									@click="callPhone()" :color="$theme.primary" size="24"></u-icon>
							</view>
							<view style="padding: 0 20rpx 0 0;">
								<u-icon @click="opensharebox"
									:name="settingFile.root_img+'/static/app/imgs/shop/share.png'" size="24">
								</u-icon>
							</view>
						</view>
					</view>
					<view class="shop_line">
						<view class="shop_line_p3" @click="openmap()">
							<u-icon :name="settingFile.root_img+'/static/app/imgs/shop/daohang.png'" :color="primary"
								size="15"  labelSize='12'>
							</u-icon>
							<view class="title">
								{{farm_info.farm_address}}
							</view>
							
						</view>
					</view>
					<view class="shop_line">
						<view class="shop_line_p2">
							<u-icon name="clock" :color="primary" size="16" :label="timename" labelSize='12'>
							</u-icon>
							<u-icon name="grid" :color="primary" size="16" :label="farm_info.shopnum" labelSize='12'>
							</u-icon>
							<u-icon name="car" :color="primary" size="16" :label="farm_info.shoporder" labelSize='12'>
							</u-icon>
							<u-icon name="eye" :color="primary" size="16" :label="farm_info.page_view" labelSize='12'>
							</u-icon>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 	商品 -->
		<view class="order-section">
			<view class="content">
				<view class="order-item" @click="navTo(1)" hover-class="common-hover" :hover-stay-time="40">
					<image class="yticon" :src="settingFile.root_img+'/static/app/imgs/shop/goods.png'" mode="">
					</image>
					<text>商品</text>
				</view>
				<view class="order-item" @click="navTo(2)" hover-class="common-hover" :hover-stay-time="40">
					<image class="yticon" :src="settingFile.root_img+'/static/app/imgs/mine/dis/50.png'" mode="">
					</image>
					<text>土地</text>
				</view>
				<view class="order-item" @click="navTo(3)" hover-class="common-hover" :hover-stay-time="40">
					<image class="yticon" :src="settingFile.root_img+'/static/app/imgs/mine/dis/51.png'" mode="">
					</image> <text>认养</text>
				</view>
				<view class="order-item" @click="navTo(4)" hover-class="common-hover" :hover-stay-time="40">
					<image class="yticon" :src="settingFile.root_img+'/static/app/imgs/mine/dis/52.png?t=1'" mode="">
					</image> <text>监控</text>
				</view>
				<view class="order-item" @click="navTo(5)" hover-class="common-hover" :hover-stay-time="40">
					<image class="yticon" :src="settingFile.root_img+'/static/app/imgs/mine/dis/53.png?t=88'" mode="">
					</image> <text>活动</text>
				</view>
			</view>

		</view>

		<view class="lswiper" v-if='list1'>
			<u-swiper :list="list1" @change="change" @click="click"></u-swiper>
		</view>
		<!-- #ifdef APP-PLUS || MP-WEIXIN -->
		<u-sticky :offset-top="offset" style="z-index: 10;">
			<!-- #endif -->
			<!-- #ifdef H5 -->
			<u-sticky offset-top="-44" style="z-index: 10;">
				<!-- #endif -->
				<view class="warning">
					<u-sticky bgColor="#fff">
						<u-tabs :list="radios" @click="tabsclick" :lineColor="primary"></u-tabs>
					</u-sticky>
				</view>
			</u-sticky>
			<view class="swiper_item">

				<scroll-view class="scroll_bar"  :refresher-triggered="triggered" scroll-y @scrolltolower="expandbottom">
					<!-- 商品列表 -->
					<view class="commodity_list" v-if="commoditylist&&swiperCurrent===0">

						<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>
					<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>

			</view>
			<!-- 分享 -->
			<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,
				btnstatus: 2,
				loadmore: '',
				list1: [],
				radios: [],

				// 因为内部的滑动机制限制，请将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: {}, //农场信息
				cateid: '',
				offset: -1,
			}
		},
		onLoad(options) {
			this.farm_id = options.id
			// this.offset = this.offset + uni.$u.sys().statusBarHeight
			console.log('this.offset',this.offset)
			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: {
			navTo(type) {
				if (type == 1) {
					uni.navigateTo({
						url: '/pagesC/pages/merchantdetails/farmshoplist?type=1' + '&farm_id=' + this.farm_id
					})
				} else if (type == 2) {
					uni.navigateTo({
						url: '/pagesC/pages/merchantdetails/farmshoplist?type=2' + '&farm_id=' + this.farm_id
					})
				} else if (type == 3) {
					uni.navigateTo({
						url: '/pagesC/pages/merchantdetails/farmshoplist?type=3' + '&farm_id=' + this.farm_id
					})
				} else if (type == 4) {
					uni.navigateTo({
						url: '/pagesC/pages/merchantdetails/farmshoplist?type=4' + '&farm_id=' + this.farm_id
					})
				} else if (type == 5) {
					uni.navigateTo({
						url: '/pagesC/pages/merchantdetails/farmshoplist?type=5' + '&farm_id=' + this.farm_id
					})
				}

			},
			tabsclick(e) {
				this.cateid = e.id
				this.commoditylist = []
				this.getshopdetails()
			},
			change() {

			},
			click(item) {
				console.log('item', item);
			},

			callPhone() {
				let that = this;
				console.log('servicemobile', that.farm_info.servicemobile);
				if (that.farm_info.servicemobile) {
					// #ifdef H5
					window.location.href = 'tel://' + that.farm_info.servicemobile
					// #endif
					// #ifdef APP-PLUS || MP-WEIXIN
					uni.makePhoneCall({
						phoneNumber: that.farm_info.servicemobile,
						success: function() {
							console.log('拨打电话成功');
						},
						fail() {
							this.$api.msg('打电话失败了')
							return
						}
					})
					// #endif
				} else {
					this.$api.msg('暂无商家联系电话')
					return
				}
			},
			//分享
			opensharebox() {
				this.$refs.sbox.opensharebox(this.sharedata);
			},
			openmap() { //打开地图查看农场位置
				// console.log('this.farm_info', JSON.stringify(this.farm_info))
				// #ifdef MP-WEIXIN  || APP-PLUS
				uni.openLocation({
					latitude: Number(this.farm_info.latitude),
					longitude: Number(this.farm_info.longitude),
					name: '',
					address: this.farm_info.farm_address,
					success: function(res) {
						console.log(res, "地图打开了")
					},
					fail: function(error) {
						console.log(error, "error")
					}
				})
				// #endif
			},
			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.farm_item2({
						farm_id: this.farm_id,
						cateid: this.cateid,
						p: this.page
					})
					.then(res => {
						if (res.status == 1) {
							res.data.res.forEach(ele => {
								this.commoditylist.push(ele)
							})
							if (res.data.res.length < 10) {
								this.loadmore = "nomore"
							} else {
								this.loadmore = "loadmore"
							}
							this.farm_info = res.data.farm_info
							this.sharedata = res.data.sharedata
							this.radios = res.data.shopcate
							this.list1 = res.data.farm_info.lun_img
							this.timename = res.data.farm_info.tradetime
							this.sharedata.path = '/pagesC/pages/merchantdetails/merchantdetails?pid=' + this
								.$getuid() + '&id=' + this.farm_id;
						} else {
							this.page--
							this.loadmore = "nomore"
						}
					})
			},
			// tabs通知swiper切换并更改数据
			tabsChange(e) {
				this.swiperCurrent = e.index
				this.commoditylist = []
				this.page = 1
				this.getshopdetails()
			},
			//展开底部，可以查看全部信息
			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);
			},
			//阻止用户手动滑动
			stopTouchMove() {
				return true
			}
		}
	}
</script>
<style lang="scss" scoped>
	.all_box {
		width: auto;
		background-color: #f1f1f1;
		min-height: 100vh;

		.lswiper {
			padding: 15rpx;
			z-index: 1;
		}

		.shop_names {
			padding: 20rpx 15rpx 15rpx 15rpx;
			background-color: #f1f1f1;

			.shop_name {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 30rpx 15rpx 15rpx 15rpx;
				background-color: #FFFFFF;
				border-radius: 10rpx;

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

				.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 {
							padding: 10rpx 2rpx;
							color: #000;
							font-size: 32rpx;
							font-weight: 200;
						}

						.shop_line_p2 {
							display: flex;
							justify-content: space-between;
							width: 100%;
							padding: 15rpx 0rpx;
							padding-right: 30rpx;
							color: #828282;
							font-size: 26rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						.shop_line_p3 {
							display: flex;
							justify-content: flex-start;
							width: 100%;
							padding: 15rpx 0rpx;
							padding-right: 30rpx;
							color: #828282;
							font-size: 26rpx;
								
							.title{
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
								padding-left: 8rpx;
								width: 100%;
							}
						}
						.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;
						padding: 10rpx 0rpx;
						font-size: 26rpx;
						color: #999999;

						.shop_one_1 {}

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

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

				}
			}
		}

		.swiper_item {
			min-height: calc(100vh - 780rpx);

			.scroll_bar {
				min-height: calc(100vh - 780rpx);
				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%;
							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 {
		padding: 15rpx;

		.content {
			padding: 18rpx 0rpx;
			display: flex;
			background-color: #FFFFFF;
			border-radius: 10rpx;

			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: 70rpx;
					height: 70rpx;
				}
			}

			.yticon {

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

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

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

	}

	.warning {
		width: 100%;
		background-color: #fff;
		display: flex;
	}
</style>
