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

		scroll-view{
			flex-grow: 1;
			height:1rpx;
			.card{
				margin-top:0;
				&>.info{
					display:flex;
					align-items: center;
					margin-bottom:20rpx;
					text{
						&:first-child{
							flex-shrink: 0;
							font-size:20rpx;
							color:#fff;
							background:#10C176;
							border-radius: 0 20rpx 0 20rpx;
							height:40rpx;
							width:80rpx;
							line-height: 40rpx;
							text-align: center;
							margin-right:16rpx;
						}
						&:nth-child(2){
							font-weight: bold;
						}
						&:nth-child(3){
							flex-shrink: 0;
							color:#999;
							font-size: 20rpx;
							margin-left:6rpx;
						}
						&:nth-child(4){
							margin-left:15rpx;
							flex-shrink: 0;
							color:#10C176;
							font-size: 24rpx;
							margin-left: auto;
						}
					}
				}
				&>.name{
					text{
						&:first-child{
							color:#FBA83C;
						}
						&:nth-child(2){
							color:#999;
							margin-left:22rpx;
						}
					}
				}
				&>.data{
					display:flex;
					align-items: center;
					justify-content: space-between;
					border-top:2rpx solid #D8D8D8;
					margin-top:20rpx;
					padding-top:16rpx;
					text{
						&:first-child{
							color:#999;
							font-size:24rpx;
						}
						&:nth-child(2){
							font-weight: bold;
							&:after{
								content:"("attr(data-unit)")";
								font-weight: normal;
								margin-left:5rpx;
							}
						}
					}
				}
			}
		}
	}
</style>
<template>
	<view class="container flex">
		<d-search v-model="searchVal.search" @search="clean();search()"/>

		<scroll-view scroll-y @scrollotower="search">
			<view class="card" v-for="(v,k) in list" :key="k">
				<view class="info">
					<text>{{v.goodsType}}</text> <text class="over">{{v.substanceName}}</text> <text>({{v.specDescribe}})</text> <text>剩余{{v.surplus}}{{v.unit}}</text>
				</view>
				<view class="name">
					<text>{{v.goodsDetailType}}</text> <text class="over">{{v.supplier}}</text>
				</view>
				<view class="data">
					<text>领用时间：{{new Date(v.operateTime).format("yyyy-MM-dd")}}</text> <text :data-unit="`共${v.equivalentAmount}${v.unit}`">{{v.number}}{{v.packgeUnit}}</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 {
	data(){
		return{
			searchVal:{
				baseId: this.$store.state.plantBaseInfoId,
				userId:"",
				enterpriseId:"",
				flagGroupBy:'n',
				search: "",
				pageNo:1,
				pageSize:6,
			},
			list:[],
			total:0,
		}
	},
	onLoad(options){
		if (this.$store.getters['userInfo'].roleCode=="baseAdmin") {
			this.searchVal.userId = this.$store.getters['userInfo'].id
			this.searchVal.enterpriseId = ''
		} else {
			this.searchVal.enterpriseId = this.$store.getters.userInfo.companyId
			this.searchVal.userId = ''
		}
		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/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,
					})
				}
			}
		},
	}
}
</script>