<style lang="scss" scoped>
	.farm-record{
		display:flex;
		flex-direction: column;
		height: 100%;
		&>.head{
			flex-shrink: 0;
			display:flex;
			align-items: center;
			margin:30rpx;
			image{
				height:32rpx;
				width:32rpx;
				margin-right:14rpx;
			}
			text{
				font-size:24rpx;
				&.title{
					color:#999;
					margin-right:auto;
				}
				&.add{
					color:#10C176;
				}
			}
		}
		scroll-view{
			flex-grow: 1;
			height:1rpx;
			.card{
				margin-top:0;
				.name{
					display:flex;
					align-items: center;
					text{
						&:first-child{
							flex-shrink: 0;
							color:#fff;
							background:#10C176;
							font-size:20rpx;
							border-radius: 8rpx 40rpx 8rpx 40rpx;
							width:80rpx;
							text-align: center;
							height:40rpx;
							line-height: 40rpx;
							margin-right:12rpx;
						}
						&:nth-child(2){
							flex-grow: 1;
						}
						&:nth-child(3){
							flex-shrink: 0;
							color:#10C176;
							font-weight: bold;
							font-size:32rpx;
							margin-left:10rpx;
						}
					}
				}
				.info{
					margin-top:20rpx;
					border-top:2rpx solid rgba(216, 216, 216, 0.4);
					padding-top:20rpx;
					display:flex;
					justify-content: space-between;
					text{
						color:#999;
						font-size:24rpx;
					}
				}
				.detail{
					display:flex;
					align-items: center;
					text{
						color:#999;
						font-size:24rpx;
						&:first-child{
							flex-shrink: 0;
							color:#fff;
							background:#10C176;
							font-size:20rpx;
							border-radius: 8rpx 40rpx 8rpx 40rpx;
							width:80rpx;
							text-align: center;
							height:40rpx;
							line-height: 40rpx;
							margin-right:12rpx;
						}
						&:nth-child(2){
							margin-right:auto;
						}
					}
				}
			}
		}
	}
</style>
<template>
	<view class="farm-record">
		<view class="head">
			<image mode="aspectFit" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAXhJREFUOE+dk7FLw1AQxr+LbSyInQuODiIW+hc4iZP/QCfBpXmmUHR26eRopdT0ZRLX7k7FybmgKAUJjrZriTqY2Jy80IQ0aik5eMO7++7H4953hFRYlrWlaZoAcEBEG6rMzG8AboMgkKZpviRbKLo0m81cqVQ6B3BKRLk0eAb6JqIWgDPDMHyVCwHtdnu1UCj0mXn3r8Z0jpnvPc/bbzQaXyHAtm0JwFimOdIwsxRCHFOn09nJ5/OPAFaiYrVaxWAwgOM4i5hT3/crJKVsEdFJUlmr1UKAOouCmS/Jtu0hgO2MgKECfABYywIA8KkALoD1jIB3BXgCUE4DRqMRxuPx3Ahc150bLDM/K8CFMk9SqX6hWCz+mt9kMkGv14vzQRC0qNvtljVNe0h+45J+mBJRJTSSlPKKiMwlG0MZM1tCiHpsZV3X+0SUzcrRPui6rl5yBED75zUBM197nldXexAvU1I8s/YhgD0Am7PaK4A7Zr4RQijjxfEDDjS1T8RMzc4AAAAASUVORK5CYII="/>
			<text class="title">农资使用情况</text>
			<text class="add" @click="toAdd">+添加农事</text>
		</view>
		<scroll-view scroll-y @scrollotower="search">
			<view class="card" v-for="(v,k) in list" :key="k">
				<template v-if="v.inputName">
					<view class="name">
						<text>{{v.type}}</text> <text>{{v.inputName}}</text> <text>{{v.inputTotal||0}}{{v.unit}}</text>
					</view>
					<view class="info">
						<text>负责人：{{v.principal}}</text> <text>记录时间：{{new Date(v.time).format('yyyy-MM-dd')}}</text>
					</view>
				</template>
				<view v-else class="detail">
					<text>{{v.type}}</text> <text>负责人：{{v.principal}}</text> <text>记录时间：{{new Date(v.time).format('yyyy-MM-dd')}}</text>
				</view>
			</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 {
	name:"farmRecord",
	props:{
		plotId:{
			type:String,
			default:""
		}
	},
	data(){
		return{
			searchVal:{
				search:"",
				pageNo:1,
				pageSize:6,
				PlantBaseInfoId: this.$store.state.plantBaseInfoId,
				startTime:"",
				endTime:"",
			},
			total:0,
			list:[],
		}
	},
	created(){
		this.search()
	},
	methods:{
		toAdd(){
			uni.navigateTo({
				url:`/pages/massif/add_farming?plotId=${this.plotId}`,
				events:{update: e=>{
					this.total=0
					this.list=[]
					this.searchVal.pageNo=1
					this.search()
				}}
			})
		},
		async search(){
			if(this.total==0 || this.list.length<this.total){
				var res=await request("/api/plantFarming/listFarmByPlotId",{
					params: {
						...this.searchVal,
						plotId: this.plotId,
					}
				})
				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,
					})
				}
			}
		}
	}
}
</script>