// pages/scanCode/scanCode.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { code: '', }, scanCode() { let that = this wx.scanCode({ success(res) { // return res.result // console.log(res.result, this) // codenum = res.result wx.showToast({ title: '扫码成功', icon: "none" }) that.setData({ code: res.result }) }, fail(err) { wx.showToast({ title: '扫码失败,请重新尝试', icon: "none" }) } }) }, bindcode(e){ console.log(e); this.setData({ code :e.detail }) }, add() { console.log(app); let data = { serialNumber: this.data.code, userId: wx.getStorageSync('userInfo').userId } wx.request({ url: `https://puyue.yhupai.com/prod-api/iot/operator/device/bindUser?serialNumber=${this.data.code}&userId=${wx.getStorageSync('userInfo').userId}`, method: "POST", header: { "Access-Control-Allow-Headers": 'token', Authorization: `Bearer ${wx.getStorageSync('token')}` }, // data: data, success: (res, header) => { if (res.data.code != 200) { wx.showToast({ title: res.data.msg, icon: 'none' }); } else { wx.showToast({ title: res.data.msg, icon: 'none' }); wx.switchTab({ url: '/pages/home/home', }) // this.setData({ // code:'' // }) } } }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })