<style lang="scss">
	.container{
		height:100%;
		background:#f6f6f6;
		&>.d-search{
			&/deep/ .want_search{
				.title{
					color:#999;
					font-size:24rpx;
					font-weight: normal;
				}
				.content{
					display:flex;
					flex-wrap: wrap;
					margin:14rpx -20rpx -20rpx 0;
					text{
						height:48rpx;
						line-height: 48rpx;
						border-radius: 30rpx;
						width:calc(100%/5 - 20rpx);
						text-align: center;
						font-size:24rpx;
						margin:0 20rpx 20rpx 0;
						transition: all 0.3s;
						color:#999;
						background:#EEEEEE;
						&.active{
							color:#fff;
							background:#10C176;
						}
					}
				}
			}
		}

		.date-range{
			flex-shrink: 0;
			display: flex;
			align-items: center;
			color:#999;
			picker{
				width:50%;
				background:#fff;
				margin:0 30rpx;
				border-radius:10rpx;
				height:60rpx;
				line-height: 60rpx;
				text-align:center;
				position:relative;
				color:#333;
				&:before{
					transform: rotate(90deg);
					position:absolute;
					right:10rpx;
				}
				&.noData{
					color:#999;
				}
			}
		}

		scroll-view{
			flex-grow: 1;
			height:1rpx;

			.card{
				.info{
					display:flex;
					align-items: center;
					text{
						&:first-child{
							flex-shrink: 0;
							background:#10C176;
							border-radius:4rpx 40rpx 4rpx 40rpx;
							padding:0 10rpx;
							box-sizing: border-box;
							color:#fff;
							height:40rpx;
							line-height: 40rpx;
							min-width:80rpx;
							text-align: center;
							font-size:20rpx;
							margin-right:12rpx;
						}
						&:nth-child(3){
							margin-left:auto;
							flex-shrink: 0;
							color:#10C176;
							font-size:24rpx;
							font-weight: bold;
						}
					}
				}
				&>.tabs{
					display:flex;
					flex-wrap: wrap;
					margin:12rpx -18rpx -16rpx 0;
					text{
						border-radius: 10rpx;
						margin:0 18rpx 16rpx 0;
						font-size:24rpx;
						height:44rpx;
						line-height: 44rpx;
						background-position: 20rpx 12rpx;
						background-repeat: no-repeat;
						color:rgba(var(--c),1);
						background-color:rgba(var(--c),0.1);
						padding-right:20rpx;
					}
					.germinate{
						--c:15, 194, 119;
						background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAALCAYAAAB24g05AAAAAXNSR0IArs4c6QAAAYZJREFUKFOdkU1IVHEUxc957yE45YwKSRnUpp24dKELZ4YCMdFNJNWyRdDOr3lBkMzK0PmIEsFVqzDMlRsXBcObaBuCgRjMphREUOq9USqc9z/igGKKMHi3554f955D1DCXC8/aLNu8pNgFoonSqsA5v8m8YQ1+NBZTgcB6AN8oXRF5lYAjaakKuFQcbnfgDEHoAlkHaPlfxYz+vZ37AYGxz+4aoe8S7oIwMhxRuPe+fGdmhzEv9RTA9KEAYAPALwA3INh+ItOMD/ftaMvNOYvWIIC9CszAbjxbOLqcMc+doKV9iR0EegUJ4FcJpSAx9TDqua8rDiYdKa6K+VRO5rZPvv1fBg3eWL9Nzgq4BnEeMCuw2O53Zx6dl9XZENNpq74zuP6nJ78e+ei22nXmQTmRzdcOOLXZWEw9/h3PvL0wIOaNTfiJ7POaAZEvbqsT4okl3QMZGKlEoB+EF8K82936uYjBhfC4hVNkRgujL2jbfYBuEWyu6oIvahPkssL98SD5qnTkOwB+A5pVJ9wdJQAAAABJRU5ErkJggg==);
						background-size:30rpx 22rpx;
						padding-left:30rpx+25rpx;
					}
					.organ{
						--c:248, 203, 54;
						background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAANCAYAAACdKY9CAAAAAXNSR0IArs4c6QAAAQ9JREFUKFOlUrtKA1EQPedeHxERFAQRCYK9GCW7Ivb+hEUqsbONhZVFCm0kYCPoD9gFS4tgYeFVsLBLmyaNWO5qmCOYjYJuksJphnmcmTMPIpPkIXoGuda3f7QEoSVgbyoOd+wH0sfoCKL/DZA0A+IAQLMQhR0moVwHXPFv5cxjuJTTIYHpQhTWmYRYA5O/AjoDUAIw+w+A0AV0QcemmTZIVAFm8+V2sBOjzq2bpnJ+fowTVwTjHtWBlGQATgHcSjgmuTUCkD+6YDVPNWjOj8fhfviWhNZrp12aW1jadbK3yc2n6xEA1QW8kFoF3IqXauy9BJbzCAlqOOpG8hVAi864//0aw473EcrbEt8NqnwCf8mG+U/vRGMAAAAASUVORK5CYII=);
						background-size:26rpx 24rpx;
						padding-left:26rpx+25rpx;
					}
					.type{
						--c:235, 67, 118;
						background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAAXNSR0IArs4c6QAAASBJREFUKFN9kD0vQ2EYhq/7bUUklUhEYxAMNfsDJk0TGxN/wWJ0EpvExmjpajMYTAaDxSIWg1ERFh/toCGpr55bzkk1qmmf8cl9PR+XqvPRHfY+QRH9KvY2YkXVYmTgEFjCNIBmi8sghv7MSDNtwHapfv8+OlPZ/UhCV4W1wZHJoSpiuAV1AgltxxVJL0nA9ogUCj03YC8iPWBixDiQ/fdS10lz+ZOdsSRULUanwFxfIH0IPhMD2ANIj2rGURzClsT0r5hOS62Rtq8F5aZ9miHMWo4kXXZYSrW2AZ7q942p7MSrklYu5M8Qtz0B7POBz8zCV/Z7+Y3aXi6MHSHV+2xwjZhNiUnsG4I2kC5S4Lm4fqBYxwRWwekJ3aVEdtmi9AMqTJE6K1mcKgAAAABJRU5ErkJggg==);
						background-size:24rpx 22rpx;
						padding-left:24rpx+25rpx;
					}
				}
				.adder{
					display:flex;
					align-items: center;
					font-size:24rpx;
					margin-top:20rpx;
					padding-top:20rpx;
					border-top:2rpx solid rgba(216, 216, 216, 0.3);
					text:first-child{
						color:#999;
						margin-right:auto;
					}
					text:nth-child(2){
						color:#10C176;
						flex-shrink: 0;
						margin-left:20rpx;
					}
				}
				.record{
					margin-top:15rpx;
					display:flex;
					align-items: center;
					justify-content: space-between;
					text{
						font-size:24rpx;
						color:#999;
					}
				}
				.detail{
					display: flex;
					align-items: center;
					text{
						font-size:24rpx;
						color:#999;
						&.type{
							flex-shrink: 0;
							background:#10C176;
							border-radius:4rpx 40rpx 4rpx 40rpx;
							padding:0 10rpx;
							box-sizing: border-box;
							color:#fff;
							height:40rpx;
							line-height: 40rpx;
							min-width:80rpx;
							text-align: center;
							font-size:20rpx;
							margin-right:12rpx;
						}
						&.time{
							margin-left:auto;
						}
					}
				}
			}
		}
	}
