<template>
	<view class="stock-check-detail-page">
		<NavBar :title="$t('库存盘点')"></NavBar>
		<view class="container">
			<view class="title">
				{{list[0].ml001}}|{{list[0].materialName}}
			</view>
			<view class="detail">
				<view class="card" v-for="(item, index) in list" :key="index">
					<view class="info">
						<view class="item inventory-info">
							{{$t('库房/储位')}}：{{item.warehouse}}|{{item.location}}
							<view class="batch-info" v-if="item.batchNo">
								{{$t('批次号')}}：{{item.batchNo}}
							</view>
						</view>
						<view class="item inventory-data">
							{{$t('库存数')}}：{{item.stockQuantity || 0}}
						</view>
					</view>
					<view class="physical-inventory">
						<view>
							{{$t('盘点数')}}：
						</view>
						<uni-easyinput v-model="item.physicalQuantity" type="number" trim="all"
							:placeholder="$t('请输入盘点数')" @change="handleChange($event, item, index)" />
					</view>
				</view>
			</view>
		</view>
		<view class="footer">
			<button class="sumbit-btn" @click="handleSumbit">{{$t('确认')}}</button>
		</view>
	</view>
	</view>
</template>

<script>
	import i18n from '@/lang/index';
	export default {
		data() {
			return {
				list: ""
			}
		},
		onLoad(option) {
			if (option.list) {
				this.list = JSON.parse(decodeURIComponent(option.list));
			};
		},
		methods: {
			handleChange(e, row, index) {
				// if (index == 0) {
					// if(e > row.stockQuantity) {
					// 	this.$u.toast(i18n.t('盘点数不能大于库存数'));
					// }
				// } else {
				// 	row.stockQuantity = e;
				// }
			},
			handleSumbit() {
				// if (this.list[0]['physicalQuantity'] > this.list[0]['stockQuantity']) {
				// 	return this.$u.toast(i18n.t('盘点数量不能大于库存数量'));
				// }
				let pages = getCurrentPages();
				// 2. 上一页面实例
				// 注意是length长度，所以要想得到上一页面的实例需要 -2
				// 若要返回上上页面的实例就 -3，以此类推
				let prevPage = pages[pages.length - 2];
				// 3. 给上一页面实例绑定getValue()方法和参数（注意是$vm）
				prevPage.$vm.getDetailValue(this.list);
				// 4. 返回上一页面
				uni.navigateBack({
					delta: 1 // 返回的页面数
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.stock-check-detail-page {
		.container {
			.title {
				font-size: 32rpx;
				font-weight: bolder;
				padding-top: 24rpx;
				padding-left: 24rpx;
			}

			.detail {
				width: calc(100% - 40rpx);
				margin: 20rpx;
				padding: 20rpx;
				background-color: #f1f1f3;
				border-radius: 12rpx;

				.card {
					padding: 24rpx;
					margin-bottom: 24rpx;
					box-sizing: border-box;
					background-color: #ffffff;
					border-radius: 12rpx;

					.info {
						display: flex;
						justify-content: space-between;
						align-items: center;
						margin-bottom: 24rpx;

						.item {
							text-align: left;
						}
						
						.batch-info {
							font-size: 24rpx;
							color: #666;
							margin-top: 8rpx;
						}
					}

					.physical-inventory {
						display: flex;
						justify-content: space-between;
						align-items: center;
					}
				}
			}
		}

		.footer {
			position: fixed;
			bottom: 0;
			width: 100%;
			height: 150rpx;
			padding: 24rpx;
			background-color: #ffffff;

			.sumbit-btn {
				width: 300rpx;
			}
		}
	}
</style>