提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
* date: |
|
3 |
* author: neeler |
|
4 |
*/ |
|
5 |
|
|
6 |
//test data start |
|
7 |
// var data_getItem = Mock.mock('/basicconfig/gates/getCEquipment.htm', {code: 0, item: {id: 3, eqname: 'eeeqnnn', equipmentno: 'qwerq21321312', mclientNo: 'mc111', type: '地感线圈', ip: '1.1.1.2', serviceIP: '2.5.6.3', port: '5542', servicePort: '8797', aname: 'zhangsan', password: '', state: false, aspect: 2, controlBarrier: 1}}) |
|
8 |
// var data_getItem = Mock.mock('/basicconfig/gates/getCEquipment.htm', {"code":0,"hint":null,"errmsg":null,"item":{"id":2,"eqname":"ICReader2","equipmentno":"1112","mclientNo":"111","type":"一般摄像头","stype":"0","ip":"192.168.200.218","serviceIP":"192.168.200.9","port":"39169","servicePort":"39169","aname":"sss","password":"aa","state":true,"controlBarrier":0,"aspect":1,"pid":0,"lft":3,"rgt":4,"level":1,"ordering":0}}) |
|
9 |
// var data_doSave = Mock.mock('/basicconfig/gates/saveCEquipment.htm', {code: 0, }) |
|
10 |
//test data end |
|
11 |
|
|
12 |
var TYPE = ['IC卡读卡器', 'RFID读卡器', '道闸', '车牌识别系统', '地感线圈', 'LED显示屏', '车牌识别摄像头', '一般摄像头', '滚闸'] |
|
13 |
var STYPE = {'一般摄像头': [{index: 0, value: '海康摄像头'}, {index: 1, value: '大华摄像头'}]} |
|
14 |
var ASPECT = [{index: 1, value: '进'}, {index: 2, value: '出'}] |
|
15 |
var CB = [{index: 0, value: '不控制'}, {index: 1, value: '升闸机'}, {index: 2, value: '降闸机'}] |
|
16 |
|
|
17 |
var Obj = { |
|
18 |
id: 0, |
|
19 |
eqname: '', |
|
20 |
equipmentno: '', |
|
21 |
mclientNo: $('#mclientNo').val(), |
|
22 |
type: '', |
|
23 |
stype: '', |
|
24 |
ip: '', |
|
25 |
serviceIP: '', |
|
26 |
port: '', |
|
27 |
servicePort: '', |
|
28 |
aname: '', |
|
29 |
password: '', |
|
30 |
state: '', |
|
31 |
aspect: '', |
|
32 |
controlBarrier: '', |
|
33 |
} |
|
34 |
|
|
35 |
window.I = { |
|
36 |
idv: $('#id').val(), |
|
37 |
save: $('#save'), |
|
38 |
back: $('#back') |
|
39 |
} |
|
40 |
|
|
41 |
var ViewModel = function() { |
|
42 |
var self = this; |
|
43 |
self.o = ko.observable(ko.mapping.fromJS(Obj)); |
|
44 |
self.tList = ko.observableArray(TYPE); |
|
45 |
self.asList = ko.observableArray(ASPECT); |
|
46 |
self.cbList = ko.observableArray(CB); |
|
47 |
self.stList = ko.observableArray(); |
|
48 |
|
|
49 |
self.typeChange = function(item) { |
|
50 |
changeSType(item); |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
$(function () { |
|
55 |
window.vm = new ViewModel(); |
|
56 |
ko.applyBindings(vm); |
|
57 |
if (I.idv) { |
|
58 |
getItem(I.idv); |
|
59 |
} |
|
60 |
pageInit(); |
|
61 |
}); |
|
62 |
|
|
63 |
function pageInit() { |
|
64 |
I.back.click(function (e) { |
|
65 |
e.preventDefault(); |
|
66 |
history.go(-1); |
|
67 |
}); |
|
68 |
I.save.click(function (e) { |
|
69 |
e.preventDefault(); |
|
70 |
if (valid()) { |
|
71 |
doSave(); |
|
72 |
} |
|
73 |
}); |
|
74 |
} |
|
75 |
|
|
76 |
function changeSType(item) { |
|
77 |
console.log(item); |
|
78 |
if (STYPE[item]) { |
|
79 |
vm.stList(STYPE[item]); |
|
80 |
} else { |
|
81 |
vm.stList([{index: null, value: '没有可选类型'}]); |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
function getItem(id) { |
|
86 |
$.post("/basicconfig/gates/getCEquipment.htm", {id: id}, |
|
87 |
function (data, textStatus, jqXHR) { |
|
88 |
if (data.code >= 1) { |
|
89 |
// parent.showErrmsg(data.errmsg); |
|
90 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
91 |
return; |
|
92 |
} |
|
93 |
if (data.code == 0) { |
|
94 |
vm.o(ko.mapping.fromJS(data.item)); |
|
95 |
$('#type').trigger('change'); |
|
96 |
return; |
|
97 |
} |
|
98 |
}, |
|
99 |
"json" |
|
100 |
); |
|
101 |
} |
|
102 |
|
|
103 |
function doSave() { |
|
104 |
if (!I.AjaxSaveItem &&valid()) { |
|
105 |
I.AjaxSaveItem = true; |
|
106 |
var o = ko.mapping.toJS(vm.o()); |
|
107 |
$.post('/basicconfig/gates/saveCEquipment.htm', o, function(data, textStatus, xhr) { |
|
108 |
I.AjaxSaveItem = false; |
|
109 |
if (data.code >= 1) { |
|
110 |
// parent.showErrmsg(data.errmsg); |
|
111 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
112 |
return; |
|
113 |
} |
|
114 |
if (data.code == 0) { |
|
115 |
// location.replace(location.href); |
|
116 |
parent.showErrmsg('保存成功!', function() { |
|
117 |
history.go(-1); |
|
118 |
}); |
|
119 |
return; |
|
120 |
} |
|
121 |
}, 'json'); |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
function valid(){ |
|
126 |
var isValid = false; |
|
127 |
var iF = $('#form'); |
|
128 |
iF.validate({ |
|
129 |
rules: { |
|
130 |
'eqname': { |
|
131 |
required: true |
|
132 |
} |
|
133 |
}, |
|
134 |
messages: { |
|
135 |
'eqname': { |
|
136 |
required: '设备名称不能为空!' |
|
137 |
} |
|
138 |
}, |
|
139 |
errorPlacement: function (err, element) { |
|
140 |
var p = element.parents('.col-md-9').eq(0); |
|
141 |
var d = p.children('.text-error').eq(0); |
|
142 |
d.css('color', '#D9534F'); |
|
143 |
err.appendTo(d); |
|
144 |
} |
|
145 |
}) |
|
146 |
isValid = iF.valid(); |
|
147 |
return isValid; |
|
148 |
} |