<template>
	<view :class="[AppTheme]" class="all_box">
		<!-- #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="shop_name">
					<view style="width: 70%;">
						<u-search shape="round" :clearabled="true" placeholder="搜索" v-model="keyword" bgColor='#fff'
							@search='search()'></u-search>
					</view>
					<view class="shop_lines" @click="addshop()">
						<view class="link">
							<view class="shop_lines_1">
								<u-icon name="plus-circle" size="15" color="red"></u-icon>
							</view>
							<view class="shop_lines_2">
								添加商品
							</view>
						</view>
					</view>
				</view>
				<view style="width: 100%;background-color:#fff;">
					<u-tabs @click="tabsChange" :scrollable="false" :lineColor="primary" ref="uTabs" :list="titlelist"
						:current="current" :activeStyle="{
			        color: primary,
			        transform: 'scale(1.05)'
			    }" :inactiveStyle="{
			        color: '#606266',
			        transform: 'scale(1)'
			    }" lineWidth="30"></u-tabs>
				</view>
			</u-sticky>
			<scroll-view class="list-scroll-content" :refresher-enabled="true" :refresher-triggered="triggered"
				@refresherrefresh="refresh" scroll-y @scrolltolower="handle">
				<view v-if="commoditylist&&commoditylist.length>0" class="order-item"
					v-for="(item,index2) in commoditylist" :key="index2">
					<view>
						<view class="detail_title_1">
							<view class="detail_title_p1">
								<image class="image" :src="item.pic" mode=""></image>
							</view>
							<view class="detail_title_p2">
								<view class="detail_title_p3">{{item.name}}</view>
								<view class="fram_oper_1">
									<view class="fram_oper_2">
										<view class="views1">{{item.price}}</view>
										<view class="views1">{{item.num}}</view>
										<view class="views1">{{item.dissells}}</view>
									</view>
									<view class="fram_oper_2">
										<view class="views2">价格</view>
										<view class="views2">库存</view>
										<view class="views2">销量</view>
									</view>

								</view>
							</view>
						</view>
						<view v-if="item.tstate==5">
							<u-collapse :border="false">
								<u-collapse-item>
									<text slot="title" class="u-page__item__title__slot-title">驳回原因</text>
									<text class="u-collapse-content">{{item.mark}}</text>
								</u-collapse-item>
							</u-collapse>
						</view>
						<view class="bor_solp"></view>
						<view class="shopbtn">
							<view v-if="item.tstate==3" class="shop_1" @click="upshop(item.id,1,index2)">上架
							</view>
							<view v-if="item.tstate==1" class="shop_2" @click="downshop(item.id,2,index2)">下架
							</view>
							<view v-if="item.tstate==2||item.tstate==3||item.tstate==5" class="shop_3"
								@click="editshop(item.id)">编辑</view>
							<view class="shop_4" @click="$until.toUrl('/pagesD/pages/product/product?id='+item.id)">
								详情</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>
				<view style="height: 30rpx;"></view>
			</scroll-view>
			<u-modal :show="show" :title="title" :content='content' :showCancelButton='true' @confirm='confirm'
				@cancel='cancel'></u-modal>
	</view>
