// pages/guanlian/guanlian.js. var app = getApp(); Page({ data: { erweima: '', value: '', index: 0 }, onLoad: function (options) { }, onShow: function () { wx.hideHomeButton() }, tap: function (e) { this.setData({ index: e.currentTarget.dataset.index, erweima: '', value: '' }) }, input2: function (e) { this.setData({ value: e.detail.value }) }, input1: function (e) { this.setData({ erweima: e.detail.value }) }, relieve: function () { //解除绑定 var that = this; if (that.data.value == '') { wx.showModal({ title: '提示', content: '请完善中控设备号', showCancel: false }) } else { wx.showLoading({ title: '解绑中...', }) let data = { box_no: that.data.value } app.request('control/unbindingBike', data, 'POST').then(res => { wx.hideLoading(); if (res.statusCode == 200) { wx.showToast({ title: '解除成功', icon: 'none' }) that.setData({ value: '' }) } }) } }, qued: function () { //点击立即绑定 var that = this; if (that.data.erweima == '' || that.data.value == '') { wx.showModal({ title: '提示', content: '请完善设备码或车辆编号', showCancel: false }) } else { wx.showLoading({ title: '绑定中...', }) let data = { bike_no: that.data.erweima, box_no: that.data.value } app.request('control/addBike', data, 'POST').then(res => { wx.hideLoading(); if (res.statusCode == 200) { wx.showToast({ title: '绑定成功', icon: 'none' }) that.setData({ erweima: '', value: '' }) } }) } }, tiaoxing: function () { //点击扫描条形码 var that = this; wx.scanCode({ success: function (res) { console.log(typeof (res.result)) if (typeof (res.result) == 'string') { console.log(res.result) if (res.result.length == 9) { that.setData({ value: res.result }) } else { wx.showToast({ title: '扫错了~', icon: 'none' }) } } }, fail: function () { wx.showToast({ title: '扫码失败', icon: 'none' }) } }) }, erwei: function () { //点击扫描二维码 var that = this; wx.scanCode({ success: function (res) { console.log(res) var code = decodeURIComponent(res.result); var code1 = code.lastIndexOf("\="); var source = code.substring(code1 + 1, code.length); that.setData({ erweima: source }) }, fail: function () { wx.showToast({ title: '扫码失败', icon: 'none' }) } }) }, // scanCode:function(){ // wx.scanCode({ // success: function (res) { // console.log(res) // var code = decodeURIComponent(res.result); // var code1 = code.lastIndexOf("\="); // var source = code.substring(code1 + 1, code.length); // wx.request({ // url: 'https://admin.weilaibike.com/app-api/open/bikeInfoByBikeNo?bike_no=' + source+'&token='+wx.getStorageSync('token'), // method: 'GET', // header: { // 'content-type': 'application/x-www-form-urlencoded' // }, // success: function (res) { // console.log(res) // if (res.statusCode == 200) { // wx.navigateTo({ // url: '../index/index?bike_id=' + res.data.bike_no + '&bike_no=' + res.data.box_no, // }) // } else if (res.statusCode == 401) { // wx.clearStorageSync('token'); // wx.redirectTo({ // url: '../login/index', // }) // }else { // wx.showToast({ // title: res.data.message, // icon: 'none', // duration: 3000 // }) // } // } // }) // }, // fail: function () { // wx.showToast({ // title: '扫码失败', // icon: 'none' // }) // } // }) // } })