<template>
	<view style="padding: 3px;">
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 2px;margin-top: 5px;">
			<text style="align-self: center;font-size: 35rpx;color: darkslategray;">交验单号：</text>
			<text style="align-self: center;font-size: 35rpx;word-wrap: break-word;width: 200px;font-weight: bold;">{{deliverDtlMd.deliverNo}}</text>
		</view>
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 2px;">
			<text style="align-self: center;font-size: 35rpx;color: darkslategray;">物料号：</text>
			<text style="align-self: center;font-size: 35rpx;word-wrap: break-word;width: 200px;font-weight: bold;">{{deliverDtlMd.materialCode}}</text>
		</view>
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 2px;margin-top: 5px;margin-bottom: 5px;">
			<text style="align-self: center;font-size: 35rpx;color: darkslategray;">物料名称：</text>
			<text style="align-self: center;font-size: 35rpx;word-wrap: break-word;width: 200px;font-weight: bold;">{{deliverDtlMd.materialName}}</text>
		</view>
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 2px;">
			<text style="align-self: center;font-size: 35rpx;color: darkslategray;">规格型号/图号：</text>
			<text style="align-self: center;font-size: 35rpx;word-wrap: break-word;width: 200px;font-weight: bold;">{{deliverDtlMd.materialSpec}}</text>
		</view>
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 2px;">
			<text style="align-self: center;font-size: 35rpx;color: darkslategray;">交验单数量：</text>
			<text style="align-self: center;font-size: 40rpx;font-weight: bold;">{{deliverDtlMd.sumQty}}</text>
		</view>
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 2px;">
			<text style="align-self: center;font-size: 35rpx;color: darkslategray;">已质检数量：</text>
			<text style="align-self: center;font-size: 40rpx;font-weight: bold;color: blue;">{{deliverDtlMd.sumCheckQty}}</text>
		</view>
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 2px; ">
			<text style="align-self: center;font-size: 35rpx;color: darkslategray;width: 230rpx;">BN/SN码：</text>
			<input class="uni-input" style="margin-right: 5px;font-size: 40rpx;font-weight: bold;" v-model="bnSnCode" :focus="foucusIndex === 0" placeholder="请输BN/SN码" />
		</view>
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 2px;">
			<text style="align-self: center;font-size: 35rpx;color: darkslategray;width: 230rpx;">合格数量：</text>
			<input class="uni-input" type="number" style="margin-right: 5px;color: blue;font-size: 40rpx;font-weight: bold;" v-model="checkOkQty" placeholder="请输合格数量" />
		</view>
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 2px;">
			<text style="align-self: center;font-size: 35rpx;color: red;width: 230rpx;">不合格数量：</text>
			<input class="uni-input" type="number" style="margin-right: 5px;color: red;font-size: 40rpx;font-weight: bold;" v-model="checkNgQty" placeholder="请输不合格数量" />
		</view>
		<button type="primary" style="margin-top: 20px;" @click="resetCondition">重   置</button>
		<button type="primary" style="margin-top: 20px;" @click="submitResult">质检结果&#8194;==>>&#8194;快速出库过账</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				deliverDtlMd: {},
				bnSnCode: '',
				checkOkQty: 0,
				checkNgQty: 0,
				foucusIndex: 0
			}
		},
		onUnload() {
			
		},
		onLoad() {
			uni.$once('sendDeliverDtlData', (data) => {
				this.deliverDtlMd = data
				this.checkOkQty = data.sumQty - data.sumCheckQty
			})
		},
		methods: {
			async submitResult() {
				if(this.isEmptyStr(this.bnSnCode)) {
					uni.showToast({
						title: 'BN/SN码不能为空！',
						icon: 'none',
						duration: 1000
					})
					return;
				}
				if(Number(this.checkOkQty) <= 0 && Number(this.checkNgQty) <= 0) {
					uni.showToast({
						title: '质检合格数量和不合格数量，至少需要输入一项！',
						icon: 'none',
						duration: 1000
					})
					return;
				}
				if((Number(this.checkOkQty) + Number(this.checkNgQty) + this.deliverDtlMd.sumCheckQty) > this.deliverDtlMd.sumQty) {
					uni.showToast({
						title: '质检合格数量+不合格数量 不能大于未质检数量。录入错误！',
						icon: 'none',
						duration: 1000
					})
					return;
				}
				let tmpMd = this.deliverDtlMd;
				tmpMd.DeliverNo = this.deliverNo;
				tmpMd.MaterialSpec = this.materialSpecCode;
				tmpMd.BnSnCode = this.bnSnCode;
				tmpMd.CheckOkQty = this.checkOkQty;
				tmpMd.CheckNgQty = this.checkNgQty;
				let parm = {
					url : '/business/QaInspectRecord/InspectOneClickOutStore',
					data: tmpMd,
					method: 'POST',
					isHaveToken : true
				}
				let retData = await getApp().RequestData(parm)
				if(retData.isSuccess) {
					if(retData.data.code == 200) {
						uni.navigateBack({
							url: '/pages/Inspect/FastOutStoreInspectDtl',
							success: () => {
								uni.$emit('CallSapDeliverDtlQueryFunc',null);
							}
						});
					}
					else {
						uni.showToast({
							title: '提交数据失败！' + retData.data.msg,
							icon: 'none',
							duration: 1000
						})
					}
				}
				else {
					uni.showToast({
						title: '接口异常！' + retData.retMsg,
						icon: 'none',
						duration: 1000
					})
				}
			},
			isEmptyStr(s) {
				if (s == undefined || s === '') {
					return true
				}
				return false
			},
			foucusChange0(event) {
				let str = event.detail.value
				if(str.length !== 0) {
					this.foucusIndex = 1
				}
			},
			foucusChange1(event) {
				let str = event.detail.value
				if(str.length !== 0) {
					this.foucusIndex = 2
				}
			},
			resetCondition() {
				this.bnSnCode = ''
				this.foucusIndex = 1
				setTimeout(() => {
					this.foucusIndex = 0;
				}, 150)
				this.checkOkQty = this.deliverDtlMd.sumQty - this.deliverDtlMd.sumCheckQty
				this.checkNgQty = 0
			}
		}
	}
</script>

<style lang="scss">
	@import '@/common/uni-nvue.css';
</style>