</template>
<script>
	import mineApi from "@/api/mine/index.js"
	export default {
		components: {},
		data() {
			return {
				primary: this.$theme.primary,
				sharedata: null,
				settingFile: getApp().globalData.siteinfo,
				btnstatus: 2,
				offset: 0,
				triggered: true,
				loadmore: '',
				titlelist: [{
						name: '出售中'
					},
					{
						name: '售罄'
					},
					{
						name: '仓库中'
					},
					{
						name: '审核中'
					},
					{
						name: '驳回'
					}
				],
				// 因为内部的滑动机制限制，请将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: [], //列表

				farm_info: {}, //农场信息
				keyword: '',
				show: false,
				title: '温馨提示',
				content: '',
				type: '',
				id: '',
				rowindex: 0
			}
		},
		onLoad(options) {
			this.farm_id = options.id
			this.getshopdetails()
		},
		onShow() {
			let that = this;
			const mobileInfo = uni.getSystemInfoSync();
			let iphoneXArr = ["iPhone X", "iPhone 11", "iPhone 11 Pro Max"];
			iphoneXArr.forEach(function(item) {
				if (mobileInfo.model.search(item) !== -1) {
					// that.offset = 89;
					return
				}
			});
		},
		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: {
			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);
			},
			handle() {
				this.page++;
				this.getshopdetails()
			},
			cancel() {
				this.show = false
			},
			confirm() {
				let that = this;
				console.log('that.rowindex', that.rowindex)
				if (that.type == 2) { //下架
					mineApi.downshop({
							id: that.id,
						})
						.then(res => {
							if (res.status == 1) {
								uni.showToast({
									icon: 'none',
									title: res.msg
								})
								if (that.commoditylist.length > that.rowindex) {
									that.commoditylist[that.rowindex].tstate = 2;
								}
							}
						})

				} else if (that.type == 1) { //上架
					mineApi.upshop({
							id: that.id,
						})
						.then(res => {
							if (res.status == 1) {
								uni.showToast({
									icon: 'none',
									title: res.msg
								})
								if (that.commoditylist.length > that.rowindex) {
									that.commoditylist[that.rowindex].tstate = 1;
								}
							}
						})
				}
				that.show = false
			},
			//编辑商品
			editshop(id) {
				uni.navigateTo({
					url: "/pagesC/pages/merchantdetails/editshop?id=" + id + '&farm_id=' + this.farm_id
				})
			},
			//下架商品
			downshop(id, type, index) {
				this.content = '确定要下架该商品吗？'
				this.show = true
				this.type = type
				this.id = id
				this.rowindex = index;
			},
			//上架商品
			upshop(id, type, index) {
				this.content = '确定要上架该商品吗'
				this.show = true
				this.type = type
				this.id = id
				this.rowindex = index;
			},
			search() {
				this.page = 1
				this.commoditylist = []
				this.getshopdetails()
			},
			addshop() {
				uni.navigateTo({
					url: "/pagesC/pages/merchantdetails/addshop?id=" + this.farm_id
				})
			},
			//分享
			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() { //获取店铺详情
				let that = this;
				that.loadmore = 'loading'
				mineApi.shopmanagement({
						farm_id: that.farm_id,
						type: that.swiperCurrent + 1,
						p: that.page,
						keyword: that.keyword
					})
					.then(res => {
						if (res.status == 1) {
							if (res.data.length < 10) {
								that.loadmore = "nomore"
							} else {
								that.loadmore = "loadmore"
							}
							that.farm_info = res.data.farm_info
							that.commoditylist = that.commoditylist.concat(res.data);
							console.log('this.commoditylist', that.commoditylist)
						} else {
							that.page--
							that.loadmore = "nomore"
						}
					})
			},
			// tabs通知swiper切换并更改数据
			tabsChange(e) {
				this.swiperCurrent = e.index
				this.commoditylist = []
				this.page = 1
				this.getshopdetails()
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			transition(e) {
				let dx = e.detail.dx
				// this.$refs.uTabs.setDx(dx)
			},
			// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
			// swiper滑动结束，分别设置tabs和swiper的状态
			animationfinish(e) {
				let current = e.detail.current
				// this.$refs.uTabs.setFinishCurrent(current)
				this.swiperCurrent = current
				this.current = current
			},
			//展开底部，可以查看全部信息
			expandbottom() { //上拉加载分页
				this.page++
				this.getshopdetails()
			},
			//阻止用户手动滑动
			stopTouchMove() {
				return true
			}
		}
	}
