Riku
2024-08-13 cf693a5227f17bbf2201512128d267281a8c5695
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { deviceStatusForm } from '../device-info-items.js';
import {
  fetchDeviceStatus,
  uploadDeviceStatus,
} from '../../../../../services/inspection/fetchDevice';
 
var defaultForm = deviceStatusForm();
 
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) {
    this.getOpenerEventChannel().on('acceptDeviceStatusData', data => {
      if (data) {
        const { scene, type, deviceInfo } = data;
        defaultForm = deviceStatusForm({
          dlDeviceId: deviceInfo.diId,
          dlDeviceType: type,
          dlSceneGuid: scene.guid,
          dlSceneTypeId: scene.typeid,
        });
        this.setData({
          scene,
          type,
          deviceInfo,
        });
 
        this.fetchDeviceStatus();
      }
    });
  },
 
  fetchDeviceStatus() {
    const { scene, type, deviceInfo } = this.data;
    fetchDeviceStatus(scene.guid, deviceInfo.diId, type).then(res => {
      this.setData({
        deviceStatusList: res.data,
      });
    });
  },
 
  // 显示新增设备状态输入表单
  onAddStatus() {
    this.setData({
      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,
    });
  },
});