<style lang="scss">
	.container{
		height:100%;
		background:#f6f6f6;

		scroll-view{
			flex-grow: 1;
			height:1rpx;
			.card{
				margin-top:0;
				.name{
					display:flex;
					align-items: center;
					margin-bottom:20rpx;
					text{
						&:first-child{
							flex-shrink: 0;
							color:#fff;
							font-size:20rpx;
							border-radius: 0px 20rpx 0px 20rpx;
							background:#10C176;
							width:80rpx;
							height:40rpx;
							text-align: center;
							line-height: 40rpx;
							margin-right:10rpx;
						}
						&:nth-child(2){
							flex-grow: 1;
							display:flex;
							align-items: center;
							font-weight: bold;
							margin-right:20rpx;
						}
					}
				}
				.company{
					text{
						font-size:24rpx;
						&:first-child{
							color:#FBA83C;
							margin-right:16rpx;
						}
						&:nth-child(2){
							color:#999;
						}
					}
				}
			}
		}
	}
</style>
<template>
	<view class="container flex">
		<d-search v-model="searchVal.search" @search="clean();search()"/>

		<scroll-view scroll-y>
			<view class="card" v-for="(v,k) in list" :key="k" @click="toSpecs(v)">
				<view class="name">
					<text>{{v.goodsType}}</text> <text>{{v.substanceName}}</text> <text class="plant-youbian"/>
				</view>
				<view class="company">
					<text>{{v.goodsDetailType}}</text> <text>{{v.supplier}}</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'
export default {
	data(){
		return{
			searchVal:{
				baseId: this.$store.state.plantBaseInfoId,
				pageNo:1,
				flagGroupBy:'y',
				pageSize:6,
				search:"",
			},
			list:[],
			total:0,
			eventChannel:null,
		}
	},
	onLoad(){
		this.eventChannel=this.getOpenerEventChannel()
		this.search()
	},
	methods:{
		clean(){
			this.list=[]
			this.total=0
			this.searchVal.pageNo=1
		},
		async search(){
			var res=await request("/api/Inventory/queryCollectingList",{
				method:"post",
				body: this.searchVal
			})
			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,
				})
			}
		},
		toSpecs(e){
			uni.navigateTo({
				url:`/pages/massif/agrSpecs?id=${e.id}`,
				events:{update: e=>{
					this.eventChannel.emit("addSpecs", e)
					uni.navigateBack()
				}},
				success(res){
					res.eventChannel.emit('detail',e)
				}
			})
		},
	}
}
</script>
