<template>
	<u-popup :show="show" :round="36" mode="bottom" @close="close">
		<view class="bind_device">
			<div class="top adfacjb">
				<div class="pre adffcacjc" @tap="scanBind">
					<image src="http://106.54.209.120:8188/static/scan_bind.png"></image>
					<text>扫码绑定设备</text>
				</div>
				<div class="pre adffcacjc" @tap="wifiBind">
					<image src="http://106.54.209.120:8188/static/wifi_bind.png"></image>
					<text>配网并绑定设备</text>
				</div>
			</div>
			<div class="close">
				<u-icon name="close" color="#5C5C5C" size="50" @tap="close"></u-icon>
			</div>
		</view>
	</u-popup>
</template>

<script>
	export default {
		data(){
			return {
				show:false
			}
		},
		methods:{
			close(){
				this.show = false;
			},
			scanBind(){
				this.show = false;
				let that = this;
				uni.scanCode({
					success: (res) => {
						let result = JSON.parse(res.result);
						if(res.errMsg==='scanCode:ok'){
							that.$api.post('/device/bindAdd',{
								...result,
								"type": "",
								"userId": 0,
								"agentId": ""
							}).then(res=>{
								if(res.data.code!==0) return that.$showToast(res.data.msg)
								uni.navigateTo({
									url:'/pagesMy/scanResult'
								})
							})
						}
					}
				})
			},
			wifiBind(){
				this.show = false;
				uni.navigateTo({
					url:'/pagesMy/deviceAdd'
				})
			},
		}
	}
</script>

<style scoped lang="less">
	.bind_device{
		width: 100%;
		padding: 74rpx 74rpx 20rpx;
		box-sizing: border-box;
		.top{
			.pre{
				width: calc(50% - 51rpx);
				image{
					width: 110rpx;
					height: 110rpx;
				}
				text{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #111111;
					line-height: 32rpx;
					text-align: center;
					margin-top: 24rpx;
				}
			}
		}
		.close{
			width: 100%;
			margin-top: 113rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
</style>