<template>
	<view>
		<StickyNavBar>
			<NavBar title="生产发料"></NavBar>
			<view class="btn">
				<uni-easyinput
					prefixIcon="search"
					:disabled="isDisabled"
					v-model="wxparams"
					:focus="isFocus"
					placeholder="请扫描单号"
					@input="handleInputPlnr"
				></uni-easyinput>
			</view>
		</StickyNavBar>
		<view class="cardBox">
			<text class="cardBoxTip">
				步骤一    扫描单号
			</text>
			<u-image class='cardBoxImg' :src="bgSrc" width="560rpx" height="400rpx"></u-image>
			<view class="cardBoxTip2">
				摄像头对准
			</view>
			<view class="cardBoxTip3">
				生产发料单号二维码
			</view>
			<view class="cardBoxTip2">
				<text class="tipLeft">
					点击扫描或
				</text>
				<text class="tipRight">
					点选单号
				</text>
			</view>
		</view>
		<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 {
			bgSrc: require('@/static/images/qrcode.png'),
			number: 0,
			totalNum: 0,
			show: true,
			nlpla: '',
			wxparams: '',
			btnArr: [
				{
					style: '',
					type: 'primary',
					text: '扫描单号',
					way: 'scanning'
				},
				{
					style: '',
					type: 'warning',
					text: '查询单号',
					way: 'goClick'
				}
			],
			goodsList: [],
			isFocus: false,
			isDisabled: false
		};
	},
	created() {
		// this.getPlnr('SN202400172');
	},
	methods: {
		getBtnHandle(row) {
			this[row.way]();
		},
		goClick() {
			uni.navigateTo({
				url: `/pages/productionIssuance/oddNumList`
			});
		},
		scanning() {
			uni.navigateTo({
				url: `/pages/productionIssuance/productionIssuanceList?order=${JSON.stringify(this.goodsList)}`
			});
		},
		handleInputPlnr(e) {
			this.isFocus = false;
			e && this.getPlnr(e);
		},
		getPlnr(applyNo) {
			this.totalNum = 0;
			this.isDisabled = true;
			this.$u.api.mesApi
				.pdaMaterialcreate({
					pageNum:1,
					pageSize:10,
					applyNo
				})
				.then((res) => {
					console.log(res,'-=')
					if (res.code - 200 === 0) {
						if(res.rows.length){
							uni.navigateTo({
								url: `/pages/productionIssuance/productionIssuanceList?order=${applyNo}`
							});
						}else{
							setTimeout(() => {
								this.isFocus = true;
								this.isDisabled = false;
								this.wxparams = ''
								this.$u.toast('未查询到数据');
							}, 1000);
						}
						// const data = res.rows
						// data.forEach((ele,index) => {
						// 	ele.sonItemCode = []
						// 	ele.sonItemCode.push(...data)
						// })
						// const result = data.filter((item, index, self) => {
						//     return self.findIndex(t => t.itemCode === item.itemCode) === index;
						// });
						// let i=null,j=null
						// for(i = 0; i < result.length; i++){
						//   for(j = 0; j < result[i].sonItemCode.length; j++){
						// 	if(result[i].itemCode !== result[i].sonItemCode[j].itemCode){
						// 		result[i].sonItemCode.splice(j,1)
						// 		j--
						// 	}
						//   }
						// }
						// console.log(result)
						// setTimeout(() => {
						// 	this.wxparams = '';
						// 	this.isFocus = true;
						// 	this.isDisabled = false;
						// }, 1000);
						// 	uni.navigateTo({
						// 		url: `/pages/productionIssuance/productionIssuanceList?order=${JSON.stringify(result)}`
						// 	});
						
						// console.log(result)
						// this.goodsList = this.goodsList.concat(res.rows);
						// setTimeout(() => {
						// 	this.wxparams = '';
						// 	this.isFocus = true;
						// 	this.isDisabled = false;
						// }, 1000);
						// console.log(this.goodsList)
						// uni.navigateTo({
						// 	url: `/pages/productionIssuance/productionIssuanceList?order=${JSON.stringify(this.goodsList)}`
						// });
					} else {
						setTimeout(() => {
							this.isFocus = true;
							this.isDisabled = false;
						}, 1000);
						this.$u.toast(res.msg);
					}
					this.loading = false;
				});
		}
	}
};
</script>

<style lang="scss" scoped>
page {
	background: #f8f8f8;
}
.btn {
	padding: 20rpx;
	background: #fff;
	.topSearch {
		margin-bottom: 20rpx;
	}
}
.cardBox {
	min-height: calc(100vh - 400rpx);
	padding: 0rpx 20rpx;
	margin-top: 20rpx;
}
/deep/ .u-sticky {
	top: 0 !important;
	background: #fff;
}
.cardBoxTip{
	color: #000;
	font-size: 28rpx;
}
.cardBoxTip2{
	color: #000;
	font-size: 28rpx;
	text-align: center;
}
.cardBoxTip3{
	color: #3f9dcc;
	font-size: 28rpx;
	text-align: center;
}
.tipRight{
	color: #ff9900;
}
</style>