XhScan.vue 1.6 KB
<!-- *******************  扫码  *******************  -->
<template>
	<view class="">
		<view class="u-flex" @click="scanCode">
			<view class="txt u-flex-1">扫描二维码(仅挚达充电桩可扫描)</view>
			<u-icon name="arrow-right" color="#666" size="28"></u-icon>
		</view>
		<view class="u-flex">
			<u-input class="u-flex-1 input-item" v-model="dataValue" @input="valueChange" type="text" />
		</view>
	</view>
</template>

<script>
	import stringMixin from './stringMixin'
	export default {
		name: 'XhScan',
		components: {},
		mixins: [stringMixin],
		props: {},
		filters:{},
		data() {
			return {}
		},
		computed: {
			valueTxt() {
				let str = ''
				const dataValue = this.dataValue
				if(dataValue && dataValue.length>1){
					str = '经度:'+dataValue[0]+','+'维度:'+dataValue[1]
				}
				return str
			}
		},
		watch: {},
		mounted() {},
		methods: {
			scanCode(type){
				const self = this
				// qrCode 二维码;barCode 条形码
				let scanType = type && [type] || ['qrCode']
				uni.scanCode({
				    // scanType: scanType,
				    success: function (res) {
						self.dataValue = res.result
						self.valueChange(res.result)
				        // console.log('条码类型:' + res.scanType);
				        // console.log('条码内容:' + res.result);
				    }
				});
			},
			// setValue(txt) {
			// 	this.valueChange(this.dataValue)
			// }
		}
	}
</script>
<style lang="scss" scoped>
	.required {
		padding-right: 10rpx;
		font-size: 28rpx;
		line-height: 40rpx;
		color: #fa3534;
	}
	.input-item{
		background: #F4F5F7;
		border-radius: 12rpx;
		padding-left: 20rpx;	
	}
</style>