<template>
	<view>
		<StickyNavBar>
			<NavBar title="发货过账扫描"></NavBar>
			<view class="btn">
				<!-- <uni-easyinput prefixIcon="search" class="topSearch" v-model="nlpla" focus placeholder="请扫描库位" @change="handleInputNlpla"></uni-easyinput> -->
				<uni-easyinput
					prefixIcon="search"
					:disabled="isDisabled"
					v-model="wxparams"
					:focus="isFocus"
					placeholder="请扫描交货单"
					@input="handleInputPlnr"
				></uni-easyinput>
			</view>
		</StickyNavBar>
		<ContentLoadingMore class="cardbox"  :list='goodsList'>
			<view class="cardContent" v-for="(item, index) in goodsList">
				<view class="listItemTitle">
					<view class="item">交货单号：{{ item.MATNR }}</view>
				</view>
			</view>
		</ContentLoadingMore>
		<BottomBtn :btnArr="btnArr" @getBtnHandle="getBtnHandle"></BottomBtn>
	</view>
</template>

<script>
import StickyNavBar from '@/components/StickyNavBar/index.vue';
import ContentLoadingMore from '@/components/ContentLoadingMore/index.vue';
import BottomBtn from '@/components/BottomBtn/index.vue';
export default {
	components: {
		StickyNavBar,
		ContentLoadingMore,
		BottomBtn
	},
	data() {
		return {
			number: 0,
			totalNum: 0,
			show: true,
			nlpla: '',
			wxparams: '',
			btnArr: [
				{
					style: '',
					type: 'warning',
					text: '返回',
					way: 'goBack'
				},
				{
					style: '',
					type: 'primary',
					text: '过账',
					way: 'goSubmit'
				}
			],
			goodsList: [],
			isFocus: false,
			isDisabled: false
		};
	},
	created() {
		// this.getPlnr('10000820240325000001|10000320100');
	},
	methods: {
		deleGonds(idx) {
			this.goodsList.splice(idx, 1);
			this.totalNum = 0;
			this.goodsList.forEach((ele) => {
				this.totalNum += ele.ERFMG;
			});
		},
		getBtnHandle(row) {
			this[row.way]();
		},
		goBack() {
			uni.navigateBack();
		},
		goSubmit() {
			if (this.goodsList.length === 0) {
				return;
			}
			const params = {
				"VBELN": this.goodsList[0].VBELN,	
				"WADAT": parseTime(new Date())	
			} 
			this.$u.api.sapApi
				.sapDelv(params)
				.then((res) => {
					this.loading = false;
					console.log(res);
					if (res.every((item) => item.TYPE === 'S')) {
						this.$u.toast('提交成功');
					}
					res.forEach((ele) => {
						if (ele.TYPE === 'E') {
							this.$u.toast(ele.MESSAGE);
						}
					});
				});
		},
		handleInputPlnr(e) {
			this.isFocus = false;
			// e&& e.length > 79 && this.getPlnr(e);
			e && this.getPlnr(e);
		},
		handleInputNlpla(e) {
			if (e) {
				this.nlpla = e;
				this.goodsList.forEach((ele) => {
					this.totalNum += ele.ERFMG;
					ele.NLPLA = ele.NLPLA || this.nlpla;
				});
			}
		},
		getPlnr(plnr) {
			this.totalNum = 0;
			this.isDisabled = true;
			this.$u.api.sapApi
				.sapPlnr({
					plnr
				})
				.then((res) => {
					if (res && res.RESULT.TYPE === 'S') {
						this.goodsList = this.goodsList.concat(res.DATA);
						this.goodsList.forEach((ele) => {
							this.totalNum += ele.ERFMG;
							ele.NLPLA = ele.NLPLA || this.nlpla;
							ele.PLNR = plnr
						});
						setTimeout(() => {
							this.wxparams = '';
							this.isFocus = true;
							this.isDisabled = false;
						}, 1000);
					} else {
						setTimeout(() => {
							this.isFocus = true;
							this.isDisabled = false;
						}, 1000);
						this.$u.toast(res.RESULT.MESSAGE);
					}
					this.loading = false;
				});
		}
	}
};
</script>

<style lang="scss" scoped>
page {
	background: #f8f8f8;
}
.btn {
	padding: 20rpx;
	background: #fff;
	.topSearch {
		margin-bottom: 20rpx;
	}
}
.bottomBtn {
	position: sticky;
	padding: 20rpx;
	display: flex;
	justify-content: space-between;
	background: #fff;
	bottom: 0rpx;
	margin-top: 20rpx;
	.u-btn {
		width: 300rpx;
	}
}
.blue {
	color: #3f9dcc;
}
.total {
	background: #fff;
	color: #000;
	padding: 0rpx 40rpx;
	display: flex;
	justify-content: space-between;
	font-size: 32rpx;
	.line {
		margin: 0px 10rpx;
	}
}
.cardbox {
	min-height: calc(100vh - 280rpx);
	padding: 0rpx 20rpx;
	margin-top: 20rpx;
}
.cardContent {
	border-radius: 8px;
	background: #fff;
}
.listItemTitle {
	display: flex;
	justify-content: space-between;
	padding: 20rpx;
	border-bottom: 2px solid #f8f8f8;
	.u-btn {
		width: 150rpx;
		margin: 0px;
		margin-top: 10rpx;
	}
	.item {
		line-height: 50rpx;
		color: #000;
		font-size: 28rpx;
		font-weight: 500;
		word-break: break-all;
	}
}

/deep/ .u-sticky {
	top: 0 !important;
	background: #fff;
}
</style>