<template>
	<view class="page-wraper">
		<view class="">
			<com-blank-view @goScan='showFromLocationPopup' v-if="customerCode==''" title='选择用户'></com-blank-view>
		</view>
		<view class="page-wraper"  v-if="customerCode!=''">
			<view class="page-header">
				<view class="header_item">
					客户代码 : {{customerCode}}
				</view>
				<!-- <view class='split_line'></view> -->
			</view>
			<view class="page-main">
				<scroll-view scroll-y="true" class="page-main-scroll">
					<view :class="[item.pass?'scan_view':'refuse_view']"  v-for="(item, index) in list" :key="index">
						<view class="card_view">
							<text class="card_packing_code card_content ">箱码</text>
							<text class="card_content ">{{item.packingNumber}}</text>
						</view>
						<view class="card_view ">
							<text class="card_batch card_content " style="padding-left: 30px;">WMS 物料</text>
							<text class="card_content ">{{item.itemCode}}</text>
						</view>
						<view class="card_view ">
							<text class="card_order card_content " style="padding-left: 30px;">客户 物料</text>
							<text class="card_content ">{{item.customerItemCode}}</text>
						</view>
						<view class="card_view ">
							<text class="card_order card_content " style="padding-left: 30px;">实际校验 物料</text>
							<text class="card_content ">{{item.customerItemCode_reality}}</text>
						</view>
						<view class='line'></view>
					</view>
				</scroll-view>
			</view>
			<win-scan-button @goScan='openScanPopup'></win-scan-button>
		</view>
		<u-select v-model="show" mode="mutil-column-auto" :list="customerList"
			 @confirm="confirmSelect"></u-select>

		<win-check-fg-label ref="scanPopup" @checkResult="checkResult"></win-check-fg-label>
		<comMessage ref="comMessage"></comMessage>
	</view>
</template>

<script>
	import {
		issueRecordSubmit,
		getWorkShopLineStation,
		getBasicCustomerList
	} from '@/api/request2.js';

	import {
		goHome,
		getPackingNumberAndBatchByList,
		deepCopyData
	} from '@/common/basic.js';

	import {
		calc
	} from '@/common/calc.js';

	import {
		getInventoryStatusDesc,
		getDirectoryItemArray
	} from '@/common/directory.js';

	import {
		getBusinessType,
		createItemInfo,
		createDetailInfo,
	} from '@/common/record.js';

	import {
		getManagementPrecisions,
		getPrecisionStrategyList,
		getPrecisionStrategyParams
	} from '@/common/balance.js';

	import winScanButton from '@/mycomponents/scan/winScanButton.vue'
	import winScanPack from '@/mycomponents/scan/winScanPack.vue'
	import requiredLocation from '@/mycomponents/location/requiredLocation.vue'
	import comBlankView from '@/mycomponents/common/comBlankView.vue'
	import winScanLocation from "@/mycomponents/scan/winScanLocation.vue"
	import winCheckFgLabel from "@/mycomponents/scan/winCheckFgLabel.vue"
	import winScanPackAndLocation from "@/mycomponents/scan/winScanPackAndLocation.vue"
	import recordComDetailCard from '@/mycomponents/record/recordComDetailCard.vue'

	export default {
		components: {
			winScanButton,
			winScanPack,
			requiredLocation,
			comBlankView,
			winScanLocation,
			winCheckFgLabel,
			recordComDetailCard,
		},
		data() {
			return {
				showToLoaction: true,
				recommendLocationList: [], //推荐库位列表
				fromWarehouseCode: '', //来源仓库
				positionList: [],
				show: false,
				positionInfo: "请选择生产线",
				customerList: [],
				customerCode: '',
				customerName: '',
				list:[]
			};
		},
		onLoad(option) {
			getBasicCustomerList().then(res => {
				if (res.data.length > 0) {
					var list = res.data;
					list.forEach(item => {
						item.label = item.name
						item.value = item.code
					})
					this.customerList = list;

				}
			}).catch(error => {
				this.showErrorMessage(error)
			})

		},
		//返回首页
		onNavigationBarButtonTap(e) {
			if (e.index === 0) {
				goHome();
			}
		},
		//拦截返回按钮事件
		onBackPress(e) {},

		onPullDownRefresh() {},

		mounted() {},

		methods: {
			//校验结果
			checkResult(result){
				console.log('checkResult',result)
				let flag = true
				for(let i=0;i<this.list.length;i++){
					if(this.list[i].packingNumber==result.packingNumber&&this.list[i].customerItemCode==result.customerItemCode&&this.list[i].customerItemCode_reality==result.customerItemCode_reality&&this.list[i].itemCode==result.itemCode&&this.list[i].pass==result.pass){
						flag = false
					}
				}
				if(flag){
					this.list.unshift(result)
				}
				if(result.pass){
					//通过
					this.showMessage('校验通过')
				}else{
					this.showErrorMessage('校验未通过')
				}
				this.$refs.scanPopup.closeScanPopup();
			},
			//打开扫描
			openScanPopup() {
				this.$refs.scanPopup.openScanPopupForType(this.customerCode);
			},
			
			showErrorMessage(message) {
				this.$refs.comMessage.showErrorMessage(message, res => {
					if (res) {}
				});
			},
			
			showSelect() {
				this.show = true
			},

			confirmSelect(e) {
				if (e.length > 0) {
					this.customerCode = e[0].value
					this.customerName = e[0].label
				}
			},
			
			showFromLocationPopup() {
				this.show = true;
			},

			closeScanPopup() {
				if (this.$refs.scanPopup != undefined) {
					this.$refs.scanPopup.closeScanPopup();
				}
			},

			scanPopupGetFocus() {
				if (this.$refs.scanPopup != undefined) {
					this.$refs.scanPopup.getfocus();
				}
			},
			showMessage(message) {
				this.$refs.comMessage.showMessage(message, res => {
					if (res) {}
				});
			},

			showScanMessage(message) {
				this.$refs.comMessage.showScanMessage(message);
			},

			afterCloseMessage() {
				this.scanPopupGetFocus();
			},

			closeScanMessage() {
				this.scanPopupGetFocus();
			},
			showCommitSuccessMessage(hint) {
				this.$refs.comMessage.showSuccessMessage(hint, res => {
				})
			},
			
		}
	}
</script>

<style scoped lang="scss">
	.u-drawer-content {
		height: 500rpx;
		background-color: bisque;
	}
	.refuse_view {
		background: linear-gradient(90deg, rgba(255, 160, 161, 1) 0%, rgba(255, 160, 161, 0) 100%)
	}
	.line {
		background-color: #e0e0e0;
		height: 1px;
	}
</style>