<template>
	<view id="barcode" style="background-color: #18B566;width: 100%;height: 100%"></view>
</template>

<script>
	export default {
		data() {
			return {
				// #ifdef APP-PLUS
				barcode: [
					plus.barcode.CODE39,
					plus.barcode.CODE93,
					plus.barcode.CODE128,
				], //码类型
				bug:'',
				// #endif
			};
		},
		created() {
			var statusBarHeight = uni.getSystemInfoSync().statusBarHeight; //状态栏
			var height = statusBarHeight + 44 + 144 + 'px';
			var pages = getCurrentPages();
			var page = pages[pages.length - 1];
			// #ifdef APP-PLUS
			var currentWebview = page.$getAppWebview();
			this.barcode = plus.barcode.create('barcode', this.barcode, {
				top: '0',
				left: '0',
				width: '100%',
				height: '420', //180px
				position: 'static',
				background: '#ffffff',
				frameColor: '#00A0EA',
				scanbarColor: '#00A0EA'
			});
			
			this.barcode.onmarked = this.onmarked;
			
			// this.barcode.start({vibrate: false}); //振动
			this.barcode.start({sound: "none"}); //提示音
			
			currentWebview.append(this.barcode);
			const res = uni.getSystemInfoSync();
			if (res.platform == 'android') { //安卓机
				this.barcode.start();
			}
			this.barcode.setStyle({
				background: '#ffffff',
				frameColor: '#00A0EA',
				scanbarColor: '#00A0EA'
			});
			// #endif
		},
		methods: {
			onmarked(type, result) {
				this.$emit('getCode', result);
				this.t = setTimeout(() => {
					this.barcode.start();
				}, 2500)
			}
		}
	}
</script>

<style lang="less">

</style>
