From ec7f5ba1f7eb84507e1c8e7b6f66b1ecfbc22728 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期四, 17 四月 2025 17:31:25 +0800
Subject: [PATCH] 线上监管

---
 pages/inspection/scene/info/device-info/index.js |  134 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 99 insertions(+), 35 deletions(-)

diff --git a/pages/inspection/scene/info/device-info/index.js b/pages/inspection/scene/info/device-info/index.js
index b850077..52565b2 100644
--- a/pages/inspection/scene/info/device-info/index.js
+++ b/pages/inspection/scene/info/device-info/index.js
@@ -11,62 +11,126 @@
     deviceType: 0,
     // 妯″紡锛宎dd: 鏂板璁惧锛泆pdate锛氭洿鏂拌澶�
     mode: 'add',
+    submitText: '淇濆瓨',
   },
 
   onLoad(options) {
-    if (options.type) {
-      this.setData({ deviceType: parseInt(options.type) });
-      let barTitle, _formArr;
-      switch (options.type) {
-        case '0':
-          barTitle = '鏂板鐩戞祴璁惧';
-          _formArr = monitorDeviceForm;
-          break;
-        case '1':
-          barTitle = '鏂板娌荤悊璁惧';
-          _formArr = treatmentDeviceForm;
-          break;
-        case '2':
-          barTitle = '鏂板鐢熶骇璁惧';
-          _formArr = productionDeviceForm;
-          break;
-        default:
-          barTitle = '璁惧淇℃伅';
-          _formArr = monitorDeviceForm;
-          break;
+    this.getOpenerEventChannel().on('acceptDeviceData', data => {
+      if (data) {
+        const { scene, type, mode, deviceInfo } = data;
+        let barTitle = mode == 'add' ? '鏂板' : '淇敼',
+          _formArr;
+        switch (type) {
+          case 1:
+            barTitle += '娌荤悊璁惧';
+            let defaultValue1 =
+              mode == 'update'
+                ? deviceInfo
+                : {
+                    piSceneGuid: scene.guid,
+                    piSceneTypeId: scene.typeid,
+                  };
+            _formArr = treatmentDeviceForm(scene.typeid, defaultValue1);
+            break;
+          case 2:
+            barTitle += '鐢熶骇璁惧';
+            let defaultValue2 =
+              mode == 'update'
+                ? deviceInfo
+                : {
+                    wiSceneGuid: scene.guid,
+                    wiSceneTypeId: scene.typeid,
+                  };
+            _formArr = productionDeviceForm(scene.typeid, defaultValue2);
+            break;
+          case 0:
+          default:
+            barTitle += '鐩戞祴璁惧';
+            let defaultValue0 =
+              mode == 'update'
+                ? deviceInfo
+                : {
+                    diSceneGuid: scene.guid,
+                    diSceneTypeId: scene.typeid,
+                  };
+            _formArr = monitorDeviceForm(scene.typeid, defaultValue0);
+            break;
+        }
+        wx.setNavigationBarTitle({
+          title: barTitle,
+        });
+        this.setData({
+          formArray: _formArr,
+          scene,
+          deviceType: type,
+          mode,
+          submitText: mode == 'add' ? '淇濆瓨' : '鏇存柊',
+        });
       }
-      wx.setNavigationBarTitle({
-        title: barTitle,
-      });
-      this.setData({ formArray: _formArr });
-    }
-    if (options.mode == 'add' || options.mode == 'update') {
-      this.setData({ mode: options.mode });
-    }
+    });
   },
 
   // 鎻愪氦琛ㄥ崟
   submit(e) {
-    const formArr = e.detail;
+    const formObj = e.detail;
+    const { mode } = this.data;
+    if (mode == 'add') {
+      this.addDevice(formObj);
+    } else {
+      this.updateDevice(formObj);
+    }
     console.log('submit');
-    console.log(formArr);
+    console.log(formObj);
   },
 
   // 鍙栨秷琛ㄥ崟
   cancel() {
-    console.log('cancel');
+    // console.log('cancel');
+    wx.navigateBack({
+      delta: 1,
+      success: res => {},
+      fail: res => {},
+      complete: res => {},
+    });
   },
 
   // 鏂板璁惧淇℃伅
   addDevice(formObj) {
     const { deviceType } = this.data;
-    formObj.diSceneGuid
-    formObj.diSceneTypeId
     uploadDevice(formObj, deviceType).then(res => {
-      console.log(res);
+      // console.log(res);
+      this.getOpenerEventChannel().emit('updateDeviceInfoOver');
+      wx.navigateBack({
+        delta: 1,
+        success: () => {
+          wx.showToast({
+            title: '璁惧鏂板鎴愬姛',
+            duration: 2000,
+            icon: 'success',
+            mask: true,
+          });
+        },
+      });
     });
   },
 
   // 鏇存柊璁惧淇℃伅
-  updateDevice() {},
+  updateDevice(formObj) {
+    const { deviceType } = this.data;
+    updateDevice(formObj, deviceType).then(res => {
+      // console.log(res);
+      this.getOpenerEventChannel().emit('updateDeviceInfoOver');
+      wx.navigateBack({
+        delta: 1,
+        success: () => {
+          wx.showToast({
+            title: '璁惧淇敼鎴愬姛',
+            duration: 2000,
+            icon: 'success',
+            mask: true,
+          });
+        },
+      });
+    });
+  },
 });

--
Gitblit v1.9.3