<template>
	<winScanStandard ref="standard" :title="title" @getScanResult="getScanResult">

	</winScanStandard>
</template>

<script>
	import {
		getContainerByNumber,
	} from '@/api/request.js';
	 
	import winScanStandard from '@/mycomponents/wincom/scanCom/winScanStandard.vue'
	export default {
		components: {
			winScanStandard
		},
		emits: ["getScanCode"],
		props: {
			title: {
				type: String,
				default: '器具代码'
			},
			locationTypeList: {
				type: Array,
				default: []
			},
			isJudgeStatus: {
				type: Boolean,
				default: true
			},
		},
		data() {
			return {
				code: '',
				number: '',
				container: {}
			}
		},

		created() {

		},
		methods: {
			openScanPopup() {
				this.$refs.standard.openScanPopup()
			},
			closeScanPopup() {
				this.$refs.standard.closeScanPopup()
			},
			scanClick() {
				this.$refs.standard.clickScanMsg();
			},
			cancelClick() {
				this.$refs.standard.clearScanValue();
			},
			getScanResult(result) {
				if (result.label.Type == "QRCode") {
					this.code = result.label.itemCode;
				} else if (result.label.Type == "BarCode") {
					this.code = result.label.code;
				}

				uni.showLoading({
					title: '扫描中...',
					mask: true
				});

				getContainerByNumber(this.code).then(res => {
					uni.hideLoading();

					if (res.data.total > 0) {
						var number = res.data.list[0].number;
						var type = res.data.list[0].type;
						var status = res.data.list[0].status;
						if (this.isJudgeStatus) {
							if (status == 'qjztUsed') {
								this.container = res.data.list[0];
								this.callBack();
							} else {
								this.$refs.standard.showWarningMessage("扫描器具[" + this.code + "]不可用", res => {})
							}

						}

					} else {
						this.$refs.standard.showWarningMessage('未查询到器具' + '【' + this.code + '】', res => {

						})
					}
				}).catch(error => {
					uni.hideLoading();
					this.$refs.standard.showWarningMessage(error, res => {

					})
				})
			},
			callBack() {
				this.closeScanPopup();
				this.$emit("getScanCode", this.container, this.number);
			},
			getfocus() {
				this.$refs.standard.getfocus();
			},

		}
	}
</script>

<style>
</style>
