<template>
	<view>
		<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.bomNo}}</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;">
			<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: 1px;">
			<text style="align-self: center;font-size: 35rpx;color: darkslategray;">交验单数量：</text>
			<text style="align-self: center;font-size: 40rpx;font-weight: bold;">{{deliverDtlMd.qty}}</text>
		</view>
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 1px;">
			<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.checkQty}}</text>
		</view>
		<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;">BN/SN码：</text>
			<input class="uni-input" style="margin-right: 5px;" v-model="bnSnCode" :focus="foucusIndex === 0" @confirm="foucusChange0" placeholder="请输BN/SN码" />
		</view>
		<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>
			<input class="uni-input" type="number" style="margin-right: 5px;" v-model="checkOkQty" :focus="foucusIndex === 1" @confirm="foucusChange1" placeholder="请输合格数量" />
		</view>
		<button type="primary" style="margin-top: 15px;" @click="submitResult">质检结果提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				deliverDtlMd: {},
				bnSnCode: '',
				checkOkQty: '',
				foucusIndex: 0
			}
		},
		onUnload() {
			
		},
		onLoad() {
			uni.$once('sendDeliverDtlData', (data) => {
				this.deliverDtlMd = data
			})
		},
		methods: {
			async submitResult() {
				// let that = this;
				if(this.isEmptyStr(this.bnSnCode)) {
					uni.showToast({
						title: 'BN/SN码不能为空！',
						icon: 'none',
						duration: 1000
					})
					return;
				}
				if(Number(this.checkOkQty) <= 0) {
					uni.showToast({
						title: '未输入质检合格数量！',
						icon: 'none',
						duration: 1000
					})
					return;
				}
				if((Number(this.checkOkQty) + this.deliverDtlMd.checkQty) > this.deliverDtlMd.qty) {
					uni.showToast({
						title: '质检合格数量录入错误，数量不能大于未录入数！',
						icon: 'none',
						duration: 1000
					})
					return;
				}
				let tmpMd = this.deliverDtlMd;
				tmpMd.bnSnCode = this.bnSnCode;
				tmpMd.checkOkQty = this.checkOkQty;
				let parm = {
					url : '/business/QaInspectRecord/addSapDeliverDtlInspectResult',
					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/inspectDtl',
							success: () => {
								uni.$emit('addInspectedData',tmpMd);
							}
						});
					}
					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
				}
			}
		}
	}
</script>

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