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
| /**
| * date:
| * author: neeler
| */
|
| //test data start
| // 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}})
| // 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}})
| // var data_doSave = Mock.mock('/basicconfig/gates/saveCEquipment.htm', {code: 0, })
| //test data end
|
| var TYPE = ['IC卡读卡器', 'RFID读卡器', '道闸', '车牌识别系统', '地感线圈', 'LED显示屏', '车牌识别摄像头', '一般摄像头', '滚闸']
| var STYPE = {'一般摄像头': [{index: 0, value: '海康摄像头'}, {index: 1, value: '大华摄像头'}]}
| var ASPECT = [{index: 1, value: '进'}, {index: 2, value: '出'}]
| var CB = [{index: 0, value: '不控制'}, {index: 1, value: '升闸机'}, {index: 2, value: '降闸机'}]
|
| var Obj = {
| id: 0,
| eqname: '',
| equipmentno: '',
| mclientNo: $('#mclientNo').val(),
| type: '',
| stype: '',
| ip: '',
| serviceIP: '',
| port: '',
| servicePort: '',
| aname: '',
| password: '',
| state: '',
| aspect: '',
| controlBarrier: '',
| }
|
| window.I = {
| idv: $('#id').val(),
| save: $('#save'),
| back: $('#back')
| }
|
| var ViewModel = function() {
| var self = this;
| self.o = ko.observable(ko.mapping.fromJS(Obj));
| self.tList = ko.observableArray(TYPE);
| self.asList = ko.observableArray(ASPECT);
| self.cbList = ko.observableArray(CB);
| self.stList = ko.observableArray();
|
| self.typeChange = function(item) {
| changeSType(item);
| }
| }
|
| $(function () {
| window.vm = new ViewModel();
| ko.applyBindings(vm);
| if (I.idv) {
| getItem(I.idv);
| }
| pageInit();
| });
|
| function pageInit() {
| I.back.click(function (e) {
| e.preventDefault();
| history.go(-1);
| });
| I.save.click(function (e) {
| e.preventDefault();
| if (valid()) {
| doSave();
| }
| });
| }
|
| function changeSType(item) {
| console.log(item);
| if (STYPE[item]) {
| vm.stList(STYPE[item]);
| } else {
| vm.stList([{index: null, value: '没有可选类型'}]);
| }
| }
|
| function getItem(id) {
| $.post("/basicconfig/gates/getCEquipment.htm", {id: id},
| function (data, textStatus, jqXHR) {
| if (data.code >= 1) {
| // parent.showErrmsg(data.errmsg);
| swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
| return;
| }
| if (data.code == 0) {
| vm.o(ko.mapping.fromJS(data.item));
| $('#type').trigger('change');
| return;
| }
| },
| "json"
| );
| }
|
| function doSave() {
| if (!I.AjaxSaveItem &&valid()) {
| I.AjaxSaveItem = true;
| var o = ko.mapping.toJS(vm.o());
| $.post('/basicconfig/gates/saveCEquipment.htm', o, function(data, textStatus, xhr) {
| I.AjaxSaveItem = false;
| if (data.code >= 1) {
| // parent.showErrmsg(data.errmsg);
| swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
| return;
| }
| if (data.code == 0) {
| // location.replace(location.href);
| parent.showErrmsg('保存成功!', function() {
| history.go(-1);
| });
| return;
| }
| }, 'json');
| }
| }
|
| function valid(){
| var isValid = false;
| var iF = $('#form');
| iF.validate({
| rules: {
| 'eqname': {
| required: true
| }
| },
| messages: {
| 'eqname': {
| required: '设备名称不能为空!'
| }
| },
| errorPlacement: function (err, element) {
| var p = element.parents('.col-md-9').eq(0);
| var d = p.children('.text-error').eq(0);
| d.css('color', '#D9534F');
| err.appendTo(d);
| }
| })
| isValid = iF.valid();
| return isValid;
| }
|
|