</script>
<style lang="scss" scoped>
	.all_box {
		width: auto;
		background-color: #FFFFFF;
		min-height: 100vh;

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

			.shop_lines {
				display: flex;
				border: 1rpx solid #eae8e9;
				border-radius: 40rpx;
				align-items: center;
				line-height: 62rpx;
				width: 26%;
				background-color: #fff;

				.link {
					display: flex;
					align-items: center;
					margin-left: 1.5vh;

					.shop_lines_1 {

						// border: 1rpx solid red;
						// border-radius: 50%;
						color: red;
					}

					.shop_lines_2 {
						margin-left: 0.5vh;
						font-size: 28rpx;
					}
				}

			}

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

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

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

					.shop_line_p1 {
						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;

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

		.list-scroll-content {
			height: 100%;
		}

		.swiper-box {
			height: calc(100vh - 100px);

			.scroll_bar {
				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;

						.commodity_item_thumbnail {
							width: 340rpx;
							height: 365rpx;
						}
					}
				}

				.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 {
					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;
							}
						}
					}
				}
			}
		}
	}


	::v-deep .u-search__action--active[data-v-0a306a29] {
		width: 0;
	}

	.order-item {
		padding: 20rpx;
		margin: 25rpx 20rpx;
		border-radius: 10rpx;
		box-shadow: 2px 4px 12px rgba(0, 0, 0, 0.08);
		background-color: #ffffff;

		display: flex;
		flex-direction: column;
		padding-left: 30upx;
		background: #fff;
		margin-top: 16upx;


		.text_area {


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

			.right_shop_mess {
				// width: calc(100% - 120rpx);
				display: flex;
				justify-content: space-between;
				align-items: center;

				.shop_line {
					width: 70%;
					display: flex;
					flex-direction: column;
					padding: 10rpx;

					.shop_line_p1 {

						font-size: 28rpx;

					}

					.shop_line_p2 {

						font-size: 32rpx;
						font-weight: 600;
						margin-top: 1vh;
						-webkit-line-clamp: 1;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						text-overflow: ellipsis;


					}

					.shop_line_p3 {
						font-size: 28rpx;
						color: red;
						margin-top: 1vh;
						-webkit-line-clamp: 2;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						text-overflow: ellipsis;
					}
				}

				.shop_line_fl {
					line-height: 65rpx;
					width: 180rpx;
					text-align: center;
					border-radius: 40rpx;
					font-size: 30rpx;
					color: #fff;
					float: right;
				}

				.shop_line_f2 {
					font-size: 30rpx;
					color: #999;
				}

			}

			.shop_line_p4 {
				margin-top: 1vh;
				display: flex;
				justify-content: space-between;
				font-size: 28rpx;
				padding: 10rpx;
			}

		}

		.display_diagram {
			width: 100%;
			white-space: nowrap;
			margin: 10rpx 0;

			.display_diagram_item {
				width: 200rpx;
				height: 200rpx;
				margin: 0 15rpx 0 0;
				border-radius: 7.5%;
			}
		}
	}

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

		.ranking_three {
			display: flex;
			align-items: center;

			image {
				width: 80rpx;
				height: 80rpx;
			}

			view {
				margin-left: 1vh;
			}
		}

		.ranking_two {
			color: red;

		}
	}

	.detail_title_1 {
		display: flex;
		justify-content: flex-start;
		align-items: center;

		.detail_title_p1 {
			.image {
				border-radius: 10rpx;
				width: 150rpx;
				height: 150rpx;
			}
		}

		.detail_title_p2 {

			width: 100%;
			padding-left: 20rpx;

			.detail_title_p3 {
				line-height: 45rpx;
				font-size: 30rpx;
				-webkit-line-clamp: 2;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				text-overflow: ellipsis;
			}

			.detail_title_p4 {
				margin-bottom: 20rpx;
			}

			.detail_title_p4 {
				-webkit-line-clamp: 2;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				text-overflow: ellipsis;
			}

			.fram_oper_1 {
				display: flex;
				flex-direction: column;

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

					.views1 {
						font-size: 28rpx;
						width: 20%;
						text-align: center;
						color: #3e3e3e;
						-webkit-line-clamp: 1;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						text-overflow: ellipsis;
					}

					.views2 {
						font-size: 22rpx;
						width: 20%;
						color: #9f9f9f;
						text-align: center;
						-webkit-line-clamp: 1;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						text-overflow: ellipsis;
					}
				}
			}
		}
	}

	.bor_solp {
		background-color: #999;
		height: 1rpx;
		width: 100%;
		transform: scaleY(0.3);
		margin: 10rpx 0;
	}

	.shopbtn {
		display: flex;
		justify-content: flex-end;
		padding: 10rpx 0;
		align-items: center;
		font-size: 22rpx;
		color: #ffffff;

		.shop_1 {
			margin-right: 10rpx;
			border: 1rpx solid #eae8e9;
			border-radius: 40rpx;
			padding: 15rpx 40rpx;
			background-color: #00aaff;
		}


		.shop_2 {
			margin-right: 10rpx;
			border: 1rpx solid #eae8e9;
			border-radius: 40rpx;
			padding: 15rpx 40rpx;
			background-color: #a5a5a5;
		}

		.shop_3 {
			margin-right: 10rpx;
			border: 1rpx solid #eae8e9;
			border-radius: 40rpx;
			padding: 15rpx 40rpx;
			background-color: #00aa00;
		}

		.shop_4 {

			border: 1rpx solid #eae8e9;
			border-radius: 40rpx;
			padding: 15rpx 40rpx;
			background-color: #587cff;
		}
	}
</style>
