<template>
	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='库存统计' bgColor='transparent'></cus-header>
		<image class="topbg" :src="imgBase+'storage/home_bg.png'" mode="widthFix"></image>
		<div class="search">
			<u--input
				placeholder="请输入商品名称"
				border="none"
				prefixIcon="search"
				prefixIconStyle="font-size: 24px;color: #86909C"
				v-model="params.itemName"
			></u--input>
			<div class="btn" @tap="search">搜索</div>
		</div>
		<div class="select">
			<div class="left">选择仓库</div>
			<div class="right" @tap="selectWarehouse">
				<text v-if="warehouseName">{{warehouseName}} ></text>
				<div class="tip" v-else>请选择仓库<u-icon name="arrow-right" color="#198CFF" size="32" style="margin-left: 10rpx;"></u-icon></div>
			</div>
		</div>
		<div class="list" :style="{'height':'calc(100vh - '+(mt+125)+'px)'}">
			<template v-if="list.length">
				<u-list @scrolltolower="scrolltolower">
					<u-list-item v-for="(good, index) in list" :key="good.id">
						<div class="item">
							<div class="title">{{good.item.itemName}}</div>
							<div class="info">
								<div>
									规格信息：<span v-if="good.itemSku.skuCode">{{good.itemSku.skuCode+'/'}}</span>
									<span v-if="good.itemSku.skuName">{{good.itemSku.skuName}}</span>
								</div>
								<div>库存：<span :class="{'zero':good.quantity=='0'}" style="font-size: 28rpx;font-weight: bold;">{{good.quantity||''}}</span></div>
							</div>
						</div>
					</u-list-item>
				</u-list>
			</template>
			<template v-else>
				<page-empty :height="'calc(100vh - 200px)'"></page-empty>
			</template>
		</div>
		<u-picker title="仓库" :show="warehouseShow" :columns="warehouseList" keyName="warehouseName" 
			@cancel="warehouseShow=false" @confirm="warehouseConfirm">
		</u-picker>
	</view>
</template>

<script>
	import pageEmpty from '@/components/pageEmpty/index.vue'
	export default {
		components:{ pageEmpty },
		data(){
			return {
				params:{
					page:1,
					limit:10,
					itemName:'',
					warehouseId:'',
				},
				list:[],
				warehouseName:'',
				warehouseShow:false,
				warehouseList:[],
				isOver:false
			}
		},
		onLoad() {
			this.getList();
		},
		methods:{
			selectWarehouse(){
				this.warehouseShow = true;
				this.$nextTick(()=>{
					this.$api.get('/wms/warehouse/page').then(res=>{
						if(res.data.code===0){
							this.warehouseList = [res.data.data.list];
						}else this.$showToast(res.data.msg)
					})
				})
			},
			warehouseConfirm(e){
				this.params.warehouseId = e.value[0].id;
				this.warehouseName = e.value[0].warehouseName;
				this.warehouseShow = false;
				this.initList();
			},
			getList(){
				this.$api.get('/wms/inventory/boardList/warehouse',this.params).then(res=>{
					if(res.data.code===0){
						if(this.list.length<res.data.data.total){
							this.params.page++;
							this.list = [...this.list,...res.data.data.list];
						}else this.isOver = true
					}else this.$showModal(res.data.msg)
				});
			},
			search(){
				this.initList();
			},
			initList(){
				this.params.page = 1;
				this.list = [];
				this.isOver = false;
				this.getList();
			},
			scrolltolower(){
				if(this.isOver) return
				this.getList();
			},
		}
	}
</script>

<style scoped lang="less">
	.page{
		padding: 0 24rpx 20rpx;
		background: #F4F8FB;
		box-sizing: border-box;
		
		.topbg{
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 0;
		}
		
		.search{
			width: 100%;
			height: 84rpx;
			padding: 6rpx 6rpx 6rpx 30rpx;
			box-sizing: border-box;
			background: #FFFFFF;
			border-radius: 40rpx;
			border: 1rpx solid #198CFF;
			position: relative;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.btn{
				width: 118rpx;
				height: 68rpx;
				background: #198CFF;
				border-radius: 40rpx;
				border: 1rpx solid #198CFF;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #FFFFFF;
				line-height: 68rpx;
				text-align: center;
				letter-spacing: 2rpx;
			}
		}
	
		.select{
			width: 100%;
			background: #FFFFFF;
			border-radius: 16rpx;
			padding: 24rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-between;
			position: relative;
			margin-top: 20rpx;
			.left{
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #1D2129;
				line-height: 42rpx;
			}
			.right{
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 30rpx;
				color: #4E5969;
				line-height: 42rpx;
				text-align: right;
				.tip{
					display: flex;
					align-items: center;
				}
			}
		}
		
		.list{
			width: 100%;
			margin-top: 20rpx;
			background: #FFFFFF;
			position: relative;
			border-radius: 16rpx 16rpx 0rpx 0rpx;
			::v-deep .u-list{
				width: 100%;
				height: 100% !important;
			}
			::v-deep .u-list-item{
				width: 100%;
			}
			.item{
				width: 100%;
				padding: 36rpx 24rpx;
				box-sizing: border-box;
				box-shadow: inset 0rpx -1rpx 0rpx 0rpx #ECECEC;
				.title{
					font-family: PingFang-SC, PingFang-SC;
					font-weight: bold;
					font-size: 30rpx;
					color: #1D2129;
					line-height: 30rpx;
					text-align: left;
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
				}
				.info{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 28rpx;
					&>div{
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #86909C;
						line-height: 24rpx;
						text-align: left;
						span{
							color: #4E5969;
							&.zero{
								color: #FA415E;
							}
						}
					}
				}
			}
		}
	}
</style>