</style>
<template>
	<view class="container flex">
		<d-search :btn="false" popup ref="dSearch" v-model="searchVal.search" :selectVal="searchVal.value" @select="searchVal.value=$event" @search="clean();search()">
			<text class="title">猜你想搜</text>
			<view class="content">
				<text v-for="(v,k) in typeList" :class="{active:v.value==searchVal.value}" :key="k" @click="select(v.value)">{{v.label}}</text>
			</view>
		</d-search>

		<d-dateRange @date="searchVal.startTime=$event[0];searchVal.endTime=$event[1];clean();search()"/>


		<scroll-view scroll-y @scrolltolower="search">
			<view class="card" v-for="(v,k) in list" :key="k" @click="v.growthProcess && toDetail(v)">
				<template v-if="v.inputName">
					<view class="info">
						<text>{{v.type}}</text> <text class="over">{{v.inputName}}</text> <text>{{v.inputTotal}}{{v.unit}}</text> <text class="plant-youbian" v-if="v.growthProcess"/>
					</view>
					<view class="tabs" v-if="v.growthProcess">
						<text class="germinate">{{v.growthProcess}}</text>
						<text class="organ">{{v.pestSite}}</text>
						<text class="type">{{v.symptom}}</text>
					</view>
					<view class="adder">
						<text class="over">{{v.plotName}}</text> <text>{{v.productName}}</text>
					</view>
					<view class="record">
						<text>记录时间：{{new Date(v.time).format('yyyy-MM-dd')}}</text> <text>负责人：{{v.principal}}</text>
					</view>
				</template>
				<template v-else>
					<view class="detail">
						<text class="type">{{v.type}}</text>
						<text class="people">负责人：{{v.principal}}</text>
						<text class="time">记录时间：{{new Date(v.time).format('yyyy-MM-dd')}}</text>
					</view>
					<view class="adder">
						<text class="over">{{v.plotName}}</text> <text>{{v.productName}}</text>
					</view>
				</template>
			</view>
			<u-empty v-if="list.length==0" text="未查询到相关信息" width="70%" icon="/static/noData.png"/>
		</scroll-view>
	</view>
</template>
<script>
import request from '@/common/request.js'
	export default {
		data(){
			return{
				searchVal:{
					search:"",
					value:"",
					pageNo:1,
					pageSize:6,
					plotId:"",
					PlantBaseInfoId: this.$store.state.baseInfo.id,
					startTime:"",
					endTime:"",
				},
				total:0,
				list:[],
				typeList:[],
			}
		},
		onLoad(){
			this.init()
			this.search()
		},
		methods:{
			select(e){
				this.$refs.dSearch.show=false
				this.searchVal.value=this.searchVal.value==e?'':e
				this.clean()
				this.search()
			},
			async init(){
				var res=await request("/api/plantFarming/listFarmName")
				if(res.statu){
					this.typeList=res.data
				}
			},
			clean(){
				this.list=[]
				this.total=0
				this.searchVal.pageNo=1
			},
			async search(){
				if(this.total==0 || this.list.length<this.total){
					var res=await request("/api/plantFarming/listFarmByPlotId",{
						params: this.searchVal
					})
					if(res.statu){
						this.list=this.list.concat(res.data.list)
						this.total=res.data.total
						this.searchVal.pageNo++
						if(this.list.length==this.total)uni.showToast({title:"加载完成！",icon:"none"})
					}else{
						uni.showModal({
							title:"提示",
							content:res.msg||"获取农事记录列表失败！",
							showCancel:false,
						})
					}
				}
			},
			toDetail(e){
				uni.navigateTo({
					url:`/pages/home/newsDetail?intoPage=farming`,
					success(res){
						res.eventChannel.emit("detail",{...e,images: (e.images||'').split(',').filter(v=>v)})
					}
				})
			},
		}
	}
</script>
