<template>
	<view class="container">
		<Navbar title="条码查询" safeAreaInsetTop placeholder canBack bgColor="#161F2E" textColor="#fff"
			leftIconColor="#fff"></Navbar>
		<view class="padding-lr-xl flex align-center w100 flex-direction" style="margin-top: 300rpx;">
			<view class="text-white margin-bottom  text-lgz">
				请输入条码查询气瓶
			</view>
			<view class="w80">
				<u-input v-model="code" placeholder="请输入条码查询气瓶"></u-input>
			</view>
			<view class="w80 flex justify-between margin-top-xl">
				<view class="w40" @click="goback">
					<u-button shape="circle" color="#4B2C24" iconColor="#fff" icon="scan" text="扫一扫"></u-button>
				</view>
				<view class="w40" @click="handleCode">
					<u-button shape="circle" color="#EA5504" text="确定"></u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				code:"",
				mode:1,
			};
		},
		onLoad(data) {
			console.log("页面接收参数",data);
			if(data.mode){
				this.mode = parseInt(data.mode);
				console.log("输入模式",this.mode);
			}
		},
		mounted() {

		},
		methods: {
			goback() {
				this.$goBack();
			},
			async handleCode() {
				if(this.code === ''){
					uni.$u.toast('请输入气瓶条码');
					return
				}
				this.$modal.showLoading('查询中...');
				let query = {
					qptm: this.code
				}
				const result = await this.$api.gasApi.getDetailByQuery(query);
				this.$modal.closeLoading();
				let {
					state,
					message
				} = result;
				if (!state) {
					uni.$u.toast(message)
					return;
				}
				if (this.mode === 1) {
					uni.redirectTo({
						url: '/pages/mine/appList/gasInformation/gasInformation?qptm=' + this.code
					})
				} else if (this.mode === 2) {
					//在需要扫码获取code的地方使用uni.$on监听scanCode即可获取code
					uni.$emit("scanCode", this.code);
					uni.navigateBack({
						delta:2
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		display: flex;
		flex: 1;
		overflow: hidden;
		width: 750rpx;
		height: 100vh;
		background: #161F2E;
	}

	.u-input {
		background: #fff;
	}
</style>