柒零 преди 1 година
родител
ревизия
8d54cf4d1f
променени са 1 файла, в които са добавени 40 реда и са изтрити 32 реда
  1. 40 32
      subpages/addMattresses/addMattresses.js

+ 40 - 32
subpages/addMattresses/addMattresses.js

@@ -149,8 +149,9 @@ Page({
     });
   },
   // 开启蓝牙
-  bindViewBlue: function () {
+  bindViewBlue: function ()  {
     const that = this;
+    wx.offBluetoothDeviceFound();
     wx.closeBluetoothAdapter();
     wx.openBluetoothAdapter({
       success(res) {
@@ -214,39 +215,40 @@ Page({
                           if (flag) {
                             var arrD = item['name'].split(' ');
                             item['sn'] = arrD[1];
-                            wx.request({
-                              url: 'https://aipush.aidsleep.cn/checkbeds',
-                              method: 'POST',
-                              header: {
-                                'content-type': 'application/json' // 设置请求的 header
-                              },
-                              data: {
-                                "snlists": arrD[1], // 需要发送的数据
-                                "token": "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3"
-                              },
-                              success: function (res) {
-                                //console.log(res);
-                                if (res.data.data[arrD[1]].trim() == 'yes') {
-                                  item['beOnline'] = 'icon-deng-ok';
-                                } else {
-                                  item['beOnline'] = '';
-                                  // if (doDevices.indexOf(item['deviceId']) >= 0) {
-                                  //   item['beOnline'] = 'icon-deng-ok';
-                                  // }
-                                }
+                            // wx.request({
+                            //   url: 'https://aipush.aidsleep.cn/checkbeds',
+                            //   method: 'POST',
+                            //   header: {
+                            //     'content-type': 'application/json' // 设置请求的 header
+                            //   },
+                            //   data: {
+                            //     "snlists": arrD[1], // 需要发送的数据
+                            //     "token": "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3"
+                            //   },
+                            //   success: function (res) {
+                            //     //console.log(res);
+                            //     if (res.data.data[arrD[1]].trim() == 'yes') {
+                            //       item['beOnline'] = 'icon-deng-ok';
+                            //     } else {
+                            //       item['beOnline'] = '';
+                            //       // if (doDevices.indexOf(item['deviceId']) >= 0) {
+                            //       //   item['beOnline'] = 'icon-deng-ok';
+                            //       // }
+                            //     }
                                 deviceList.push(item);
-                                self.setData({
-                                  deviceList: deviceList,
-                                  showBluetoothList: true
-                                });
-                                wx.setStorageSync('deviceList', deviceList);
-                              },
-                              fail: function (error) {
-                                console.error(error);
-                              }
-                            });
+                            //   },
+                            //   fail: function (error) {
+                            //     console.error(error);
+                            //   }
+                            // });
                           }
                         })
+
+                        self.setData({
+                          deviceList: deviceList,
+                          showBluetoothList: true
+                        });
+                        wx.setStorageSync('deviceList', deviceList);
                       }
                     })
                   }
@@ -270,6 +272,11 @@ Page({
   },
   commitBluetooth() {
     this.onClose();
+    if (this.data.bluetoothSelectIndex < 0) {
+      util.showToast("请选择一个床垫");
+      wx.offBluetoothDeviceFound()
+      return false;
+    }
     var deviceId = this.data.deviceList[this.data.bluetoothSelectIndex].deviceId;
     var name = this.data.deviceList[this.data.bluetoothSelectIndex].name;
     var nameList = this.data.deviceList[this.data.bluetoothSelectIndex].name.split(' ');
@@ -277,7 +284,7 @@ Page({
       deviceId: deviceId,
       sn: nameList[1]
     })
-    wx.offBluetoothDeviceFound()
+      wx.offBluetoothDeviceFound()
   },
   // 开始配网
   bindViewConnect() {
@@ -389,6 +396,7 @@ Page({
       showBluetoothConnected: true
     });
     self.setProcess(0, util.descSucList[0], 1);
+    wx.offBluetoothAdapterStateChange();
     //第一步检查蓝牙适配器是否可用
     wx.onBluetoothAdapterStateChange(function (res) {
       if (!res.available) {