mrzcc
2020-03-06 ecdac8a738f254db2b2ea28cbe3248f7a6a7eb2b
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
(function (vc, vm) {
 
    vc.extends({
        data: {
            editMachineInfo: {
                machineId: '',
                machineCode: '',
                machineVersion: '',
                machineName: '',
                machineTypeCd: '',
                authCode: '',
                machineIp: '',
                machineMac: '',
                floorId: '',
                floorNum: '',
                floorName: '',
                unitId: '',
                unitNum: '',
                roomId: '',
                locationTypeCd: '',
                locationObjId: '',
                roomNum: '',
                machineUrl: '',
                direction:''
 
            }
        },
        _initMethod: function () {
 
        },
        _initEvent: function () {
            vc.on('editMachine', 'openEditMachineModal', function (_params) {
                vc.component.refreshEditMachineInfo();
                $('#editMachineModel').modal('show');
                vc.copyObject(_params, vc.component.editMachineInfo);
                vc.component._initMachineUrl();
                //根据位置类型 传输数据
                if (vc.component.editMachineInfo.locationTypeCd == '2000') {
                    vc.emit('editMachine', 'floorSelect2', 'setFloor', {
                        floorId: vc.component.editMachineInfo.floorId,
                        floorNum: vc.component.editMachineInfo.floorNum
                    });
                    vc.emit('editMachine', 'unitSelect2', 'setUnit', {
                        floorId: vc.component.editMachineInfo.floorId,
                        floorNum: vc.component.editMachineInfo.floorNum,
                        unitId: vc.component.editMachineInfo.unitId,
                        unitNum: vc.component.editMachineInfo.unitNum,
                    });
                } else if (vc.component.editMachineInfo.locationTypeCd == '3000') {
                    vc.emit('editMachine', 'floorSelect2', 'setFloor', {
                        floorId: vc.component.editMachineInfo.floorId,
                        floorNum: vc.component.editMachineInfo.floorNum
                    });
                    vc.emit('editMachine', 'unitSelect2', 'setUnit', {
                        floorId: vc.component.editMachineInfo.floorId,
                        floorNum: vc.component.editMachineInfo.floorNum,
                        unitId: vc.component.editMachineInfo.unitId,
                        unitNum: vc.component.editMachineInfo.unitNum,
                    });
                    vc.emit('editMachine', 'roomSelect2', 'setRoom', {
                        floorId: vc.component.editMachineInfo.floorId,
                        floorNum: vc.component.editMachineInfo.floorNum,
                        unitId: vc.component.editMachineInfo.unitId,
                        unitNum: vc.component.editMachineInfo.unitNum,
                        roomId: vc.component.editMachineInfo.roomId,
                        roomNum: vc.component.editMachineInfo.roomNum,
                    });
                }
                vc.component.editMachineInfo.communityId = vc.getCurrentCommunity().communityId;
            });
 
            vc.on("editMachine", "notify", function (_param) {
                if (_param.hasOwnProperty("floorId")) {
                    vc.component.editMachineInfo.floorId = _param.floorId;
                }
 
                if (_param.hasOwnProperty("unitId")) {
                    vc.component.editMachineInfo.unitId = _param.unitId;
                }
 
                if (_param.hasOwnProperty("roomId")) {
                    vc.component.editMachineInfo.roomId = _param.roomId;
                }
            });
        },
        methods: {
            _initMachineUrl: function () {
                var sysInfo = vc.getData("_sysInfo");
                if (sysInfo == null) {
                    return;
                }
 
                var apiUrl = sysInfo.apiUrl + "/api/machineTranslate.machineHeartbeart?communityId="
                    + vc.getCurrentCommunity().communityId + "&transaction_id=-1&req_time=20181113225612&user_id=-1"
                    + "&app_id=" + vc.component.editMachineInfo.machineTypeCd;
                vc.component.editMachineInfo.machineUrl = apiUrl;
 
 
            },
            editMachineValidate: function () {
                return vc.validate.validate({
                    editMachineInfo: vc.component.editMachineInfo
                }, {
                    'editMachineInfo.machineCode': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "设备编码不能为空"
                        },
                        {
                            limit: "maxin",
                            param: "1,30",
                            errInfo: "设备编码不能超过30位"
                        },
                    ],
                    'editMachineInfo.machineVersion': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "版本号不能为空"
                        }],
                    'editMachineInfo.machineName':
                        [
                            {
                                limit: "required",
                                param: "",
                                errInfo: "设备名称不能为空"
                            }],
                    'editMachineInfo.machineTypeCd':
                        [
                            {
                                limit: "required",
                                param: "",
                                errInfo: "设备类型不能为空"
                            },
                            {
                                limit: "num",
                                param: "",
                                errInfo: "设备类型格式错误"
                            },
                        ],
                    'editMachineInfo.direction':
                    [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "设备方向不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "设备方向格式错误"
                        },
                    ],
                    'editMachineInfo.authCode':
                        [
                            {
                                limit: "required",
                                param: "",
                                errInfo: "鉴权编码不能为空"
                            },
                            {
                                limit: "maxLength",
                                param: "64",
                                errInfo: "鉴权编码不能大于64位"
                            },
                        ],
                    'editMachineInfo.machineIp':
                        [
                            {
                                limit: "maxLength",
                                param: "64",
                                errInfo: "设备IP格式错误"
                            },
                        ],
                    'editMachineInfo.machineMac':
                        [
                            {
                                limit: "maxLength",
                                param: "64",
                                errInfo: "设备MAC 格式错误"
                            },
                        ],
                    'editMachineInfo.machineId':
                        [
                            {
                                limit: "required",
                                param: "",
                                errInfo: "设备ID不能为空"
                            }],
                    'editMachineInfo.locationTypeCd':
                        [
                            {
                                limit: "required",
                                param: "",
                                errInfo: "请选择设备位置"
                            }
                        ],
                    'editMachineInfo.locationObjId':
                        [
                            {
                                limit: "required",
                                param: "",
                                errInfo: "请选择位置"
                            }
                        ]
 
                })
                    ;
            },
            editMachine: function () {
                vc.component.editMachineInfo.communityId = vc.getCurrentCommunity().communityId;
                if (vc.component.editMachineInfo.locationTypeCd != '2000' && vc.component.editMachineInfo.locationTypeCd != '3000') { //大门时直接写 小区ID
                    vc.component.editMachineInfo.locationObjId = vc.component.editMachineInfo.communityId;
                } else if (vc.component.editMachineInfo.locationTypeCd == '2000') {
                    vc.component.editMachineInfo.locationObjId = vc.component.editMachineInfo.unitId;
                } else if (vc.component.editMachineInfo.locationTypeCd == '3000') {
                    vc.component.editMachineInfo.locationObjId = vc.component.editMachineInfo.roomId;
                } else {
                    vc.toast("设备位置值错误");
                    return;
                }
                if (!vc.component.editMachineValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
 
                vc.http.post(
                    'editMachine',
                    'update',
                    JSON.stringify(vc.component.editMachineInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        if (res.status == 200) {
                            //关闭model
                            $('#editMachineModel').modal('hide');
                            vc.emit('machineManage', 'listMachine', {});
                            return;
                        }
                        vc.message(json);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
 
                        vc.message(errInfo);
                    });
            },
            refreshEditMachineInfo: function () {
                vc.component.editMachineInfo = {
                    machineId: '',
                    machineCode: '',
                    machineVersion: '',
                    machineName: '',
                    machineTypeCd: '',
                    authCode: '',
                    machineIp: '',
                    machineMac: '',
                    floorId: '',
                    floorNum: '',
                    floorName: '',
                    unitId: '',
                    unitNum: '',
                    roomId: '',
                    locationTypeCd: '',
                    locationObjId: '',
                    roomNum: '',
                    machineUrl: '',
                     direction:''
 
                }
            }
        }
    });
 
})(window.vc, window.vc.component);