threshold.js
11.3 KB
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
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'reservoir/threshold/index' + location.search,
add_url: 'reservoir/threshold/add',
edit_url: 'reservoir/threshold/edit',
del_url: 'reservoir/threshold/del',
multi_url: 'reservoir/threshold/multi',
import_url: 'reservoir/threshold/import',
table: 'reservoir_threshold',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
// {field: 'reservoirequipment.type', title: __('Reservoirequipment.type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4'),"5":__('Type 5'),"6":__('Type 6'),"7":__('Type 7')},custom: {"1":'none', "2":'none',"3":'none', "4":'none', "5":'none', "6":'none', "7":'none'}, formatter: Table.api.formatter.status},
// {field: 'reservoirequipment.name', title: __('Reservoirequipment.name'), operate: 'LIKE'},
{field: 'type_text', title: __('设备类型'), operate: false},
{field: 'device_name', title: __('设备名称'), operate: false},
{field: 'deviceId', title: __('Deviceid'), operate: 'LIKE'},
{field: 'config', title: __('Config')},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'reservoirlist.name', title: '水库名称', operate: 'LIKE'},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
$('input[name="row[types]"]').on('change',function () {
let types = parseInt($(this).val());
let deviceId = $('#deviceId');
let deviceCode2 = $('#device_code2');
let deviceCode3 = $('#device_code3');
let deviceCode4 = $('#device_code4');
let deviceCode5 = $('#device_code5');
let deviceCode6 = $('#device_code6');
let deviceCode7 = $('#device_code7');
let config2 = $('#config2');
let config = $('#config');
if (types === 1){
deviceId.show();
deviceCode2.hide();
deviceCode3.hide();
deviceCode4.hide();
deviceCode5.hide();
deviceCode6.hide();
deviceCode7.hide();
config2.hide();
if (config){
config.show();
}
}else if(types === 2){
deviceId.hide();
deviceCode2.show();
deviceCode3.hide();
deviceCode4.hide();
deviceCode5.hide();
deviceCode6.hide();
deviceCode7.hide();
let code2Val = $('#c-device_code2').val();
if (code2Val){
config2.show();
}else{
config2.hide();
}
if (config){
config.hide();
}
}else if(types === 3){
deviceId.hide();
deviceCode2.hide();
deviceCode3.show();
deviceCode4.hide();
deviceCode5.hide();
deviceCode6.hide();
deviceCode7.hide();
let code3Val = $('#c-device_code3').val();
if (code3Val){
config2.show();
}else{
config2.hide();
}
if (config){
config.hide();
}
}else if(types === 4){
deviceId.hide();
deviceCode2.hide();
deviceCode3.hide();
deviceCode4.show();
deviceCode5.hide();
deviceCode6.hide();
deviceCode7.hide();
let code4Val = $('#c-device_code4').val();
if (code4Val){
config2.show();
}else{
config2.hide();
}
if (config){
config.hide();
}
}else if(types === 5){
deviceId.hide();
deviceCode2.hide();
deviceCode3.hide();
deviceCode4.hide();
deviceCode5.show();
deviceCode6.hide();
deviceCode7.hide();
let code5Val = $('#c-device_code5').val();
if (code5Val){
config2.show();
}else{
config2.hide();
}
if (config){
config.hide();
}
}else if(types === 6){
deviceId.hide();
deviceCode2.hide();
deviceCode3.hide();
deviceCode4.hide();
deviceCode5.hide();
deviceCode6.show();
deviceCode7.hide();
let code6Val = $('#c-device_code6').val();
if (code6Val){
config2.show();
}else{
config2.hide();
}
if (config){
config.hide();
}
}else if(types === 7){
deviceId.hide();
deviceCode2.hide();
deviceCode3.hide();
deviceCode4.hide();
deviceCode5.hide();
deviceCode6.hide();
deviceCode7.show();
let code7Val = $('#c-device_code7').val();
if (code7Val){
config2.show();
}else{
config2.hide();
}
if (config){
config.hide();
}
}
});
$('#c-device_code2').on('change',function () {
let code2Val = $('#c-device_code2').val();
let config2 = $('#config2');
if (code2Val){
config2.show();
}else{
config2.hide();
}
});
$('#c-device_code3').on('change',function () {
let code3Val = $('#c-device_code3').val();
let config2 = $('#config2');
if (code3Val){
config2.show();
}else{
config2.hide();
}
});
$('#c-device_code4').on('change',function () {
let code4Val = $('#c-device_code4').val();
let config2 = $('#config2');
if (code4Val){
config2.show();
}else{
config2.hide();
}
});
$('#c-device_code5').on('change',function () {
let code5Val = $('#c-device_code5').val();
let config2 = $('#config2');
if (code5Val){
config2.show();
}else{
config2.hide();
}
});
$('#c-device_code6').on('change',function () {
let code6Val = $('#c-device_code6').val();
let config2 = $('#config2');
if (code6Val){
config2.show();
}else{
config2.hide();
}
});
$('#c-device_code7').on('change',function () {
let code7Val = $('#c-device_code7').val();
let config2 = $('#config2');
if (code7Val){
config2.show();
}else{
config2.hide();
}
});
$("#c-deviceId").on("change", function(){
var id = $("#c-deviceId").val();
if (!id){
$('#config').remove();
$('#c-reservoir_id').val('');
return;
}
$.ajax({
url:"reservoir/equipment/getType",
data:{id:id},
dataType:'json',
type:'post',
success:function(res){
$('#config').remove();
$('#c-reservoir_id').val(res.reservoir_id);
if(res.type != '6'){
var str = '<div class="form-group" id="config"><label class="control-label col-xs-12 col-sm-2">预警阈值区间[单位:mm](示例:10,20):</label><div class="col-xs-12 col-sm-8"><input id="c-config-value" class="form-control" name="row[config][value]" type="text" value=""></div></div>';
$('#deviceId').after(str);
}
else{
var str = '<div id="config"><div class="form-group"><label class="control-label col-xs-12 col-sm-2">X预警阈值区间[单位:mm]((示例:10,20):</label><div class="col-xs-12 col-sm-8"><input id="c-config-x"class="form-control"name="row[config][x]"type="text"value=""></div></div><div class="form-group"><label class="control-label col-xs-12 col-sm-2">Y预警阈值区间[单位:mm]((示例:10,20):</label><div class="col-xs-12 col-sm-8"><input id="c-config-y"class="form-control"name="row[config][y]"type="text"value=""></div></div><div class="form-group"><label class="control-label col-xs-12 col-sm-2">Z预警阈值区间[单位:mm]((示例:10,20):</label><div class="col-xs-12 col-sm-8"><input id="c-config-z"class="form-control"name="row[config][z]"type="text"value=""></div></div></div>';
$('#deviceId').after(str);
}
}
})
});
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});