123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- 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'
- })
- }
- })
- }
- })
|