var ble = require('../../services/ble') Page({ data: { statusBarHeight: 44, checking: false, result: null, error: '' }, onLoad: function () { var app = getApp() this.setData({ statusBarHeight: app.globalData.statusBarHeight }) }, onShow: function () { this.checkWearing() }, checkWearing: function () { var self = this self.setData({ checking: true, result: null, error: '' }) if (this._onStatus) ble.off('status', this._onStatus) this._onStatus = function (status) { self.setData({ checking: false }) if (status.bind_status === 1) { self.setData({ result: 'ok' }) } else { self.setData({ result: 'fail', error: '请确认设备已正确佩戴' }) } } ble.on('status', this._onStatus) ble.queryStatus().catch(function (err) { self.setData({ checking: false, result: 'fail', error: err.error_msg || '查询失败' }) }) }, onUnload: function () { if (this._onStatus) ble.off('status', this._onStatus) }, onNext: function () { wx.navigateTo({ url: '/pages/treatment-setup/treatment-setup' }) }, onRetry: function () { this.checkWearing() } })