import { BluetoothManager, BtErrorCode, CMD } from '../../service/BluWkm' var app = getApp(); const bluM = new BluetoothManager Page({ data: { message: [], bike_id: '', bike_no: '', tap: false, switch1Checked:false }, onLoad: function (options) { var that = this; that.setData({ bike_id: options.bike_id, bike_no: options.bike_no, }) this.refresh1() }, switch1Change: function (e) { console.log(e) var that = this; wx.openBluetoothAdapter({ success(res) { console.log(res) that.setData({ switch1Checked: e.detail.value }) }, fail(err) { console.log(err) wx.showModal({ title: '提示', content: '请开启蓝牙', showCancel: false }) that.setData({ switch1Checked: false }) } }) }, refresh: function () { this.setData({ tap: true }) this.refresh1() }, refresh1: function () { //刷新信息 var that = this; var data= { box_no: this.data.bike_no }; app.request('open/bikeInfo',data,'GET').then(res=>{ console.log(res) if (res.statusCode == 200) { that.setData({ message: res.data, }) if(res.data.is_link==0){ that.setData({switch1Checked:true}) }else{ that.setData({switch1Checked:false}) } if (that.data.tap == true) { wx.showToast({ title: '成功', icon: 'none' }) } } }) }, bikeBell: function () { //响铃 var that = this; if(that.data.switch1Checked){ wx.showLoading({ title: '连接蓝牙中...', mask:true }) bluM.connectDeivece(that.data.bike_no, CMD.bell) }else{ wx.showLoading({ title: '找车中...', }) var data = { bike_no: that.data.bike_id } app.request('open/bikeBell',data,'POST').then(res=>{ console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '找车成功', icon: 'none' }) } }) } }, bikeOpen: function () { //开锁 var that = this; if(that.data.switch1Checked){ wx.showLoading({ title: '连接蓝牙中...', mask:true }) bluM.connectDeivece(that.data.bike_no,CMD.unlock); }else{ wx.showLoading({ title: '开锁中...', }) var data={ bike_no: this.data.bike_id } app.request('open/bikeOpen',data,'POST').then(res=>{ console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '开锁成功', icon: 'none' }) } }) } }, bikeClose: function () { //关锁 var that = this; if(that.data.switch1Checked){ wx.showLoading({ title: '连接蓝牙中...', mask:true }) bluM.connectDeivece(that.data.bike_no,CMD.lock) }else{ wx.showLoading({ title: '关锁中...', }) var data= { bike_no: this.data.bike_id } app.request('open/bikeClose',data,'POST').then(res=>{ console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '关锁成功', icon: 'none' }) } }) } }, bikeOpenBattery: function () { //开电池锁 var that = this; if(that.data.switch1Checked){ wx.showLoading({ title: '连接蓝牙中...', mask:true }) bluM.connectDeivece(that.data.bike_no,CMD.batteryUnlock); }else{ wx.showLoading({ title: '开电池锁中...', }) var data= { bike_no: this.data.bike_id } app.request('open/bikeOpenBattery',data,'POST').then(res=>{ console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '开电池锁成功', icon: 'none' }) } }) } }, bikeCloseBattery: function () { //关电池锁 var that = this; if(that.data.switch1Checked){ wx.showLoading({ title: '连接蓝牙中...', mask:true }) bluM.connectDeivece(that.data.bike_no,CMD.batteryUnlock); }else{ var data= { bike_no: this.data.bike_id } app.request('open/bikeCloseBattery',data,'POST').then(res=>{ console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '关电池锁成功', icon: 'none' }) } }) } }, bikeBattery: function () { var that = this; var data= { bike_no: this.data.bike_id } app.request('open/newBikeBatteryMSG',data,'POST').then(res=>{ console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '刷新电量成功', icon: 'none' }) } }) }, bikeLocation: function () { var that = this; var data= { bike_no: this.data.bike_id } app.request('open/newBikeLocation',data,'POST').then(res=>{ console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '获取位置成功', icon: 'none' }) } }) }, chongqi: function () { console.log(this.data.bike_id) var that = this; var data= { bike_no: this.data.bike_id } app.request('open/rebootBox',data,'POST').then(res=>{ console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '重启中控成功', icon: 'none' }) } }) } })