riku
2024-08-12 65124213af664a68ad88ce7f6dcb133116d7702f
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
import {
  monitorDeviceForm,
  treatmentDeviceForm,
  productionDeviceForm,
} from '../device-info-items.js';
import { uploadDevice, updateDevice } from '../../../../../services/inspection/fetchDevice';
 
Page({
  data: {
    // 设备类型id(0:监控设备;1:治理设备;2:生产设备;)
    deviceType: 0,
    // 模式,add: 新增设备;update:更新设备
    mode: 'add',
  },
 
  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;
      }
      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;
    console.log('submit');
    console.log(formArr);
  },
 
  // 取消表单
  cancel() {
    console.log('cancel');
  },
 
  // 新增设备信息
  addDevice(formObj) {
    const { deviceType } = this.data;
    formObj.diSceneGuid
    formObj.diSceneTypeId
    uploadDevice(formObj, deviceType).then(res => {
      console.log(res);
    });
  },
 
  // 更新设备信息
  updateDevice() {},
});