123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- 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
- })
- }
- }
- })
- }
- })
|