const App = getApp() let regeneratorRuntime = require("../../utils/regenerator-runtime/runtime"); //获取应用实例 const app = getApp(); var token = wx.getStorageSync('token'); var http = require("../../utils/config.js"); import { BluetoothManager, BtErrorCode } from '../../service/BlueMgr' const bluM = new BluetoothManager Page({ data: { current: 3, bike_no: '', //车牌号 hintShow: false, //是否显示提示弹窗 sideShow: false, //是否显示侧边栏 footerShow: true, iconList1: [{ icon: "http://resource.weilaibike.com/xiaobanma_yunwei/outline_xbm.png", con: "下线" }, { icon: "http://resource.weilaibike.com/xiaobanma_yunwei/lowPower_xbm.png", con: "低电量" }, { icon: "http://resource.weilaibike.com/xiaobanma_yunwei/noUser_xbm.png", con: "未使用" }, { icon: "http://resource.weilaibike.com/trobole.png", con: "故障" }, { icon: "http://resource.weilaibike.com/xiaobanma_yunwei/repair_xbm.png", con: "待维修" }, { icon: "http://resource.weilaibike.com/xiaobanma_yunwei/noInPark_xbm.png", con: "未在停车区" }, { icon: "http://resource.weilaibike.com/xiaobanma_yunwei/riding_xbm.png", con: "骑行中" }, { icon: "http://resource.weilaibike.com/bike_yunwei/outLi.png", con: "离线" }, { icon: "http://resource.weilaibike.com/bike_yunwei/work.png", con: "运维人员骑行" }, ], markers: [], //显示单车、停车的P polygons: [], //区域 longitude: '113.779801', latitude: '34.753993', // allArea: [{ // text: '全部区域', // value: 0, // areaID: '' // }], allArea: [], allEle: [{ text: '全部电量', value: 0, areaID: '' }, { text: '70%以下', value: 1, areaID: '70' }, { text: '60%以下', value: 2, areaID: '60' }, { text: '50%以下', value: 3, areaID: '50' }, { text: '30%以下', value: 4, areaID: '30' }, { text: '20%以下', value: 5, areaID: '20' }, ], allStatus: [{ text: '全部状态', value: 0, areaID: '' }], allDay: [{ text: '使用状态', value: 0 }, { text: '1天未使用', value: 1 }, { text: '3天未使用', value: 2 }, { text: '7天未使用', value: 3 } ], area: 0, ele: 0, status: 0, day: 0, show: false, //车子详情的布尔值 longitude: '113.779801', latitude: '34.753993', id: '', //停车区域的ID stopP: false, //判断是否显示停车区域 polygons1: [], //可骑行区域 先用这个变量代表 controls: [], //地图上当前定位的箭头 background: '', //弹窗的背景颜色 over: '', //关闭图标 location: '', //是否有位置权限 bluetooth: false, //是否开启蓝牙 false开始 true未开启 box_no: '', //中控编号 bikeDetail: [], bikeId: '', areaID: '', low_power: '', state: '', use_state: '', parkAreaShow: false, //还车点是否显示 noParkAreaShow: true, //禁停区是否显示 ridding: true, moreShow: false, screenHeight: '', //屏幕可视高度 areas: [], parking: [], parking_points: [], no_parking: [], no_parking_points: [], parkShow: '', switch1Checked: '', delBtnWidth: 200, //删除或完成 按钮宽度 typeName: '', //1 待认领工单 2已领工单 page: 1, //当前页面 workShow: false, //工单弹窗 workCount: '', //侧边栏报修数量(未读) list: [], //工单列表 workState: 1, //工单列表状态【1 待领取 2已领】 repairsList: [], //报修列表 repairsCount: '', //侧边栏工单数量(未认领) repairsState: 1, //报修列表状态【1 未读 2已读】 repairsShow: false, //是否显示报修弹窗 【false 不显示 true 显示】 topNum: 0, }, touchS: function (e) { if (e.touches.length == 1) { this.setData({ //设置触摸起始点水平方向位置 startX: e.touches[0].clientX }); } }, touchM: function (e) { // console.log(this.data.list[index].txtStyle) // console.log(e); if (e.touches.length == 1) { //手指移动时水平方向位置 var moveX = e.touches[0].clientX; //手指起始点位置与移动期间的差值 var disX = this.data.startX - moveX; // console.log(disX,'disX') var delBtnWidth = this.data.delBtnWidth; var txtStyle = ""; if (disX == 0 || disX < 0) { //如果移动距离小于等于0,文本层位置不变 txtStyle = "left:0rpx"; } else if (disX > 0) { //移动距离大于0,文本层left值等于手指移动距离 txtStyle = "left:-" + disX + "rpx"; if (disX >= delBtnWidth) { //控制手指移动距离最大值为删除按钮的宽度 txtStyle = "left:-" + delBtnWidth + "rpx"; } } //获取手指触摸的是哪一项 var index = e.currentTarget.dataset.idx; var list = this.data.list; list[index].txtStyle = txtStyle; //更新列表的状态 this.setData({ list: list }); } }, touchE: function (e) { if (e.changedTouches.length == 1) { //手指移动结束后水平位置 var endX = e.changedTouches[0].clientX; //触摸开始与结束,手指移动的距离 var disX = this.data.startX - endX; var delBtnWidth = this.data.delBtnWidth; //如果距离小于删除按钮的1/2,不显示删除按钮 var txtStyle = disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "rpx" : "left:0rpx"; //获取手指触摸的是哪一项 var index = e.currentTarget.dataset.idx; var list = this.data.list; list[index].txtStyle = txtStyle; //更新列表的状态 this.setData({ list: list }); } }, goTop: function (e) { // 一键回到顶部 this.setData({ topNum: 0 }); }, // //获取元素自适应后的实际宽度 // getEleWidth: function (w) { // var real = 0; // try { // var res = wx.getSystemInfoSync().windowWidth; // var scale = (750 / 2) / (w / 2); //以宽度750px设计稿做宽度的自适应 // // console.log(scale); // real = Math.floor(res / scale); // return real; // } catch (e) { // return false; // // Do something when catch error // } // }, // initEleWidth: function () { // var delBtnWidth = this.getEleWidth(this.data.delBtnWidth); // this.setData({ // delBtnWidth: delBtnWidth // }); // }, async onLoad(options) { console.log(wx.getStorageSync('allArea'), 'allArea') var that = this; that.setData({ screenHeight: app.globalData.screenHeight, }) let timer = setTimeout(function () { if (wx.getStorageSync('allArea')) { let allArea = wx.getStorageSync('allArea') let allState = wx.getStorageSync('allState') that.setData({ allArea, allStatus: allState }) } console.log(that.data.allArea) let curVal = wx.getStorageSync('curVal') console.log(curVal, 'log_curVal') if (curVal) { that.setData({ area: curVal }) } let areaID = wx.getStorageSync('curId') console.log(areaID, 'log_areaID') if (areaID) { that.setData({ areaID }) } else { let id = that.data.allArea[0].areaID that.setData({ areaID: id }) } that.menu = that.selectComponent("#menu"); that.menu.changeTitle(that.data.allArea[that.data.area].text); }, 500) that.posi(); //获取当前位置 await this.initData(1) if (options.bike_no) { that.getBike_info(options.bike_no) } if (options.scan == 1) { this.scanCode(); } that.getBikes(); // that.lookWork(); // that.initEleWidth(); }, // lookWork() { // let url = url = "work_order/list?planned=" + 1 + "&bike_no=" + 10010010101 // app.request(url, '', 'GET').then(res => { // console.log(res) // this.setData({ // list: res.data.data // }) // }) // }, /* * 工单弹窗 报修弹窗 begin */ //关闭弹窗 coverHidn(e) { let show = e.currentTarget.dataset.show; if (show == 1) { this.setData({ moreShow: false, workState: 1 }) } else if (show == 2) { this.setData({ workShow: false, typeName: '' }) } else if (show == 3) { this.setData({ repairsShow: false, typeName: '', repairsState: 1 }) } }, //点击可拨打电话 phone(e) { console.log(1111) wx.makePhoneCall({ phoneNumber: e.currentTarget.dataset.phone }) }, showPop(e) { let show = e.currentTarget.dataset.idx; this.setData({ typeName: show }) if (show == 1) { this.setData({ workShow: true }); this.lookWork(); } else if (show == 2) { this.setData({ repairsShow: true }); this.lookRepairs(); } }, workChoose(e) { wx.showLoading({ title: '加载中...', }) let state = e.currentTarget.dataset.state; this.setData({ workState: state, list: [] }) this.lookWork(); this.goTop(); }, //工单列表 lookWork() { wx.showLoading({ title: '加载中...', }) let that = this; let planned = ''; let url = ""; let state = that.data.workState // console.log(state, 'workState') if (state == 1) { planned = 1 url = "work_order/list?planned=" + planned + "&bike_no=" + that.data.bikeId } else { let planned = 2; url = 'work_order/myWorkOrderList?planned=' + planned + "&bike_no=" + that.data.bikeId } app.request(url, '', 'GET').then(res => { wx.hideLoading(); let work = res.data.data; // console.log(work, '工单列表') if (work.length == 0) { // wx.showToast({ // title: '暂无工单~', // icon: 'none' // }) that.setData({ list: '' }) } else { work.map(i => { i.txtStyle = 'left:0rpx' }) that.setData({ workShow: true, list: work }) // console.log(that.data.list, 'list') } }) }, //接单 getWork(e) { wx.showLoading({ title: '领取中...', }) let id = e.currentTarget.dataset.id console.log(id, 'getWorkid'); app.request('work_order/receive?work_order_id=' + id, '', 'GET').then(res => { wx.hideLoading(); console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '接单成功', icon: "none" }) let work = this.data.list; work.map((i, index) => { if (i.id == id) { work.splice(index, 1) console.log(i) } }) let count = this.data.workCount count = count - 1 this.setData({ list: work, workCount: count }) if (work.length == 0) { wx.showToast({ title: '该车辆已无待领工单~', icon: 'none' }) this.setData({ workShow: false, workCount: '' }) } } }) }, //完成 finishWork(e) { wx.showLoading({ title: '操作中...', }) // console.log('finishWork') let id = e.currentTarget.dataset.id console.log(id, 'finishWorkId') app.request('work_order/over?work_order_id=' + id, '', 'GET').then(res => { wx.hideLoading(); if (res.statusCode == 200) { console.log(res) wx.showToast({ title: '操作成功', icon: "none" }) let list = this.data.list list.map((i, index) => { if (i.id == id) { console.log(i) list.splice(index, 1) } }) this.setData({ list }) if (list.length == 0) { wx.showToast({ title: '已完成所有认领工单~', icon: 'none' }) this.setData({ workShow: false }) } } }) }, //上拉加载 moreWork() { wx.showLoading({ title: '加载中...', }) let that = this; var page = that.data.page + 1; let planned = ''; let url = ""; if (that.data.workState == 1) { planned = 1 url = "work_order/list?planned=" + planned + "&bike_no=" + that.data.bikeId + '&page=' + page } else { planned = 2 url = 'work_order/myWorkOrderList?planned=' + planned + "&bike_no=" + that.data.bikeId + '&page=' + page } app.request(url, '', 'GET').then(res => { wx.hideLoading(); if (res.data.data.length > 0) { let work = res.data.data work.map(i => { i.txtStyle = 'left:0rpx' }) this.setData({ workShow: true, list: that.data.list.concat(work), page }) } else { wx.showToast({ title: '没有更多数据了~', icon: 'none' }) } }) }, //报修列表 lookRepairs() { wx.showLoading({ title: '加载中...', }) let status = '' let state = this.data.repairsState if (state == 1) { status = 0 } else if (state == 2) { status = 1 } app.request('user/userRepaired?bike_no=' + this.data.bikeId + '&status=' + status, '', 'GET').then(res => { if (res.statusCode == 200) { wx.hideLoading(); // console.log(res, '报修列表') let list = res.data.data; if (list.length == 0) { // wx.showToast({ // title: '暂无报修记录~', // icon: 'none' // }) this.setData({ repairsList: [] }) } else { let repairs = res.data.data; repairs.map(i => { i.txtStyle = 'left:0rpx' }) this.setData({ repairsList: res.data.data }) } } }) }, repairsChoose(e) { let state = e.currentTarget.dataset.state; this.setData({ repairsState: state, repairsList: [] }) this.lookRepairs(); this.goTop(); }, markRead(e) { let id = e.currentTarget.dataset.id app.request('user/userRepaired/status?id=' + id, '', 'GET').then(res => { if (res.statusCode == 200) { console.log(res) this.lookRepairs(); let list = this.data.repairsList; if (list.length == 0) { wx.showToast({ title: '暂无报修~', icon: 'none' }) this.setData({ repairsCount: '' }) } else { let count = this.data.repairsCount; count = count - 1; this.setData({ repairsCount: count }) } } }) }, morkRepairs() { wx.showLoading({ title: '加载中...', }) let that = this; let status = ''; var page = that.data.page + 1; let state = this.data.repairsState if (state == 1) { status = 0 } else if (state == 2) { status = 1 } app.request('user/userRepaired?bike_no=' + this.data.bikeId + '&status=' + status + '&page=' + page, '', 'GET').then(res => { wx.hideLoading(); if (res.statusCode == 200) { let list = res.data.data; if (list.length > 0) { this.setData({ repairsList: that.data.repairsList.concat(list), page }) } else { wx.showToast({ title: '没有更多数据了~', icon: 'none' }) } } }) }, /* * 工单弹窗 报修弹窗 end */ more: function () { this.setData({ moreShow: true }) }, async initData(isLoad = false) { var that = this; that.setData({ markers: [] }) wx.showLoading({ title: '加载中...', }) await app.request('getAreas?put_area_id=' + that.data.areaID, '', 'GET').then(res => { wx.hideLoading(); // console.log(res.data.ridding_area); let data = res.data that.setData({ ridding_area: data.ridding_area, no_parking: data.no_parking_area, no_parking_points: data.no_parking_points, parking: data.parking_area, parking_points: data.parking_points }) if (isLoad) { this.showArea(1) if (this.data.noParkAreaShow) this.showNoParking(0) if (this.data.parkAreaShow) this.showParking(0) } }) }, showArea(type = 0) { if (type) { this.setData({ polygons: this.data.ridding_area, }) } else { this.setData({ polygons: this.data.polygons.concat(this.data.ridding_area), }) } }, clear(type = 0) { if (type === 0) { let polygons = this.data.polygons.filter((polygons) => { if (polygons.id.slice(0, 1) === 'A') { return false } return true }) this.setData({ 'polygons': polygons }) } if (type === 1) { let polygons = this.data.polygons.filter((polygons) => { if (polygons.id.slice(0, 1) !== 'P') { return true } return false }) let markers = this.data.markers.filter((polygons) => { if (polygons.id.slice(0, 1) !== 'p') { return true } return false }) this.setData({ 'polygons': polygons, 'markers': markers }) } if (type === 2) { let polygons = this.data.polygons.filter((polygons) => { if (polygons.id.slice(0, 1) !== 'N') { return true } return false }) let markers = this.data.markers.filter((polygons) => { if (polygons.id.slice(0, 1) !== 'n') { return true } return false }) this.setData({ 'polygons': polygons, 'markers': markers }) } }, //显示还车点 0:追加停车点 1:只显示停车点 2:删除停车点 showParking(type = 0) { if (type === 0) { this.setData({ polygons: this.data.polygons.concat(this.data.parking), markers: this.data.markers.concat(this.data.parking_points) }) } if (type === 1) { this.setData({ polygons: this.data.parking, markers: this.data.parking_points }) } if (type === 2) { this.clear(1) } }, showNoParking(type = 0) { if (type === 0) { this.setData({ polygons: this.data.polygons.concat(this.data.no_parking), markers: this.data.markers.concat(this.data.no_parking_points) }) } if (type === 1) { this.setData({ polygons: this.data.no_parking, markers: this.data.no_parking_points }) } if (type === 2) { this.clear(2) } }, scanCode: function () { var that = this; console.log('scanCode') wx.scanCode({ success: function (res) { let index = res.result.lastIndexOf("\="); var code = res.result.substring(index + 1, res.result.length); that.setData({ bikeId: code }) that.getBike_info(code) }, fail: function () { wx.showModal({ title: '提示', content: '手动输入车辆标号', success: function (res) { if (res.confirm) { wx.navigateTo({ url: '/pages/manualInp/manualInp', }) } } }) } }) }, getBikes: function (clear = 0) { wx.showLoading({ title: '加载中...', }) var that = this; var areaId = that.data.areaID; var low_power = that.data.low_power; var state = that.data.state; var use_state = that.data.use_state; let time = parseInt(use_state / 1000) if (time === 0) { time = '' } var data = { put_area_id: areaId, battery_power: low_power, all_states: state, last_use_bike_end_time: time }; app.request('getBikes', data, 'POST').then(res => { wx.hideLoading(); console.log(res, 'bikes') let markers = this.data.markers if (clear) { markers = that.data.markers.filter((marker) => { if (marker.id.slice(0, 1) === 'B') { return false } return true }) } that.setData({ markers: markers.concat(res.data) }) }) }, load: function () { wx.showLoading({ title: '刷新中...', }) this.setData({ markers: [] }) if (this.data.noParkAreaShow) { this.showNoParking(0); } else { this.showNoParking(2); } if (this.data.parkAreaShow) { this.showParking(0) } else { this.showParking(2) } this.getBikes(1); wx.hideLoading(); }, posi: function () { wx.showLoading({ title: '定位中...', }) //点击定位 var that = this; wx.getLocation({ type: 'gcj02', success: (res) => { wx.hideLoading(); // console.log(res, ) var latitude = res.latitude var longitude = res.longitude that.setData({ longitude: longitude, latitude: latitude }) }, fail: function (err) { wx.hideLoading(); console.log(err) } }) }, change: function (e) { let that = this; console.log(e.detail) wx.setStorageSync('curVal', that.data.allArea[e.detail].value) wx.setStorageSync('curId', that.data.allArea[e.detail].areaID) this.setData({ areaID: that.data.allArea[e.detail].areaID }) this.initData(1) that.getBikes(1) }, change2: function (e) { //选择电量 console.log(e) this.setData({ low_power: this.data.allEle[e.detail].areaID }) this.getBikes(1); }, change3: function (e) { //选择状态 console.log(e) this.setData({ state: this.data.allStatus[e.detail].areaID }) this.getBikes(1) }, change4: function (e) { //选择使用状态 var time = new Date().getTime(); var index = e.detail if (index == 0) { time = ""; } else if (index == 1) { time = time - 86400000 * 1; } else if (index == 2) { time = time - 86400000 * 3; } else if (index == 3) { time = time - 86400000 * 7; } this.setData({ use_state: time }) this.getBikes(1) }, marker: function ({ markerId }) { if (this.data.repairsShow || this.data.sideShow || this.data.workShow) return; let type = markerId.slice(0, 1) //车辆索引 if (type === 'B') { this.getBike_info(markerId.slice(1)) } }, // 获取车辆信息 getBike_info: function (bikeId = false) { wx.showLoading({ title: '加载中...', }) if (typeof bikeId === 'object') { bikeId = this.data.bikeId } console.log(bikeId, 'bikeId') this.setData({ bikeId }) console.log(this.data.bikeId, 'bike_no') app.request('bike/getBikeInfo?bike_no=' + this.data.bikeId, '', 'GET').then(res => { wx.hideLoading(); console.log(res, '获取车辆信息') if (res.data.bike_info == '') { this.setData({ sideShow: false }) wx.showToast({ title: '暂无该车辆信息~', }) } else { this.setData({ bikeDetail: res.data, sideShow: true, footerShow: false }) } }) app.request("work_order/list?planned=" + 1 + "&bike_no=" + bikeId, '', 'GET').then(res => { if (res.statusCode == 200) { // console.log(res.data.meta.total, '工单数量') this.setData({ workCount: res.data.meta.total }) } }) app.request('user/userRepaired?bike_no=' + bikeId + '&&status=' + 0, '', 'GET').then(res => { // console.log(res.data) // console.log(res.data.meta.total, '报修数量') this.setData({ repairsCount: res.data.meta.total }) }) }, //获取输入框的值 bindKeyInput(e) { // console.log(e.detail.value, 11111) this.setData({ bikeId: e.detail.value }) }, refresh_power: function () { this.getBike_info(this.data.bikeId), wx.showToast({ title: '刷新完成', icon: 'none' }) }, bikePosition: function () { wx.navigateTo({ url: '/pages/carPosition/carPosition?id=' + this.data.bikeDetail.bike_info.id + '&bike_no=' + this.data.bikeDetail.bike_info.bike_no, }) }, recentOrder: function () { wx.navigateTo({ url: '/pages/recentOrder/recentOrder?id=' + this.data.bikeDetail.bike_info.id, }) }, showPopup() { this.setData({ show: true }); }, onClose() { this.setData({ show: false }); }, modify: function () { //跳转修改车辆信息 var bike = this.data.bikeDetail.bike_info wx.navigateTo({ url: '/pages/amendCar/amendCar?id=' + bike.id + '&bike_no=' + bike.bike_no + '&box_no=' + bike.box_no, }) }, parkShow() { this.setData({ parkAreaShow: !this.data.parkAreaShow }) if (this.data.parkAreaShow) { this.showParking(0) } else { this.showParking(2) } }, forbidShow() { this.setData({ noParkAreaShow: !this.data.noParkAreaShow }) if (this.data.noParkAreaShow) { this.showNoParking(0); } else { this.showNoParking(2); } }, //显示图标提示弹窗 hintIcon() { this.setData({ hintShow: true }) wx.hideTabBar({}); }, // 关闭图标提示弹窗 closeHint() { this.setData({ hintShow: false }) wx.showTabBar({}) }, //关闭侧边栏 closeSide() { this.setData({ sideShow: false, footerShow: true, workShow: false, workState: 1, repairsState: 1, typeName: '' }) wx.showTabBar({}) }, //调转我的工单 skipWork() { wx.navigateTo({ url: '/pages/myWork/myWork', }) }, // 鸣笛 whistle() { var that = this; if (that.data.switch1Checked) { wx.showLoading({ title: '连接蓝牙中...', }) bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => { wx.showToast({ title: '响铃成功', icon: 'none' }) return bluM.bellBike() }) } else { app.request('bike/bikeBell?bike_id=' + that.data.bikeDetail.bike_info.id, '', 'GET').then(res => { if (res.statusCode == 200) { bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => { return bluM.bellBike() }) wx.showToast({ title: '响铃成功', icon: 'none' }) } }) } }, //开锁 unlock() { var that = this; if (that.data.switch1Checked) { wx.showLoading({ title: '连接蓝牙中...', }) bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => { wx.showToast({ title: '开锁成功', icon: 'none' }) return bluM.unlockBike() }) } else { app.request('bike/openBikeLock?bike_id=' + that.data.bikeDetail.bike_info.id, '', 'GET').then(res => { if (res.statusCode == 200) { bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => { return bluM.unlockBike() }) wx.showToast({ title: '开锁成功', icon: 'none' }) } }) } }, //关锁 close_lock() { var that = this; if (that.data.switch1Checked) { wx.showLoading({ title: '连接蓝牙中...', }) bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => { wx.showToast({ title: '关锁成功', icon: 'none' }) return bluM.lockBike() }) } else { // console.log('接口') app.request('bike/closeBikeLock?bike_id=' + that.data.bikeDetail.bike_info.id, '', 'GET').then(res => { if (res.statusCode == 200) { bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => { return bluM.lockBike() }) wx.showToast({ title: '关锁成功', icon: 'none' }) } }) } }, bike_detail: function () { //车辆详情页面 var bike = this.data.bikeDetail.bike_info; wx.navigateTo({ url: '/pages/carDetails/carDetails?bike_no=' + bike.bike_no + '&id=' + bike.id, }) }, reqair: function () { var bike = this.data.bikeDetail.bike_info; wx.navigateTo({ url: '/pages/reqair/reqair?bike_no=' + bike.bike_no, }) }, //开电池锁 battery_load() { var that = this; if (that.data.switch1Checked) { wx.showLoading({ title: '连接蓝牙中...', }) bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => { wx.showToast({ title: '开电池锁成功', icon: 'none' }) return bluM.batteryUnlockBike() }) } else { app.request('bike/openBatteryLock?bike_id=' + that.data.bikeDetail.bike_info.id, '', 'GET').then(res => { if (res.statusCode == 200) { bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => { return bluM.batteryUnlockBike() }) wx.showToast({ title: '开电池锁成功', icon: 'none' }) } }) } }, renewalPower: function () { //更新电量 app.request('bike/newBikeBatteryMSG?bike_id=' + this.data.bikeDetail.bike_info.id, '', 'GET').then(res => { // console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '更新电量成功', icon: 'none' }) } }) }, renewalLocation: function () { //更新位置 app.request('bike/newBikeLocation?bike_id=' + this.data.bikeDetail.bike_info.id, '', 'GET').then(res => { if (res.statusCode == 200) { wx.showToast({ title: '更新位置成功', icon: 'none' }) } }) }, renewal: function () { //重启中控 var that = this; if (that.data.switch1Checked) { wx.showLoading({ title: '连接蓝牙中...', }) bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => { wx.showToast({ title: '重启中控成功', icon: 'none' }) return bluM.boxReboot() }) } else { app.request('bike/rebootBox?bike_id=' + that.data.bikeDetail.bike_info.id, '', 'GET').then(res => { if (res.statusCode == 200) { bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => { return bluM.boxReboot() }) wx.showToast({ title: '重启中控成功', icon: 'none' }) } }) } }, // 设为停车区 recover() { app.request('bike/repairInParking?bike_id=' + this.data.bikeDetail.bike_info.id, '', 'GET').then(res => { // console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '操作成功', icon: 'none' }) } else { wx.showToast({ title: '操作失败', icon: 'none' }) } }) }, //上线 online() { app.request('bike/login?bike_id=' + this.data.bikeDetail.bike_info.id, '', 'GET').then(res => { // console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '上线成功', icon: 'none' }) } }) }, //下线 Offline() { app.request('bike/logout?bike_id=' + this.data.bikeDetail.bike_info.id, '', 'GET').then(res => { console.log(res) if (res.statusCode == 200) { wx.showToast({ title: '下线成功', icon: 'none' }) } }) }, onShow() { // console.log(app.globalData.swichChecked) this.setData({ switch1Checked: app.globalData.swichChecked, }) }, operate(){ wx.navigateTo({ url: '/pages/bikeInfo/bikeInfo' }) }, switch1Change: function (e) { console.log(e) var that = this; wx.openBluetoothAdapter({ success(res) { console.log(res) that.setData({ switch1Checked: e.detail.value }) app.globalData.swichChecked = e.detail.value; }, fail(err) { console.log(err) wx.showModal({ title: '提示', content: '请开启蓝牙', showCancel: false }) that.setData({ switch1Checked: false }) app.globalData.swichChecked = false; } }) }, onShareAppMessage: function () { return { path: "/pages/login/login", title: "轻松出行,方便你我~" }; }, })