import { BluetoothManager, BtErrorCode } from '../../service/BlueMgr' const bluM = new BluetoothManager Page({ data: { message:[], bike_id:'', bike_no:'', tap:false }, onLoad: function (options) { var that = this; console.log(options) that.setData({ bike_id:options.bike_id, bike_no: options.bike_no, }) this.refresh1() wx.showLoading({ title: '初始化蓝牙中...', mask:true }) bluM.connectDeivece(options.bike_no).then(res => { //蓝牙连接成功 是否用蓝牙 wx.hideLoading() wx.showToast({ title: '蓝牙初始化成功', icon:'none', duration:2000 }) }, rej => { console.log(rej) //蓝牙连接异常 wx.hideLoading() wx.getBluetoothAdapterState({ success(res) { console.log(res) if (res.available == false) { wx.showModal({ title: '提示', content: '手动开启蓝牙体验快速开锁~', showCancel: false }) }else{ wx.showModal({ title: '提示', content: '蓝牙扫描超时~', showCancel: false }) } } }) }).catch(err=>{ wx.hideLoading() wx.showToast({ title: '蓝牙初始化失败', icon: 'none', duration: 2000 }) }) }, refresh:function(){ this.setData({tap:true}) this.refresh1() }, refresh1:function(){ //刷新信息 var that = this; wx.request({ url: 'https://admin.weilaibike.com/app-api/open/bikeInfo', method: 'GET', data: { box_no: this.data.bike_no, token:wx.getStorageSync('token') }, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { console.log(res) if (res.statusCode == 200) { that.setData({ message:res.data }) if(that.data.tap==true){ wx.showToast({ title: '成功', icon: 'none' }) } } else if (res.statusCode == 401) { wx.clearStorageSync('token'); wx.redirectTo({ url: '../login/index', }) }else { wx.showToast({ title: res.data.message, icon: 'none', duration: 3000 }) } } }) }, bikeBell:function(){ //响铃 var that = this; bluM.connectDeivece(that.data.bike_no).then(res => { console.log('bellbike ===>') return bluM.bellBike() }, rej => { //抛出异常 当前蓝牙不可用 console.log(rej, 123) wx.request({ url: 'https://admin.weilaibike.com/app-api/open/bikeBell', method: 'POST', data: { bike_no: that.data.bike_id, token: wx.getStorageSync('token') }, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '找车成功', icon: 'none' }) } else if (res.statusCode == 401) { wx.clearStorageSync('token'); wx.redirectTo({ url: '../login/index', }) }else { wx.showToast({ title: res.data.message, icon: 'none', duration: 3000 }) } } }) }).then(res => { console.log(res, 1234) }, rej => { console.log(rej, 12345) wx.request({ url: 'https://admin.weilaibike.com/app-api/open/bikeBell', method: 'POST', data: { bike_no: that.data.bike_id, token: wx.getStorageSync('token') }, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '找车成功', icon: 'none' }) } else if (res.statusCode == 401) { wx.clearStorageSync('token'); wx.redirectTo({ url: '../login/index', }) }else { wx.showToast({ title: res.data.message, icon: 'none', duration: 3000 }) } } }) }) }, bikeOpen: function () { //开锁 var that = this; wx.request({ url: 'https://admin.weilaibike.com/app-api/open/bikeOpen', method: 'POST', data: { bike_no: this.data.bike_id, token: wx.getStorageSync('token') }, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { bluM.connectDeivece(that.data.bike_no).then(res => { console.log('连接成功') bluM.unlockBike() }) console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '开锁成功', icon: 'none' }) } else if (res.statusCode == 401) { wx.clearStorageSync('token'); wx.redirectTo({ url: '../login/index', }) }else { wx.showToast({ title: res.data.message, icon: 'none', duration: 3000 }) } } }) }, bikeClose: function () { //关锁 var that = this; wx.request({ url: 'https://admin.weilaibike.com/app-api/open/bikeClose', method: 'POST', data: { bike_no: this.data.bike_id, token: wx.getStorageSync('token') }, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { console.log(res) bluM.connectDeivece(that.data.bike_no).then(res => { console.log('lockbike') return bluM.lockBike() }, reject => { }) if (res.statusCode == 200) { wx.showToast({ title: '关锁成功', icon: 'none' }) } else if (res.statusCode == 401) { wx.clearStorageSync('token'); wx.redirectTo({ url: '../login/index', }) }else { wx.showToast({ title: res.data.message, icon: 'none', duration: 3000 }) } } }) }, bikeOpenBattery: function () { //开电池锁 var that = this; wx.request({ url: 'https://admin.weilaibike.com/app-api/open/bikeOpenBattery', method: 'POST', data: { bike_no: this.data.bike_id, token: wx.getStorageSync('token') }, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { console.log(res) bluM.connectDeivece(that.data.bike_no).then(res => { return bluM.batteryUnlockBike() }) if (res.statusCode == 200) { wx.showToast({ title: '开电池锁成功', icon: 'none' }) } else if (res.statusCode == 401) { wx.clearStorageSync('token'); wx.redirectTo({ url: '../login/index', }) }else { wx.showToast({ title: res.data.message, icon: 'none', duration: 3000 }) } } }) }, bikeCloseBattery: function () { //关电池锁 var that = this; wx.request({ url: 'https://admin.weilaibike.com/app-api/open/bikeCloseBattery', method: 'POST', data: { bike_no: this.data.bike_id, token: wx.getStorageSync('token') }, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { bluM.connectDeivece(that.data.bike_no).then(res => { return bluM.batteryLockBike() }) console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '关电池锁成功', icon: 'none' }) } else if (res.statusCode == 401){ wx.clearStorageSync('token'); wx.redirectTo({ url: '../login/index', }) }else{ wx.showToast({ title: res.data.message, icon: 'none', duration: 3000 }) } } }) }, bikeBattery:function(){ var that = this; wx.request({ url: 'https://admin.weilaibike.com/app-api/open/newBikeBatteryMSG', method: 'POST', data: { bike_no: that.data.bike_id, token: wx.getStorageSync('token') }, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { bluM.connectDeivece(that.data.bike_id).then(res => { console.log('bellbike ===>') return bluM.boxReboot() }) console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '刷新电量成功', icon: 'none' }) } else if (res.statusCode == 401) { wx.clearStorageSync('token'); wx.redirectTo({ url: '../login/index', }) } else { wx.showToast({ title: res.data.message, icon: 'none', duration: 3000 }) } } }) }, bikeLocation:function(){ var that = this; wx.request({ url: 'https://admin.weilaibike.com/app-api/open/newBikeLocation', method: 'POST', data: { bike_no: that.data.bike_id, token: wx.getStorageSync('token') }, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { bluM.connectDeivece(that.data.bike_id).then(res => { console.log('bellbike ===>') return bluM.boxReboot() }) console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '获取位置成功', icon: 'none' }) } else if (res.statusCode == 401) { wx.clearStorageSync('token'); wx.redirectTo({ url: '../login/index', }) } else { wx.showToast({ title: res.data.message, icon: 'none', duration: 3000 }) } } }) }, chongqi:function(){ console.log(this.data.bike_id) var that = this; wx.request({ url: 'https://admin.weilaibike.com/app-api/open/rebootBox', method: 'POST', data: { bike_no: that.data.bike_id, token: wx.getStorageSync('token') }, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { bluM.connectDeivece(that.data.bike_id).then(res => { console.log('bellbike ===>') return bluM.boxReboot() }) console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '重启中控成功', icon: 'none' }) } else if (res.statusCode == 401) { wx.clearStorageSync('token'); wx.redirectTo({ url: '../login/index', }) } else { wx.showToast({ title: res.data.message, icon: 'none', duration: 3000 }) } } }) } })