From cf693a5227f17bbf2201512128d267281a8c5695 Mon Sep 17 00:00:00 2001
From: Riku <risaku@163.com>
Date: 星期二, 13 八月 2024 23:49:20 +0800
Subject: [PATCH] 设备信息模块

---
 pages/inspection/scene/info/device-status/index.js |  112 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 98 insertions(+), 14 deletions(-)

diff --git a/pages/inspection/scene/info/device-status/index.js b/pages/inspection/scene/info/device-status/index.js
index dd0ceb9..b5d9304 100644
--- a/pages/inspection/scene/info/device-status/index.js
+++ b/pages/inspection/scene/info/device-status/index.js
@@ -8,9 +8,31 @@
 
 Page({
   data: {
+    // 璁惧鐘舵�佽〃鍗曞唴瀹�
     formArray: [],
     showNewStatus: false,
     deviceStatusList: [],
+
+    // 鍥剧墖涓婁紶鍒楄〃
+    fileList: [],
+    // 鍥剧墖灞曠ず鏂瑰紡
+    gridConfig: {
+      column: 3,
+      width: 210,
+      height: 210,
+    },
+    // 鍥剧墖闄愬埗澶у皬
+    sizeLimit: { size: 5, unit: 'MB', message: '鍥剧墖澶у皬涓嶈秴杩�5MB' },
+
+    // 瀹氫綅淇℃伅
+    locations: {
+      // 浣嶇疆鍚嶇О
+      name: '',
+      address: '',
+      // 浣跨敤 gcj02 鍥芥祴灞�鍧愭爣绯�
+      longitude: '',
+      latitude: '',
+    },
   },
 
   onLoad(options) {
@@ -23,33 +45,95 @@
           dlSceneGuid: scene.guid,
           dlSceneTypeId: scene.typeid,
         });
-        // console.log(scene);
-        // console.log(type);
-        // console.log(deviceInfo);
+        this.setData({
+          scene,
+          type,
+          deviceInfo,
+        });
+
+        this.fetchDeviceStatus();
       }
     });
   },
 
-  onAddStatus() {
-    this.setData({
-      showNewStatus: true,
-      formArray: defaultForm
+  fetchDeviceStatus() {
+    const { scene, type, deviceInfo } = this.data;
+    fetchDeviceStatus(scene.guid, deviceInfo.diId, type).then(res => {
+      this.setData({
+        deviceStatusList: res.data,
+      });
     });
   },
 
-  saveNewStatus(e) {
-    const { deviceStatusList } = this.data;
-    const formObj = e.detail;
-    deviceStatusList.push(formObj);
-    uploadDeviceStatus(formObj);
+  // 鏄剧ず鏂板璁惧鐘舵�佽緭鍏ヨ〃鍗�
+  onAddStatus() {
     this.setData({
-      showNewStatus: false,
-      deviceStatusList,
+      showNewStatus: true,
+      formArray: defaultForm,
+      fileList: [],
+      locations: {},
     });
   },
+
+  // 淇濆瓨鏂拌澶囩姸鎬�
+  saveNewStatus(e) {
+    const { deviceStatusList, fileList, locations } = this.data;
+    const formObj = e.detail;
+
+    formObj.dlLocation = locations.address;
+    formObj.dlLongitude = locations.longitude;
+    formObj.dlLatitude = locations.latitude;
+    const images = fileList.map(v => v.url);
+    uploadDeviceStatus(formObj, images).then(res => {
+      // if (res.success) {
+      //   deviceStatusList.push(formObj);
+      //   this.setData({
+      //     showNewStatus: false,
+      //     deviceStatusList,
+      //   });
+      // }
+      this.setData({
+        showNewStatus: false,
+      });
+      this.fetchDeviceStatus();
+    });
+  },
+  // 鍙栨秷璁惧鐘舵�佽〃鍗曠紪杈�
   cancelNewStatus() {
     this.setData({
       showNewStatus: false,
     });
   },
+
+  // 鎵嬪姩淇敼瀹氫綅浣嶇疆鎻忚堪
+  handleLocation(e) {},
+
+  // 浠庡湴鍥鹃�夋嫨瀹氫綅
+  chooseLocation() {
+    wx.chooseLocation({
+      success: res => {
+        console.log(res);
+        this.setData({ locations: res });
+      },
+    });
+  },
+
+  // 娣诲姞鍥剧墖
+  handleAddImg(e) {
+    const { fileList } = this.data;
+    const { files } = e.detail;
+    this.setData({
+      fileList: [...fileList, ...files],
+    });
+  },
+  // 绉婚櫎鍥剧墖
+  handleRemoveImg(e) {
+    const { index } = e.detail;
+    const { fileList } = this.data;
+
+    fileList.splice(index, 1);
+    this.setData({
+      fileList,
+    });
+  },
 });

--
Gitblit v1.9.3