<template>
    <view class="content">
        <view class="btn">
            <!-- <button type="default" @click="scan">扫描</button> -->
        	<input v-model="code" type="text" placeholder="请扫码或输入入馆码" :focus="isfocus">
        </view>
		
		<view class="admin">
			<button type="primary" @click="usecode" plain="true">核销</button>
		</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
				code:"",
				isfocus:true
            }
        },
        methods: {
			usecode(){
				var url = 'https://dangxingjiaoyujidi.langye.net/api/mobile/visit/code-use';
				let that = this;
				that.isfocus = false
				uni.request({
					url:url,
					method:"GET",
					data:{
						code:that.code
					},
					success(res) {
						
						if(res.statusCode==200){
								if(res.data.errcode){
									uni.showToast({
										icon:"none",
										title:res.data.errmsg,
										duration:2000,
										complete() {
											that.code = "";
											that.isfocus=true
										}
									})
									
								}else{
									uni.showToast({
										icon:"none",
										title:'核销成功',
										duration:2000,
										complete() {
											that.code = ""
											that.isfocus=true
										}
									})
									
								}
							}else{
								uni.showToast({
									icon:"none",
									title:'请求失败',
									duration:2000,
									complete() {
										that.code = "";
										that.isfocus=true
									}
								})
							}
							
							
						},
						fail() {
							
						}
				})
			}
			
        }
    }
</script>

<style>
	.content{
		
	}
	.btn input{
		border:1px solid #ddd;
		height:40px;
		padding:5px 10px;
		margin:10px;
		margin-top:30px;
	}
	.admin{
		text-align: center;
	}
	.admin button{
		margin:10px;
		margin-top:20px;
		
	}
</style>