kl-details-info.js
3.62 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
/**
* @description TODO(客流配置编辑片段JS模块)
*
* @author bsth@lq
*
* @date 二〇一六年十月十八日 13:31:58
*
*/
$(function(){
// 获取编辑ID
var id = $.url().param('no');
/** 填充站点下拉框选择值 */
function setLinell() {
// 获取线路和方向选择值
var dir = $('#dir').val();
var lineid = $('#line').val();
if (dir == '' || lineid == '')
return;
$get('/stationroute/all', {lineCode_eq: lineid, directions_eq: dir, destroy_eq: '0'}, function (array) {
var options = '';
/** 遍历array */
$.each(array, function (i, d) {
var selected = (d.stationCode == currentStationCode) ? 'selected' : '';
options += '<option value="' + d.stationCode + '" ' + selected + '>' + d.stationName + '</option>';
});
$('#station').html(options);
});
}
/** 加载数据 */
function loadData() {
if (!id) {
showError('未找到编辑记录');
return;
}
$get('/station_kl/' + id, null,function(data) {
if (data) {
// 填充表单数据
$('#id').val(data.id);
$('#device').val(data.device);
$('#url').val(data.url);
// 保存当前站点代码用于下拉框选中
currentStationCode = data.stationCode;
// 加载线路数据
loadLines(data);
}
});
}
/** 加载线路数据 */
function loadLines(data) {
$get('/line/all', {destroy_eq: '0'}, function(array){
var options = '<option value="">-- 请选择线路 --</option>';
$.each(array, function(i,d){
var selected = (d.lineCode == data.lineCode) ? 'selected' : '';
options += '<option value="'+d.lineCode+'" '+selected+'>'+d.name+'</option>';
});
$('#line').html(options).on('change', setLinell);
// 设置方向并触发站点加载
if (data.lineCode && data.dir !== undefined) {
$('#dir').val(data.dir);
setLinell();
}
});
}
// 初始化方向下拉框事件
$('#dir').on('change', setLinell);
// 定义表单
var form = $('#kl_edit_form');
var error = $('.alert-danger', form);
var currentStationCode = null;
// 表单验证
form.validate({
errorElement: 'span',
errorClass: 'help-block help-block-error',
focusInvalid: true,
rules: {
'device': {required: true, maxlength: 30},
'line': {required: true, maxlength: 30},
'station': {required: true, maxlength: 30},
'url': {required: true}
},
messages: {
'device': {required: '请输入设备号'},
'line': {required: '请选择线路'},
'station': {required: '请选择站点'},
'url': {required: '请输入URL地址'}
},
invalidHandler: function(event, validator) {
error.show();
App.scrollTo(error, -200);
},
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
success: function(label) {
label.closest('.form-group').removeClass('has-error');
},
submitHandler: function(f) {
error.hide();
// 表单序列化
var params = form.serializeJSON();
params.stationName = $('#station option:selected').text();
params.lineName = $('#line option:selected').text();
// 更新数据
function update() {
$("#submitBtn").addClass("disabled");
$put('/station_kl' + id, params, function(result) {
if (result.success) {
// 返回list.html页面
loadPage('list.html');
} else {
$("#submitBtn").removeClass("disabled");
showError(result.message || '更新失败');
}
});
}
update();
}
});
// 加载数据
loadData();
/** 显示错误信息 */
function showError(message) {
error.text(message).show();
App.scrollTo(error, -200);
}
});