<style lang="scss" scoped>
	.recovery{
		height:100%;
		display:flex;
		flex-direction: column;
		&>.dateRange{
			flex-shrink: 0;
			display: flex;
			align-items: center;
			margin:30rpx;
			text{
				&.plant-youbian{
					display: flex;
					align-items: center;
					flex-direction: row-reverse;
					justify-content: space-between;
					background:#fff;
					height:48rpx;
					font-size:24rpx;
					color:#333;
					border-radius: 8rpx;
					padding:0 10rpx;
					min-width:226rpx;
					box-sizing: border-box;
					&:before{
						transform: rotate(90deg);
					}
					&.noDate{
						color:#999;
					}
				}
				&:nth-child(2){
					color:#999;
					padding:0 28rpx;
				}
			}
		}

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

			.card{
				margin-top:0;
				&>.content{
					display:flex;
					border-bottom:2rpx solid rgba(216, 216, 216, 0.2);
					padding-bottom:10rpx;
					margin-bottom:20rpx;
					.u-transition{
						flex-shrink: 0;
						margin-right:20rpx;
					}
					.info{
						flex-grow: 1;
						width:1rpx;
						.title{
							display: flex;
							align-items: center;
							margin-bottom:15rpx;
							text{
								&.name{
									font-weight: bold;
								}
								&.tab{
									flex-shrink: 0;
									color:#fff;
									background:#10C176;
									height:36rpx;
									line-height: 36rpx;
									border-radius: 40rpx;
									padding:0 10rpx;
									font-size:24rpx;
									margin:0 auto 0 20rpx;
									min-width:60rpx;
									text-align: center;
								}
								&.plant-youbian{
									flex-shrink: 0;
									margin-left:20rpx;
								}
							}
						}
						.batch{
							font-size:24rpx;
							margin-bottom:6rpx;
						}
						.total{
							color:#10C176;
							font-size:24rpx;
							font-weight: bold;
							margin-bottom:6rpx;
						}
						.surplus{
							color:#FCA606;
							font-size:24rpx;
						}
					}
				}
				&>.foot{
					display:flex;
					align-items: center;
					justify-content: space-between;
					&>text{
						color:#999;
						font-size:24rpx;
					}
					button{
						background:#EEFBF5;
						border-radius: 4rpx;
						color:#10C176;
						font-size:24rpx;
						padding:0;
						height:48rpx;
						width:96rpx;
						&:before{
							font-size:40rpx;
						}
					}
				}
			}
		}
		.u-popup{
			flex:0;
		}
	}
</style>
<template>
	<view class="recovery">
		<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">
				<view class="content">
					<u-image width="170rpx" height="140rpx" radius="6rpx" mode="aspectFill" :src="`${host}/${v.images}`">
						<text slot="error" style="font-size:45rpx;" class="plant-xiaopangchetupianjiazaishibai"/>
					</u-image>
					<view class="info">
						<view class="title">
							<text class="name over">{{v.plantName}}</text>
							<text class="tab">红籽</text>
							<text class="plant-youbian"/>
						</view>
						<view class="batch">收获批次号：A000001</view>
						<view class="total">{{v.totalNum}}kg</view>
						<view class="surplus">剩余：{{v.harvestNum}}kg</view>
					</view>
				</view>
				<view class="foot">
					<text class="date">采收日期:{{v.harvestTime}}</text>
					<button class="cu-btn plant-jinrongjiaoyi" v-if="v.harvestNum>0" @click="toAddTransaction(v)">交易</button>
				</view>
			</view>
			<u-empty v-if="list.length==0" text="为查询到相关信息" width="70%" icon="/static/noData.png"/>
		</scroll-view>
	</view>
</template>
<script>
import request,{host} from '@/common/request'
export default {
	name:"recovery",
	props:{
		plotId:{
			type:String,
			default:""
		},
		plantId:{
			type:String,
			default:"",
		}
	},
	data(){
		return{
			host:host("imgUrl"),
			searchVal:{
				pageNo:1,
				pageSize:5,
				startTime:"",
				endTime:"",
			},
			list:[],
			total:0,
		}
	},
	created(){
		this.search()

	},
	methods:{
		reSearch(){
			this.clean()
			this.search()
		},
		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/plantHarvest/list",{
					params:{
						...this.searchVal,
						plotId:this.plotId,
						plantScheduleId: this.plantId,
					}
				})
				if(res.statu){
					this.list=this.list.concat(res.data.records)
					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,
					})
				}
			}
		},
		toAddTransaction(e){
			uni.navigateTo({
				url:"/pages/massif/add_transaction",
				events:{update:()=>{
					this.clean()
					this.search()
					this.$emit("trigger",e.id)
				}},
				success(res){
					res.eventChannel.emit('detail',e)
				}
			})
		},
	}
}
</script>
