<style lang="less">
	.container{
		height:100%;
		background:#f6f6f6;
		display:flex;
		flex-direction: column;
		&>.d-search{
			margin-bottom:-30rpx;
		}
		scroll-view{
			flex-grow: 1;
			height:1rpx;
			.items{
				padding:30rpx 30rpx 0;
				&+.items{
					padding-bottom:30rpx;
				}
			}
			.card{
				margin:0;
				&>.info{
					display:flex;
					&>.u-transition{
						position:relative;
						margin-right:20rpx;
						&:before{
							content:attr(data-type);
							position:absolute;
							z-index: 30;
							top:0;
							left:0;
							border-radius: 20rpx 20rpx 20rpx 0;
							background:rgba(60, 84, 44, 0.5);
							color:#fff;
							padding:6rpx 2rpx;
							min-width:80rpx;
							text-align: center;
						}
					}
					&>.detail{
						flex-grow: 1;
						width:1rpx;
						.name{
							display:flex;
							margin-bottom: 6rpx;
							text{
								&:first-child{
									flex-shrink: 0;
									font-size:20rpx;
									color:#fff;
									background:#10C176;
									height:40rpx;
									width:80rpx;
									line-height: 40rpx;
									text-align: center;
									border-radius: 6rpx;
									margin-right:12rpx;
								}
								&:nth-child(2){
									font-weight: bold;
									flex-grow: 1;
								}
							}
						}
						.batch,.recovery{
							font-size:24rpx;
							margin-bottom:6rpx;
							display:flex;
							align-items: center;
							justify-content: space-between;
							text{
								color:var(--c);
							}
						}
						.mu{
							display:flex;
							align-items: center;
							&>text.area{
								color:#10C176;
								font-size:32rpx;
								font-weight: bold;
								&:after{
									content:"亩";
								}
							}
							&>.farm{
								font-size:22rpx;
								color:#10C176;
								height:40rpx;
								line-height: 40rpx;
								margin-left:18rpx;
								background: rgba(16, 193, 119, 0.1);
								padding:0 6rpx;
							}
							button{
								margin:-20rpx 0 -20rpx auto!important;
								padding:20rpx;
								height: auto;
    							background: transparent;
							}
						}
					}
				}
				&>.date{
					border-top:2rpx solid rgba(216, 216, 216, 0.5);
					margin-top:6rpx;
					padding-top:12rpx;
					display:flex;
					align-items: center;
					text{
						flex-shrink: 0;
						color:#999;
						font-size:24rpx;
						margin-right:auto;
						&.over{
							background:#F7F7F7;
							border-radius: 8rpx;
							height:48rpx;
							line-height: 48rpx;
							padding:0 20rpx;
							margin:0 0 0 auto;
						}
					}
					button{
						margin:0 0 0 20rpx;
						color:rgba(var(--c),1);
						background:rgba(var(--c),0.15);
						height:48rpx;
						font-size:24rpx;
						padding:0 16rpx;
						min-width:100rpx;
					}
				}
			}
		}
	}
</style>
<template>
	<view class="container">
		<d-search v-model="searchVal.search" @search="clean();search()" placeholder="输入地块名称或品种搜索"/>
		<scroll-view scroll-y @scrolltolower="search">
			<view class="items" v-for="(v,k) in list" :key="k">
				<view class="card">
					<view class="info" @click="$u.route({url:'/pages/massif/mana/index',params:{id:v.plotId}})">
						<u-image :data-type="v.plantType" radius="20rpx" width="170rpx" height="140rpx" mode="aspectFill" :src="`${host}/${v.images}`">
							<text slot="error" style="font-size:45rpx;" class="plant-xiaopangchetupianjiazaishibai"/>
						</u-image>
						<view class="detail">
							<view class="name">
								<text>{{v.plantStandard}}</text> <text class="over">{{v.varietyName}}</text> <text class="plant-youbian"/>
							</view>
							<view class="batch over" style="--c:#999;">种植批次号:{{v.plantBatch}}</view>
							<view class="recovery" >
								<text class="over" style="margin-right:20rpx;">{{v.plotName}}</text>
								<text style="--c:#FFC760;flex-shrink: 0;">已采收:{{v.harvested}}kg</text>
							</view>
							<view class="mu">
								<text class="area">{{v.plantArea}}</text>
								<text class="farm">农事操作{{v.farmNum||0}}次</text>
							</view>
						</view>
					</view>
					<view class="date">
						<text>预估采收日期:{{v.harvestTime}}</text>
						<button v-if="v.status==1" class="cu-btn" style="--c:255, 196, 87;" @click.stop="finishPlant(k)">结束种植</button>
						<text v-else-if="v.status==2" class="over">已结束</text>
					</view>
				</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.js'
import dSearch from '../../uni_modules/d-search/components/d-search/d-search.vue'
export default {
  components: { dSearch },
	data(){
		return{
			host:host('imgUrl'),
			list:[],
			total:0,
			searchVal:{
				pageNo:1,
				pageSize:6,
				search:"",
			},
		}
	},
	onLoad(){
		this.search()
	},
	methods:{
		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/plantPlan/list',{
					params: {
						...this.searchVal,
						baseId: this.$store.state.baseInfo.id,
					}
				})
				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,
					})
				}
			}
		},
		finishPlant(index){
			uni.showModal({
				title:"提示",
				content:"确定结束种植!",
				success: async e=>{
					if(e.confirm){
						var res=await request("/api/plantPlan/finishPlant",{
							params:{plantPlanId:this.list[index].id}
						})
						if(res.statu){
							uni.showToast({title:"结束成功!",duration:1500})
							if(this.list.length>this.searchVal.pageSize+2){
								this.list.splice(index,1)
							}else{
								this.clean()
								this.search()
							}
						}else{
							uni.showModal({
								title:"提示",
								content:res.msg||"结束种植失败!",
								showCancel:false,
							})
						}
					}
				}
			})
		},
	},
}
</script>