<template>
	<view class="page-wraper">
		<view class="" >
			<com-blank-view @goScan='goScan()'></com-blank-view>
		</view>
	</view>
	<winScanPackLevel ref="scanPopup" @getResult='getScanResult' headerType="HCMQ" title="叫料标签" :isShowHistory="false"></winScanPackLevel>
	<comMessage ref="comMessage"></comMessage>
</template>

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

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

	import {
		goHome,
		updateTitle,
		getRemoveOption,
		navigateBack,
		getCurrDateOneMonthsTimes
	} from '@/common/basic.js';

	import {
		getDataSource
	} from '@/pages/issue/js/issue.js';

	import comBlankView from '@/mycomponents/common/comBlankView.vue'
	import jobDetailPopup from '@/mycomponents/job/jobDetailPopup.vue'
	import comScanIssuePack from '@/pages/issue/coms/comScanIssuePack.vue'
	import comIssueRequestCreator from '@/pages/issue/coms/comIssueRequestCreator.vue'
	import winScanPackLevel from '@/mycomponents/scan/winScanPackLevel.vue'
	
	export default {
		name: 'issueRequestSubmit',
		components: {
			comBlankView,
			jobDetailPopup,
			comScanIssuePack,
			comIssueRequestCreator,
			winScanPackLevel
		},
		data() {
			return {
				jobContent: {}, //任务内容
				subList: [], //接口返回的任务subList
				detailSource: {
					subList: []
				}, //绑定在页面上的数据源
				detailOptions: [],
				scanOptions: [],
				requestList: [], //需求信息
				itemCodeTypeList:[],
				useOnTheWay:"FALSE"

			}
		},
		mounted() {
		},
		onLoad(option) {
			uni.setNavigationBarTitle({
				title: option.title
			})
			var typeCode = "Issue"
			getBusinessType(typeCode, res => {
				if (res.success) {
					this.itemCodeTypeList = res.itemCodeTypeList;
					this.useOnTheWay = res.useOnTheWay;
					this.fromInventoryStatuses = res.fromInventoryStatuses
					this.toInventoryStatuses = res.toInventoryStatuses
					this.goScan()
				} else {
					this.showErrorMessage(res.message)
				}
			});

		},
		methods: {
			goScan() {
				this.$refs.scanPopup.openScanPopup();
				setTimeout(res => {
					if (this.$refs.scanPopup != undefined) {
						this.$refs.scanPopup.getfocus();
					}
				}, 400)
				
			},
			getScanResult(result){
				this.detailSource = {
					subList:[]
				}
				var labelInfo = result.label;
				
				var data = {
					itemCode:labelInfo.itemCode,
					location:labelInfo.location,
					qty:labelInfo.qty,
					uom:labelInfo.uom,
					packUnit:labelInfo.packUnit
					
				};
				this.detailSource.subList.push(data)
				this.detailSource.productionLineCode=labelInfo.productionLineCode;
				this.detailSource.workStationCode=labelInfo.workStationCode;
				this.detailSource.warehouseCode = labelInfo.warehouseCode;
				this.detailSource.workshopCode = labelInfo.workshopCode;
				this.detailSource.priority =result.priorityCode
				this.submit();
			},

			setParams() {
				this.detailSource.dueTime = getCurrDateOneMonthsTimes();
				this.detailSource.isCallMaterialsLabel = "TRUE";
				return this.detailSource
			},
			submit() {
				uni.showLoading({
					title: "提交中....",
					mask: true
				});
				var params = this.setParams()
				console.log("提交参数", JSON.stringify(params));
				issueRequestSubmit(params).then(res => {
					uni.hideLoading()
					if (res.data) {
						this.showCommitSuccessMessage("提交成功\n生成发料申请[" + res.data+"]")
					} else {
						this.showErrorMessage("提交失败[" + res.msg + "]")
					}
				}).catch(error => {
					uni.hideLoading()
					this.showErrorMessage(error)
				})
			},
			showCommitSuccessMessage(hint) {
				this.$refs.comMessage.showSuccessMessage(hint, res => {
					this.closeScanPopup();
					this.goScan();
				})
			},
			
			closeScanPopup() {
				this.$refs.scanPopup.closeScanPopup();
			},
			showErrorMessage(message) {
				this.$refs.comMessage.showErrorMessage(message, res => {
					if (res) {
						this.scanPopupGetFocus()
					}
				});
			},
			scanPopupGetFocus() {
				if (this.$refs.scanPopup != undefined) {
					this.$refs.scanPopup.getfocus();
				}
			},
		}
	}
</script>

<style>
</style>
