<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.purchaseOrder}}</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 class="text" style="align-self: center;font-size: 35rpx;color: darkslategray;padding: 1px;">BN/SN 生成模式：</view>
		<uni-data-checkbox style="align-self: center;font-size: 35rpx;padding: 5px;" v-model="radio1" :localdata="sex" @change="change"></uni-data-checkbox>
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 1px; ">
			<text style="align-self: center;font-size: 35rpx;color: darkslategray;width: 250rpx;">BN码(批次号)：</text>
			<input class="uni-input" style="margin-right: 5px;font-size: 40rpx;font-weight: bold;" :disabled="isBnInputDisabled" v-model="BnCode" :focus="foucusIndex === 0" placeholder="请输入BN码(批次号)" />
		</view>
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 1px; ">
			<text style="align-self: center;font-size: 35rpx;color: darkslategray;width: 250rpx;">SN码(序列号)：</text>
			<input class="uni-input" style="margin-right: 5px;font-size: 40rpx;font-weight: bold;" :disabled="isSnInputDisabled" v-model="SnCode" :focus="foucusIndex === 1" placeholder="请输入SN码(序列号)" />
		</view>
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 1px; ">
			<text style="align-self: center;font-size: 35rpx;color: darkslategray;width: 250rpx;">标签默认数量：</text>
			<input class="uni-input" type="number" style="margin-right: 5px;font-size: 40rpx;font-weight: bold;" v-model="PrintShowQty"/>
		</view>
		<view style="flex-direction: row;flex-direction: row;display: flex;padding: 1px; ">
			<text style="align-self: center;font-size: 35rpx;color: darkslategray;width: 250rpx;">标签打印张数：</text>
			<input class="uni-input" type="number" style="margin-right: 5px;font-size: 40rpx;font-weight: bold;" v-model="PrintLabelNum"/>
		</view>
		<button type="primary" style="margin-top: 4px;" @click="resetCondition">重   置</button>
		<button type="primary" style="margin-top: 4px;" @click="submitResult">打印标签</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				radio1: 0,
				deliverDtlMd: {},
				SnCode: '',
				BnCode: '',
				PrintLabelNum: 1,
				PrintShowQty: 1,
				foucusIndex: 1,
				sex: [{
					text: '系统自动生成',
					value: 0
				}, {
					text: '扫码生成',
					value: 1
				}],
				isBnInputDisabled: true,
				isSnInputDisabled: true
			}
		},
		onUnload() {
			
		},
		onLoad() {
			uni.$once('sendDeliverDtlData', (data) => {
				this.deliverDtlMd = data
			})
			if(!this.radio1) {
				this.isSnInputDisabled = true
				this.isBnInputDisabled = true
				this.foucusIndex = 2
			}
			else {
				this.isSnInputDisabled = false
				this.isBnInputDisabled = false
				this.foucusIndex = 0
			}
		},
		methods: {
			async submitResult() {
				if(this.radio1){
					if(this.isEmptyStr(this.BnCode)) {
						uni.showToast({
							title: 'BN码不能为空！',
							icon: 'none',
							duration: 1000
						})
						return;
					}
					if(this.isEmptyStr(this.SnCode)) {
						uni.showToast({
							title: 'SN码不能为空！',
							icon: 'none',
							duration: 1000
						})
						return;
					}
				}
				let tmpMd = {};
				tmpMd.Mc = this.deliverDtlMd.materialCode;
				tmpMd.Pn = this.deliverDtlMd.materialSpec;
				tmpMd.Name = this.deliverDtlMd.materialName;
				tmpMd.Qty = this.deliverDtlMd.qty;
				tmpMd.Unit = "";
				tmpMd.Po = this.deliverDtlMd.purchaseOrder;
				tmpMd.BnOrSnGenerationMode = !Boolean(this.radio1);
				tmpMd.PrintLabelNum = this.PrintLabelNum;
				tmpMd.PrintShowQty = this.PrintShowQty;
				if(this.radio1) {
					tmpMd.Sn = this.SnCode;
					tmpMd.Bn = this.BnCode;
				}
				let parm = {
					url : '/business/SapDeliverRecord/AddPrintLabelRecord',
					data: tmpMd,
					method: 'POST',
					isHaveToken : true
				}
				let retData = await getApp().RequestData(parm)
				if(retData.isSuccess) {
					if(retData.data.code == 200) {
						uni.showLoading({
							title: '发送打印数据成功!!',
							mask: true
						});
						setTimeout(function () {
							uni.hideLoading();
							uni.navigateBack({
								url: '/pages/Inspect/PrintLabelDtl'
							});
						}, 1000);
					}
					else {
						uni.showToast({
							title: '提交数据失败！' + retData.data.msg,
							icon: 'none',
							duration: 1000,
							mask: true
						})
					}
				}
				else {
					uni.showToast({
						title: '接口异常！' + retData.retMsg,
						icon: 'none',
						duration: 1000,
						mask: true
					})
				}
			},
			isEmptyStr(s) {
				if (s == undefined || s === '') {
					return true
				}
				return false
			},
			resetCondition() {
				this.SnCode = ''
				this.BnCode = ''
				this.radio1 = 0
			},
			change(e){
				if(!this.radio1) {
					this.isBnInputDisabled = true
					this.isSnInputDisabled = true
					this.foucusIndex = 2
				}
				else {
					this.isBnInputDisabled = false
					this.isSnInputDisabled = false
					setTimeout(() => {
						this.foucusIndex = 0;
					}, 150)
				}
			}
		}
	}
</script>

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