From 7c3c82d429f86358142adceb080e8922f6a18aa0 Mon Sep 17 00:00:00 2001
From: Riku <risaku@163.com>
Date: 星期一, 12 八月 2024 22:43:33 +0800
Subject: [PATCH] 设备信息管理模块

---
 pages/inspection/scene/info/device-info/index.js |   83 +++++++++++++++++++++++++----------------
 1 files changed, 50 insertions(+), 33 deletions(-)

diff --git a/pages/inspection/scene/info/device-info/index.js b/pages/inspection/scene/info/device-info/index.js
index b850077..1a18400 100644
--- a/pages/inspection/scene/info/device-info/index.js
+++ b/pages/inspection/scene/info/device-info/index.js
@@ -14,42 +14,56 @@
   },
 
   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 } = data;
+        let barTitle, _formArr;
+        switch (type) {
+          case 0:
+            barTitle = '鏂板鐩戞祴璁惧';
+            _formArr = monitorDeviceForm(scene.typeid);
+            break;
+          case 1:
+            barTitle = '鏂板娌荤悊璁惧';
+            _formArr = treatmentDeviceForm(scene.typeid);
+            break;
+          case 2:
+            barTitle = '鏂板鐢熶骇璁惧';
+            _formArr = productionDeviceForm(scene.typeid);
+            break;
+          default:
+            barTitle = '璁惧淇℃伅';
+            _formArr = monitorDeviceForm(scene.typeid);
+            break;
+        }
+        wx.setNavigationBarTitle({
+          title: barTitle,
+        });
+        this.setData({
+          formArray: _formArr,
+          scene,
+          deviceType: type,
+          mode,
+        });
       }
-      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, scene } = this.data;
+    formObj.diSceneGuid = scene.guid;
+    formObj.diSceneTypeId = scene.typeid;
+    formObj.diTypeId = formObj._type[0].value;
+    formObj.diSubtypeId = formObj._type[1].value;
+    if (mode == 'add') {
+      this.addDevice(formObj);
+    } else {
+      this.updateDevice(formObj);
+    }
     console.log('submit');
-    console.log(formArr);
+    console.log(formObj);
   },
 
   // 鍙栨秷琛ㄥ崟
@@ -60,13 +74,16 @@
   // 鏂板璁惧淇℃伅
   addDevice(formObj) {
     const { deviceType } = this.data;
-    formObj.diSceneGuid
-    formObj.diSceneTypeId
     uploadDevice(formObj, deviceType).then(res => {
       console.log(res);
     });
   },
 
   // 鏇存柊璁惧淇℃伅
-  updateDevice() {},
+  updateDevice() {
+    const { deviceType } = this.data;
+    updateDevice(formObj, deviceType).then(res => {
+      console.log(res);
+    });
+  },
 });

--
Gitblit v1.9.3