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
| 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) {
| 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,
| });
| }
| });
| },
|
| // 提交表单
| submit(e) {
| 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(formObj);
| },
|
| // 取消表单
| cancel() {
| console.log('cancel');
| },
|
| // 新增设备信息
| addDevice(formObj) {
| const { deviceType } = this.data;
| uploadDevice(formObj, deviceType).then(res => {
| console.log(res);
| });
| },
|
| // 更新设备信息
| updateDevice() {
| const { deviceType } = this.data;
| updateDevice(formObj, deviceType).then(res => {
| console.log(res);
| });
| },
| });
|
|