const APP = getApp(); Page({ /** * 页面的初始数据 */ data: { //设备集合 devices: [], //默认设备 defaultDevice: 1, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.list() }, /** * 设备列表 */ list() { const params = { openId: APP.globalData.openId } APP.Get(APP.Url.listBindDevices, params).then(res => { this.setData({ devices: res.data }) }) }, /** * 切换当前设备 */ changeDevice(event) { const that = this; const params = { openNum: event.currentTarget.dataset.opennum } wx.showModal({ title: '提示', content: '确定切换到该设备吗', success(res) { if (res.confirm) { APP.Post(APP.Url.switchDefaultDevice, params).then(res => { APP.Modal.tips("切换成功"); that.list(); }) } } }) }, })