<template>
	<view>
		<view class="contents">
			<input class="inputs" maxlength="20" v-model="codenums" placeholder-style="color:#ffffff;"
				placeholder="请输入设备的SN号" />
			<button class="btns" @click="configStoreDevice">确认</button>
		</view>
	</view>
</template>

<script>
	import {
		configStoreDevice
	} from '../../../Utils/Api.js';
	let app = getApp();
	export default {
		data() {
			return {
				codenums: '', //输入的sn号
				userInfo: app.globalData.userInfo
			}
		},
		methods: {
			//添加设备
			configStoreDevice() {
				if (!this.codenums) {
					uni.showToast({
						title: '请填写设备SN号',
						icon: "none",
						duration: 2000
					});
					return;
				}
				uni.showLoading({
					title: '提交中...'
				})
				let params = {
					storeId: this.userInfo.store.id,
					deviceSn: this.codenums
				}
				configStoreDevice(params).then(res => {
					uni.hideLoading();
					if (res.return_code == '000000') {
						uni.showToast({
							title: '绑定成功',
							icon: 'none',
							duration: 2000,
							success() {
								setTimeout(() => {
									uni.navigateBack({})
								}, 1000);
							}
						})
					} else {
						uni.showToast({
							title: res.return_msg,
							icon: 'none',
							duration: 2000
						})
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.contents {
		position: relative;
		top: 240rpx;
	}

	.inputs {
		height: 50px;
		line-height: 50px;
		background-color: #b4d5fb;
		width: 86%;
		margin-left: 6%;
		padding-left: 10px;
		border-radius: 5px;
		color: white;
		font-size: 20px;
	}

	.btns {
		margin-top: 200rpx;
		width: 60%;
		margin-left: 20%;
		height: 50px;
		line-height: 50px;
		background-color: #0083f5;
		color: #FFFFFF;
		font-weight: bold;
	}
</style>
