<template>
	<view class="page">
		<StickyNavBar>
			<NavBar title="发货过账扫描"></NavBar>
			<view class="btn">
				<uni-easyinput
					prefixIcon="search"
					:disabled="isDisabled"
					v-model="wxparams"
					:focus="isFocus"
					placeholder="请扫描交货单"
					@input="handleInputPlnr"
				></uni-easyinput>
			</view>
			<view class="btn">
				<uni-datetime-picker type="date" :clear-icon="false" placeholder="请选择发货日期" v-model="single" @maskClick="maskClick" />
			</view>
		</StickyNavBar>
		<ContentLoadingMore class="cardbox"  :list='goodsList'>
			<view class="cardContent" v-for="(item, index) in goodsList">
				<view class="listItemTitle">
					<view class="item">交货单号：{{ goodsList[index] }}</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';
import { parseTime} from "@/utils/ruoyi";
export default {
	components: {
		StickyNavBar,
		ContentLoadingMore,
		BottomBtn
	},
	data() {
		return {
			number: 0,
			totalNum: 0,
			show: true,
			nlpla: '',
			wxparams: '',
			single: '',
			btnArr: [
				{
					style: '',
					type: 'warning',
					text: '返回',
					way: 'goBack'
				},
				{
					style: '',
					type: 'primary',
					text: '过账',
					way: 'goSubmit'
				}
			],
			goodsList: [],
			isFocus: false,
			isDisabled: false
		};
	},
	created() {
		// this.getPlnr('10000820240325000001|10000320100');
		this.single = parseTime(new Date())
	},
	methods: {
		deleGonds(idx) {
			this.goodsList.splice(idx, 1);
			this.totalNum = 0;
			this.goodsList.forEach((ele) => {
				this.totalNum += ele.ERFMG;
			});
		},
		maskClick(e) {},
		getBtnHandle(row) {
			this[row.way]();
		},
		goBack() {
			uni.navigateBack();
		},
		goSubmit() {
			if (this.goodsList.length === 0) {
				return;
			}
			const params = {
				"VBELN": this.goodsList[0],	
				"WADAT": this.single,
			} 
			this.$u.api.sapApi
				.sapDelv(params)
				.then((res) => {
					this.loading = false;
					if(!Array.isArray(res)){
						return
					}
					if (res.every((item) => item.TYPE === 'S')) {
						this.$u.toast('提交成功');
						this.goodsList = []
						this.wxparams = ''
						this.isDisabled = false
						this.isFocus = true;
					}
					const foundObject = res.find(item => item.TYPE === 'E');
					if(foundObject && foundObject.MESSAGE){
						this.$u.toast(foundObject.MESSAGE);
					}
				});
		},
		handleInputPlnr(e) {
			this.isFocus = false;
			// e&& e.length > 79 && this.getPlnr(e);
			e && this.getPlnr(e);
		},
		getPlnr(num) {
			this.isDisabled = true
			this.goodsList.push(num)
		}
	}
};
</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;
	margin-bottom: 10rpx;
}
.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>