<template>
	<view class="sockQuery flex flex_column">
		<swiper class="list-box">
			<swiper-item class="swiper-item" style="height: 100%;width: 100%;overflow: hidden;">
				<scroll-view scroll-y style="height: 100%;width: 100%;overflow: auto;" @scrolltolower="onreachBottom">
					 <view
					  class="list-item flex align_center justify_between" 
					 v-for="item in list" 
					 :key="item.id"
					 @click="detail(item)"
					 >
					 	<view>
					 		<view class="vin-text">
					 			<text>{{item.checkFinishDate}}</text>
					 		</view>
					 		<view class="time-text">
					 			{{item.checkFinishPersonName}}
								<view>{{item.stockCheckNo}}</view>
					 		</view>
					 	</view>
						<view>
							￥{{item.totalProfitLossCost}}
						</view>
					 </view>
					 <view style="padding: 20upx;">
						 <u-empty :src="`/static/nodata.png`" icon-size="180" :text="noDataText" img-width="120" v-if="list.length==0 && status!='loading'" mode="list"></u-empty>
						 <u-loadmore v-if="(total>=list.length&&list.length)||status=='loading'" :status="status" />
					 </view>
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import { stockCheckQueryPage } from '@/api/stockCheck'
	export default {
		data() {
			return {
				status: 'loading',
				noDataText: '暂无记录',
				pageNo: 1,
				pageSize: 20,
				total: 0,
				list: [],
				shelfSn: ''
			}
		},
		onLoad(opts) {
			this.shelfSn = opts.shelfSn
			this.getList()
		},
		methods: {
			pageInit(){
				this.total = 0
				this.pageNo = 1
				this.list = []
				this.getList()
			},
			detail(item){
				uni.navigateTo({
					url: '/pages/stockCheck/submitStockCheck?stockCheckSn='+item.stockCheckSn+'&type=view'
				})
			},
			// 查询列表
			getList (pageNo) {
			  let _this = this
			  if (pageNo) {
			    this.pageNo = pageNo
			  }
			  // 状态条件
			  let params = {
			    pageNo: this.pageNo,
			    pageSize: this.pageSize,
				checkState: 'FINISH',
				shelfSn: this.shelfSn
			  }
			  this.status = "loading"
			  stockCheckQueryPage(params).then(res => {
				if (res.code == 200 || res.status == 204 || res.status == 200) {
				  if(_this.pageNo>1){
					  _this.list = _this.list.concat(res.data.list || [])
				  }else{
					  _this.list = res.data.list || []
				  }
				  _this.total = res.data.count || 0
				} else {
				  _this.list = []
				  _this.total = 0
				  _this.noDataText = res.message
				}
				_this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
			  })
			},
			// scroll-view到底部加载更多
			onreachBottom() {
				if(this.list.length < this.total){
					this.pageNo += 1
					this.getList()
				}else{
					this.status = "nomore"
				}
			},
		}
	}
</script>

<style lang="less">
.sockQuery{
	width: 100%;
	height: 100vh;
	background: #f8f8f8;
	.search-box{
		padding: 20rpx 30rpx;
	}
	.list-box{
		flex-grow: 1;
		overflow: auto;
	}
	.list-item{
		margin: 20rpx 30rpx;
		border:2rpx solid #f8f8f8;
		box-shadow: 2rpx 2rpx 6rpx #eee;
		border-radius: 20rpx;
		padding: 20rpx 15rpx;
		background: #ffffff;
		> view{
			padding: 0 10rpx;
			&:first-child{
				flex-grow: 1;
				width: 70%;
			}
			&:last-child{
				text-align: right;
				font-weight: bold;
				font-size: 34upx;
				width: 30%;
			}
		}
		.time-text{
			margin-top: 10upx;
			font-size: 24upx;
			color: #999;
			text{
				color: #333;
			}
		}
	}
}
</style>
