<template>
	<view class="page">
		<u-navbar :is-back="false" title="蜂场" :border-bottom="false" :background="bgc" title-color='#3D3D3D '
			title-size='36' height='45' id="navbar">
		</u-navbar>
		<view class="top_box">
			<view class="search">
				<image src="https://api.ccttiot.com/smartmeter/img/static/um5GxgXufKY8IK2qkaWR" mode=""></image>
				<view class="search_center">
					<input type="text" class="ips" v-model="code" @confirm="changserch" placeholder="请输入蜂场"
						placeholder-class="my-placeholder" />
				</view>
			</view>
			<view class="add" @click="addApiary()">
				<image src="https://api.ccttiot.com/smartmeter/img/static/uR30yYn3IsHDu5qWV0ML" mode=""></image>
			</view>
		</view>
		<view class="no_cont" v-if="logoflag">
			<view class="img">
				<image src="https://api.ccttiot.com/smartmeter/img/static/uUZ3MF84e3bKgwAei8Rz" mode=""></image>
			</view>
			<view class="txt">
				当前还没有添加蜂场哦
			</view>
		</view>
		<scroll-view v-else class="Apiary_box" scroll-y="true" @scrolltolower="loadMore">
			<view class="Apiary_card" v-for="(item,index) in list" :key="index" @click="btnapiaryxq(item.apiaryId)">
				<image :src="item.picture" mode=""></image>
				<view class="weather">
					<image src="https://api.ccttiot.com/smartmeter/img/static/u6wWpgZOuId6JSX8LGmz" mode="scaleToFill"></image>
					<view class="txt1">
						多云
					</view>
					<view class="txt2">
						温度舒适，湿润，光照强，空气优
					</view>
				</view>
				<view class="info">
					<view class="left">
						{{item.name}}
					</view>
					<view class="right">
						{{item.beehiveCount}}箱
					</view>
				</view>
				<view class="address">
					{{item.address}}
				</view>
			</view>
		</scroll-view>
		<tab-bar :indexs='1' style=""></tab-bar>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgc: {
					backgroundColor: " #FAFDFD",
				},
				pagesum: 1,
				list: [],
				total: '',
				pagesize: 10,
				logoflag: false,
				code: '',
			}
		},
		onLoad() {
           
		},
		onShow() {
			this.pagesum = 1
			// this.list = []
			this.ishave()
		},
		methods: {
			changserch() {
				let data = {
					pageNum: this.pagesum,
					pageSize: this.pagesize,
					name: this.code,
				}
				this.$u.get('/farm/apiary/list', data).then(res => {
					if (res.code == 200) {
						this.list = []
						this.total = res.total
						this.list = res.rows
					}
				})
			},

			// 跳转蜂场详情
			btnapiaryxq(id) {
				uni.navigateTo({
					url: '/pages/Apiary/Apiary_detail?id=' + id
				})
			},
			loadMore() {
				if (this.list.length < this.total) {
					this.ishave();
				} else {
					uni.showToast({
						title: '没有更多蜂场了',
						icon: 'none',
						duration: 1000
					});
				}
			},
			addApiary() {
				uni.navigateTo({
					url: '/pages/Apiary/AddApiary'
				})
			},
			ishave() {
				let data = {
					pageNum: this.pagesum,
					pageSize: this.pagesize
				};
				this.$u.get('/farm/apiary/list', data).then((res) => {
					if (res.code === 200) {
						this.total = res.total;
						if (this.total < 1) {
							this.logoflag = true;
						} else {
							if(this.pagesum > 1){
								this.list = this.list.concat(res.rows)
							}else{
								this.list = res.rows
							}
							this.pagesum++;
							this.logoflag = false;
							// console.log(this.list);
						}
					} else {
						this.logoflag = true
					}
				})
			},


		}
	}
</script>

<style lang="scss">
	page {
		background-color: #FAFDFD;
	}

	.page {
		// position: relative;
		width: 750rpx;

		.Apiary_box {
			padding-left: 40rpx;
			box-sizing: border-box;
			padding-bottom: 230rpx;
			overflow-y: auto;
			height: 78vh;

			.Apiary_card {
				margin-top: 20rpx;
				position: relative;
				width: 674rpx;
				height: 512rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(0, 0, 0, 0.15);
				border-radius: 20rpx 20rpx 20rpx 20rpx;
                background: linear-gradient(to bottom, rgba(255, 255, 255, 0.8), transparent);
				image {
					width: 674rpx;
					height: 360rpx;
					border-radius: 20rpx 20rpx 0 0;
				}

				.address {
					margin-top: 18rpx;
					padding: 0 24rpx;
					font-weight: 500;
					font-size: 28rpx;
					color: #50565A;
					white-space: nowrap;
					/* 禁止换行 */
					overflow: hidden;
					/* 超出部分隐藏 */
					text-overflow: ellipsis;
				}

				.info {
					margin-top: 18rpx;
					padding: 0 24rpx;
					display: flex;
					align-items: center;
					flex-wrap: nowrap;
					justify-content: space-between;

					.left {
						font-weight: 600;
						font-size: 36rpx;
						color: #3D3D3D;
					}

					.right {
						font-weight: 600;
						font-size: 32rpx;
						color: #50565A;
					}
				}

				.weather {
					padding: 20rpx 24rpx;
					position: absolute;
					display: flex;
					align-items: center;
					flex-wrap: nowrap;
					left: 0;
					top: 0;
					width: 674rpx;
					height: 70rpx;
                   background-color: rgba(255, 255, 255, 0.5);

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

					.txt1 {
						margin-left: 16rpx;
						font-weight: 600;
						font-size: 32rpx;
						color: #3d3d3d;
					}

					.txt2 {
						margin-left: 28rpx;
						font-weight: 600;
						font-size: 28rpx;
						color: #3D3D3D;
					}
				}
			}
		}

		.top_box {
			margin: 42rpx auto;
			display: flex;
			flex-wrap: nowrap;
			width: 664rpx;
            align-items: center;
			.search {

				display: flex;
				flex-wrap: nowrap;
				align-items: center;
				padding: 20rpx 26rpx;
				width: 566rpx;
				height: 82rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(0, 0, 0, 0.15);
				border-radius: 20rpx 20rpx 20rpx 20rpx;

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

				.search_center {
					margin-left: 34rpx;
					width: 480rpx;

					.ips {
						// 基本样式设置
						width: 100%; // 根据需要调整

						// border: 1px solid #ccc; // 根据需要调整

						// 设置 placeholder 样式

					}

					.my-placeholder {
						font-weight: 400;
						font-size: 32rpx;
						color: #808080;
					}
				}
			}

			.add {
				margin-left: 30rpx;
				width: 66rpx;
				height: 66rpx;
			}
		}

		.no_cont {
			margin: 152rpx auto 0;
			width: 432rpx;

			.img {
				image {
					width: 432rpx;
					height: 432rpx;
				}
			}

			.txt {
				margin-top: 50rpx;
				width: 100%;
				text-align: center;
				font-weight: 500;
				font-size: 32rpx;
				color: #808080;
			}
		}




	}
</style>