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
| /**
| * date:
| * author: neeler
| */
|
| //test data start
| // var data_getItem = Mock.mock('/basicconfig/weighthouse/getMClient.htm', {code: 0, item: {id: 3, mclientNo: '78975645', type: 'LED显示屏', ipadd: '192.168.1.111', keys: 'yiohqwejhfjashdfujhyasui', uri: '7897845456/sss', note: '暂无', relationno: '11111', relationname: '门禁2333'}})
| // var data_doSave = Mock.mock('/basicconfig/weighthouse/saveMClient.htm', {code: 0, })
| //test data end
|
| // var TYPE = ['门禁客户端' ,'磅房客户端' , '显示屏客户端']
| var TYPE = ['磅房客户端']
|
| var Obj = {
| id: 0,
| mclientNo: '',
| type: '',
| ipadd: '',
| keys: '',
| uri: '',
| note: '',
| relationno: $('#relationno').val(),
| relationname: $('#name').val(),
| }
|
| window.I = {
| relationno: $('#relationno').val(),
| name: $('#name').val(),
| save: $('#save')
| }
|
| var ViewModel = function() {
| var self = this;
| self.o = ko.observable(ko.mapping.fromJS(Obj));
| self.tList = ko.observableArray(TYPE);
| }
|
| $(function () {
| window.vm = new ViewModel();
| ko.applyBindings(vm);
| if (I.relationno) {
| getItem(I.relationno);
| }
| pageInit();
| });
|
| function pageInit() {
| I.save.click(function (e) {
| e.preventDefault();
| if (valid()) {
| doSave();
| }
| });
| }
|
| function getItem(relationno) {
| $.post("/basicconfig/weighthouse/getMClient.htm", {relationno: relationno},
| 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));
| return;
| }
| },
| "json"
| );
| }
|
| function doSave() {
| if (!I.AjaxSaveItem &&valid()) {
| I.AjaxSaveItem = true;
| var o = ko.mapping.toJS(vm.o());
| $.post('/basicconfig/weighthouse/saveMClient.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('保存成功!');
| return;
| }
| }, 'json');
| }
| }
|
| function valid(){
| var isValid = false;
| var iF = $('#form');
| iF.validate({
| rules: {
| 'ip': {
| required: true
| }
| },
| messages: {
| 'ip': {
| required: 'ip不能为空!'
| }
| },
| 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;
| }
|
|