<template>
	<view>
		<StickyNavBar>
			<NavBar title="生产发料单号"></NavBar>
		</StickyNavBar>
		<ContentLoadingMore class="cardbox" :loadmore='true' :status="status" :list='goodsList'>
			<view class="cardContent" v-for="(item, index) in goodsList">
				<view class="listItemTitle" @click="handleClick(item)">
					<view>
						<view class="item">申请单号：{{ item.applyNo }}</view>
						<!-- <view class="item">物料编号：{{ item.sapItemCode }}</view> -->
						<!-- <view class="item">物料描述：{{ item.itemName }}</view> -->
						<view class="item">作业单元：{{ item.workunitName }}</view>
						<view class="item">作业类型：{{ item.materialType ? '补料': '领料' }}</view>
						<view class="item">备料状态：{{ item.grantNum? '配货中' : '未配货' }}</view>
						<view class="item">计划时间：{{ item.startTime }}</view>
					</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: [],
			pagination: {
				pageNum:1,
				pageSize:10,
			},
			total: 0,
			status: 'loadmore'
		};
	},
	created() {
		this.getPlnr();
	},
	methods: {
		// 加载更多
		onReachBottom() {
			console.log('加载更多');
			if(this.pagination.pageNum * this.pagination.pageSize >= this.total){
				this.status = "noMore"
				return;
			}else{
				this.status = "loading"
				this.pagination.pageNum++
				this.getPlnr();
			}
		},
		handleClick(item){
			uni.navigateTo({
				url: `/pages/productionIssuance/productionIssuanceList?order=${item.applyNo}`
			});
		},
		getBtnHandle(row) {
			this[row.way]();
		},
		goBack() {
			uni.navigateBack();
		},
		goSubmit() {
			if (this.goodsList.length === 0) {
				return;
			}
			console.log([
				{
					BLDAT: '20240325',
					BUDAT: '20240325',
					ZENCODE: 'A014',
					ITEM: this.goodsList
				}
			]);
			this.$u.api.sapApi
				.sapRrm([
					{
						BLDAT: '20240325',
						BUDAT: '20240325',
						ZENCODE: 'A014',
						TYPE: 'CG',
						ITEM: this.goodsList
					}
				])
				.then((res) => {
					this.loading = false;
					if(!Array.isArray(res)){
						return
					}
					if (res && res.every((item) => item.TYPE === 'S')) {
						this.goodsList = [];
						this.totalNum = 0;
						this.nlpla = '';
						this.wxparams = '';
						this.$u.toast('提交成功');
					}
					const foundObject = res.find(item => item.TYPE === 'E');
					if(foundObject && foundObject.MESSAGE){
						this.$u.toast(foundObject.MESSAGE);
					}
				});
		},
		handleInputPlnr(e) {
			// e&& e.length > 79 && this.getPlnr(e);
			e && this.getPlnr(e);
		},
		getPlnr(applyNo = '') {
			this.totalNum = 0;
			this.isDisabled = true;
			this.$u.api.mesApi
				.pdaMaterialcreate({
					...this.pagination,
					applyNo
				})
				.then((res) => {
					if (res && res.code - 200 === 0) {
						this.goodsList = this.goodsList.concat(res.rows);
						this.goodsList = this.goodsList.filter((item, index, self) => {
							return self.findIndex(t => t.applyNo === item.applyNo) === index;
						});
						this.total = res.total
					} else {
						this.$u.toast(res.msg);
					}
				});
		}
	}
};
</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 - 540rpx);
	padding: 0rpx 20rpx;
	margin-top: 20rpx;
}
.cardContent {
	border-radius: 8px;
	background: #fff;
	margin-bottom: 20rpx;
}
.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;
	}
}
.listBottom {
	.bottomTitle {
		height: 80rpx;
		position: relative;
		.desc {
			color: #bbb;
			font-size: 24rpx;
			line-height: 80rpx;
			padding-left: 20rpx;
		}
		.topIcons {
			position: absolute;
			left: 50%;
			top: 50%;
			transform: translate(-50%, -50%);
			color: #aaa;
		}
	}
	.bottomBox {
		padding: 20rpx;
		.bottomItem {
			background: #f8f8f8;
			padding: 20rpx;
			margin-bottom: 20rpx;
			.items {
				color: #333;
				font-size: 24rpx;
				height: 40rpx;
				line-height: 40rpx;
			}
		}
	}
}
/deep/ .u-sticky {
	top: 0 !important;
	background: #fff;
}
</style>