<template>
	<view class="container">
		<u-input class="input" v-model="barCode" border type="text" placeholder="请扫描整件条码"
			placeholder-style="color:#666666" />
		<u-input class="input" v-model="wareHouse" border type="text" placeholder="请扫描货位"
			placeholder-style="color:#666666" />
		<view class="content">
			<view class="item">
				<span class="itemLabel">货位名称：</span>
				<span class="itemValue">{{ result.outLocationName }}</span>
			</view>
			<view class="item">
				<span class="itemLabel">商品编号：</span>
				<span class="itemValue">{{ result.goodNo }}</span>
			</view>
			<view class="item">
				<span class="itemLabel">商品名称：</span>
				<span class="itemValue">{{ result.goodName }}</span>
			</view>
			<view class="item">
				<span class="itemLabel">规格：</span>
				<span class="itemValue">{{ result.specifications }}</span>
			</view>
			<view class="item">
				<span class="itemLabel">厂家：</span>
				<span class="itemValue">{{ result.factory }}</span>
			</view>
			<view class="item">
				<span class="itemLabel">产地：</span>
				<span class="itemValue">{{ result.areaCode }}</span>
			</view>
			<view class="item">
				<span class="itemLabel">件装量：</span>
				<span class="itemValue">{{ result.packageQty }} 单位：{{ transUnit(result.unit) }}</span>
			</view>
			<view class="item">
				<span class="itemLabel">拣货数量：</span>
				<span class="itemValue">{{ result.pickQty }}</span>
			</view>
			<view class="item">
				<span class="itemLabel">批号：</span>
				<span class="itemValue">{{ result.batchNo }}</span>
			</view>
			<view class="item">
				<span class="itemLabel">显示效期：</span>
				<span class="itemValue">{{ result.productionDate }} —— {{ result.expiredDate }}</span>
			</view>
		</view>
		<div>
			<view class="footer">
				<u-button type="primary" @click="show = true">冲红</u-button>
				<u-button type="success" @click="sure()">确认</u-button>
			</view>
		</div>
		<u-popup v-model="show" mode="center" width="80%" height="200px" border-radius="14">
			<view style="display: flex;align-items: center;padding: 0 40rpx;margin:40rpx 0rpx">
				<span style="width: 100rpx;">工号</span>
				<u-input v-model="username" type="text" :border="true" />
			</view>
			<view style="display: flex;align-items: center;padding: 0 40rpx;">
				<span style="width: 100rpx">密码</span>
				<u-input v-model="password" type="password" :border="true" />
			</view>
			<view class="confrim-btn">
				<u-button type="primary" style="width:200rpx; margin-top: 40rpx" @click="isHave()">确定</u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				result: {},
				wareHouse: '',
				barCode: '',
				password: '',
				username: '',
				dicOptions: []
			}
		},
		onLoad(e) {
			this.result = JSON.parse(e.list)
			this.getDic()
		},

		methods: {
			getDic() {
				this.$u.api.getByDicType().then(res => {
					this.dicOptions = res.data;
				});
			},
			transUnit(unit) {
				for (let dic in this.dicOptions) {
					if (this.dicOptions[dic].dictValue === unit) {
						return this.dicOptions[dic].dictLabel;
					}
				}
			},
			isHave() {
				if (this.username && this.password) {
					this.$u.api.pickingManage.loginConfirm({
						username: this.username,
						password: this.password
					}).then((res) => {
						if (res.code === 200) {
							this.$u.route({
								url: 'pages/allPiece/rushRed',
								type: 'navigateTo',
								params: {
									list: JSON.stringify(this.result)
								}
							})
						} else {
							this.$u.toast(res.msg)
						}
						this.show = false
					})
				} else {
					this.$u.toast('请输入账号或密码')
				}

			},
			// 冲红
			rushRed() {

			},
			checkOutPick() {
				this.$u.api.pickingManage.checkOutPick({
					taskType: 1,
					barCode: this.barCode
				}).then(res => {
					console.log(res)
					if (res.code === 200) {
						//  进入索取页面
						if (res.data.pickType === 200) {
							// 整件
							this.$u.route({
								url: 'pages/allPiece/index',
								type: 'navigateTo',
								params: {
									list: JSON.stringify(res.data.taskStaticList)
								}
							})
						}
						//进入拣货页面
						if (res.data.pickType === 800) {
							// 整件
							this.$u.route({
								url: 'pages/allPiece/picking',
								type: 'navigateTo',
								params: {
									list: JSON.stringify(res.data.businOutPickDTaskVo)
								}
							})
						}
					} else {
						this.$u.toast(res.msg)
					}

				});
			},
			sure() {
				console.log(this.result)
				if (this.wareHouse) {
					this.$u.api.pickingManage.pickCaseTaskConfirm({
						...this.result,
						locationCode: this.wareHouse
					}).then((res) => {
						if (res.code === 200) {
							this.checkOutPick()
						} else {
							this.$u.toast(res.msg)
						}
					})
				} else {
					this.$u.toast('请先扫描货位')
				}
			},
		}
	}
</script>

<style lang="scss">
	.container {
		width: 90%;
		height: calc(100vh - 120rpx);
		margin: 20rpx auto;
		border: 0.5px solid #333333
	}

	.input {
		width: 90%;
		margin: 20rpx auto;
	}

	.content {
		width: 90%;
		margin: 20rpx auto;
	}

	.item {
		display: flex;
		align-items: center;
		font-size: 28rpx;
		line-height: 50rpx;

		.itemLabel {
			color: #555555;
			width: 160rpx;
			text-align: right;
		}

		.itemValue {
			color: #333333;
		}
	}

	.desktop {
		border-top: 0.5px solid #333333;
		border-left: 0.5px solid #333333;
		display: flex;
		flex-wrap: wrap;
		width: 70%;
		margin: 0 auto;
	}

	.desktopItem {
		width: 50%;
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: center;
		height: 140rpx;
		border-bottom: 0.5px solid #333333;
		border-right: 0.5px solid #333333;
	}

	.desktopLabel {
		text-align: center;
	}

	.desktopValue {
		text-align: center;
		color: #0000FF;
		;
	}

	.footer {
		width: 90%;
		margin: 0 auto;
		margin-top: 40rpx;
		display: flex;
		justify-content: space-between;
	}
</style>
