<template> <view class="page"> <u-navbar title="编号开锁" :border-bottom="false" :background="bgc" title-color='#000' title-size='36' height='45'></u-navbar> <view class="cont"> <view class="tit"> 输入编号开锁 </view> <view class="img"> <image src="https://lxnapi.ccttiot.com/bike/img/static/unMvTdIxoc2PXdYHZUGS" mode=""></image> </view> <view class="ipt"> <input type="number" class="ips" v-model="sn" placeholder="请输入车辆二维码下方编号" placeholder-style='font-weight: 400;font-size: 36rpx;color: #808080;' /> </view> <view class="btn" @click="sub" :class="istrue?'act1':''"> 确认开锁 </view> </view> </view> </template> <script> export default { data() { return { bgc: { backgroundColor: '#fff' }, sn:'', istrue:false } }, watch: { sn(newVal) { const regex = /^\d{7}$/; this.istrue = regex.test(newVal); } }, methods: { sub(){ if(this.sn==''){ uni.showToast({ title: '请输入设备编号', icon: 'none', duration: 2000 }); }else{ let that = this if(uni.getStorageSync('token')){ this.$u.get('/app/device/info?sn=' + this.sn).then((res) => { if (res.code === 200) { uni.redirectTo({ url:'/pages/index/index?sn='+this.sn }) }else{ uni.showToast({ title: res.msg, icon: 'none', duration: 2000 }); } }) }else{ wx.login({ success(res) { if (res.code) { console.log('登录!', res); let data = { wxOpenId: res.code, }; let areaId=uni.getStorageSync('areaId'); that.$u.post('/loginByopenid?jsCode='+res.code+'&areaId='+areaId).then(res=>{ uni.hideLoading(); if (res.code == 200) { uni.setStorageSync('token', res.token); that.$u.get('/app/device/info?sn=' + that.sn).then((res) => { if (res.code === 200) { uni.navigateTo({ url:'/pages/index/index?sn='+that.sn }) }else{ uni.showToast({ title: res.msg, icon: 'none', duration: 2000 }); } }) }else if(res.code == 501){ uni.showToast({ title: res.msg, icon: 'none', duration: 2000 }); }else { // console.log("老用户登录",res.data) uni.redirectTo({ url:'/pages/login/login' }) } }); } }, }); } } } } } </script> <style lang="scss" > page{ background-color: #fff; } .page{ width: 750rpx; .cont{ width: 100%; display: flex; justify-content: center; flex-wrap: wrap; .tit{ margin-top: 94rpx; font-weight: 500; font-size: 48rpx; color: #3D3D3D; } .img{ margin-top: 28rpx; width: 726rpx; height: 246rpx; image{ width: 726rpx; height: 246rpx; } } .ipt{ margin-top: 42rpx; width: 658rpx; height: 80rpx; background: #F3F3F3; border-radius: 0rpx 0rpx 0rpx 0rpx; border: 2rpx solid rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; .ips{ width: 80%; } } .btn{ margin-top: 100rpx; display: flex; align-items: center; justify-content: center; width: 658rpx; height: 86rpx; background: #808080; border-radius: 20rpx 20rpx 20rpx 20rpx; font-weight: 400; font-size: 36rpx; color: #FFFFFF; background: rgba(100,182,167,0.5); } .act1{ background: #1E807A ; } } } </style>