<template>
	<uni-popup ref="popup">
		<view class="popup_box">
			<view class="pop_title">
				扫描信息
				<text class="fr" @click="closeScanPopup()">关闭</text>
			</view>
			<!-- 以下应是tab切换格式，此处只有一个选项卡 -->
			<view class="pop_tab">
				<view class="uni-flex uni-row">
					<view v-for="(tab, index) in titleArray" :key="tab.id" class="uni-tab-item" :id="tab.id"
						:data-current="index" :class="tabIndex == index ? 'tab_tit tab_tit_active' : 'tab_tit'"
						@click="ontabtap">
						{{ tab }}
					</view>
				</view>
				<view class="tab_info">
					<win-com-scan @getScanResult="getScanResult" :placeholder='placeholder' :boxFocus='true'
						:clearResult='true'>
					</win-com-scan>
				</view>
			</view>
		</view>
	</uni-popup>
</template>

<script>
	import winComScan from '@/mycomponents/wincom/winComScan.vue'
	export default {
		name: 'winScanReceipt',
		components: {
			winComScan
		},
		props: {
			titleArray: {
				type: Array,
				default () {
					return []
				}
			},
		},
		data() {
			return {
				tabIndex: 0,
				placeholder: ''
			}
		},
		created() {

		},
		onLoad() {},
		methods: {
			openScanPopup() {
				this.placeholder = this.titleArray[0];
				this.$refs.popup.open('bottom');
			},
			closeScanPopup() {
				this.$refs.popup.close()
			},
			ontabtap(e) {
				let index = e.target.dataset.current || e.currentTarget.dataset.current;
				this.tabIndex = index;
				let title = this.titleArray[this.tabIndex];
				this.placeholder =  this.titleArray[this.tabIndex];
				this.$forceUpdate();
			},
			getScanResult(result) {
				let type = this.titleArray[this.tabIndex];
				this.closeScanPopup();
				this.$emit("getScanResult", type, result);
			}
		}
	}
</script>

<style>
</style>
