柒零 1 an în urmă
părinte
comite
efe7ce706a
1 a modificat fișierele cu 81 adăugiri și 1 ștergeri
  1. 81 1
      subpages/addMattresses/addMattresses.js

+ 81 - 1
subpages/addMattresses/addMattresses.js

@@ -11,12 +11,14 @@ Page({
    * 页面的初始数据
    */
   data: {
+    isEdit:false,
     showBluetoothList: false,
     showBluetoothConnected: false,//连接中
     isBluetoothConnected: false,//连接成功
     bluetoothConnectedStep: 0,
     placeOfUse: "",
     usingHuman: "",
+    pid:"",
     sn: "",
     ssid: "",
     password: "",
@@ -73,6 +75,80 @@ Page({
     this.checkSn(this.data.deviceId);
    
     
+  },
+  commitUserData() { 
+    const that = this;
+    if (that.data.isEdit) {
+      wx.request({
+        url: 'https://aipush.aidsleep.cn/customeredit',
+        method: 'POST',
+        data: {
+          token: "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3" || wx.getStorageSync('token'),
+          pid: this.data.pid,
+          sntram: this.data.deviceId,
+          per: this.data.usingHuman,
+          loc: this.data.placeOfUse,
+        },
+        success: (res) => {
+          var codes = res.data.codes;
+          if (codes && codes == 'success') {
+            wx.showToast({
+              icon: 'none',
+              title: "添加成功"
+            });
+            setTimeout(() => {
+              wx.navigateBack()
+            }, 800);
+          } else {
+            wx.showToast({
+              icon: 'none',
+              title: "添加失败"
+            });
+          }
+        },
+        fail: () => {
+          wx.showToast({
+            icon: 'none',
+            title: "添加失败"
+          });
+        }
+      });
+      return
+    }
+    wx.request({
+      url: 'https://aipush.aidsleep.cn/wxsaveunionsn',
+      method: 'POST',
+      data: {
+        token: "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3" || wx.getStorageSync('token'),
+        unionid: wx.getStorageSync("unionid"),
+        sntram: this.data.deviceId,
+        per: this.data.usingHuman,
+        loc: this.data.placeOfUse,
+      },
+      success: (res) => {
+        var codes = res.data.codes;
+        if (codes && codes == 'success') {
+          wx.showToast({
+            icon: 'none',
+            title: "添加成功"
+          });
+          setTimeout(() => {
+            wx.navigateBack()
+          }, 800);
+        } else {
+          wx.showToast({
+            icon: 'none',
+            title: "添加失败"
+          });
+        }
+      },
+      fail: () => {
+        wx.showToast({
+          icon: 'none',
+          title: "添加失败"
+        });
+      }
+    });
   },
   // 开启蓝牙
   bindViewBlue: function () {
@@ -112,6 +188,8 @@ Page({
                 wx.startBluetoothDevicesDiscovery({
                   success: function (res) {
                     wx.onBluetoothDeviceFound(function (res) {
+                      console.log(res);
+                      
                       var list = util.filterDevice(res.devices, "name");
                       if (list.length > 0) {
                         console.log('==========onBluetoothDeviceFound===========');
@@ -125,7 +203,6 @@ Page({
                         console.log(deviceList);
                         console.log(doDevices);
                         wx.setStorageSync('doDevices', doDevices);
-
                         wx.hideLoading();
                         list.forEach(function (item) {
                           var flag = true;
@@ -564,6 +641,7 @@ Page({
       });
       clearInterval(timeId);
       sequenceControl = 0;
+      self.commitUserData();
     }
   },
 
@@ -596,6 +674,8 @@ Page({
       const item = wx.getStorageSync("item");
       if (item) {
         this.setData({
+          isEdit: true,
+          pid: item.pid,
           placeOfUse: item.location,
           usingHuman: item.person,
           sn: item.sn,