提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
* date: |
|
3 |
* author: neeler |
|
4 |
*/ |
|
5 |
|
|
6 |
//test data start |
|
7 |
// 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'}}) |
|
8 |
// var data_doSave = Mock.mock('/basicconfig/weighthouse/saveMClient.htm', {code: 0, }) |
|
9 |
//test data end |
|
10 |
|
|
11 |
// var TYPE = ['门禁客户端' ,'磅房客户端' , '显示屏客户端'] |
|
12 |
var TYPE = ['磅房客户端'] |
|
13 |
|
|
14 |
var Obj = { |
|
15 |
id: 0, |
|
16 |
mclientNo: '', |
|
17 |
type: '', |
|
18 |
ipadd: '', |
|
19 |
keys: '', |
|
20 |
uri: '', |
|
21 |
note: '', |
|
22 |
relationno: $('#relationno').val(), |
|
23 |
relationname: $('#name').val(), |
|
24 |
} |
|
25 |
|
|
26 |
window.I = { |
|
27 |
relationno: $('#relationno').val(), |
|
28 |
name: $('#name').val(), |
|
29 |
save: $('#save') |
|
30 |
} |
|
31 |
|
|
32 |
var ViewModel = function() { |
|
33 |
var self = this; |
|
34 |
self.o = ko.observable(ko.mapping.fromJS(Obj)); |
|
35 |
self.tList = ko.observableArray(TYPE); |
|
36 |
} |
|
37 |
|
|
38 |
$(function () { |
|
39 |
window.vm = new ViewModel(); |
|
40 |
ko.applyBindings(vm); |
|
41 |
if (I.relationno) { |
|
42 |
getItem(I.relationno); |
|
43 |
} |
|
44 |
pageInit(); |
|
45 |
}); |
|
46 |
|
|
47 |
function pageInit() { |
|
48 |
I.save.click(function (e) { |
|
49 |
e.preventDefault(); |
|
50 |
if (valid()) { |
|
51 |
doSave(); |
|
52 |
} |
|
53 |
}); |
|
54 |
} |
|
55 |
|
|
56 |
function getItem(relationno) { |
|
57 |
$.post("/basicconfig/weighthouse/getMClient.htm", {relationno: relationno}, |
|
58 |
function (data, textStatus, jqXHR) { |
|
59 |
if (data.code >= 1) { |
|
60 |
//parent.showErrmsg(data.errmsg); |
|
61 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
62 |
return; |
|
63 |
} |
|
64 |
if (data.code == 0) { |
|
65 |
vm.o(ko.mapping.fromJS(data.item)); |
|
66 |
return; |
|
67 |
} |
|
68 |
}, |
|
69 |
"json" |
|
70 |
); |
|
71 |
} |
|
72 |
|
|
73 |
function doSave() { |
|
74 |
if (!I.AjaxSaveItem &&valid()) { |
|
75 |
I.AjaxSaveItem = true; |
|
76 |
var o = ko.mapping.toJS(vm.o()); |
|
77 |
$.post('/basicconfig/weighthouse/saveMClient.htm', o, function(data, textStatus, xhr) { |
|
78 |
I.AjaxSaveItem = false; |
|
79 |
if (data.code >= 1) { |
|
80 |
//parent.showErrmsg(data.errmsg); |
|
81 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
82 |
return; |
|
83 |
} |
|
84 |
if (data.code == 0) { |
|
85 |
// location.replace(location.href); |
|
86 |
parent.showErrmsg('保存成功!'); |
|
87 |
return; |
|
88 |
} |
|
89 |
}, 'json'); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
function valid(){ |
|
94 |
var isValid = false; |
|
95 |
var iF = $('#form'); |
|
96 |
iF.validate({ |
|
97 |
rules: { |
|
98 |
'ip': { |
|
99 |
required: true |
|
100 |
} |
|
101 |
}, |
|
102 |
messages: { |
|
103 |
'ip': { |
|
104 |
required: 'ip不能为空!' |
|
105 |
} |
|
106 |
}, |
|
107 |
errorPlacement: function (err, element) { |
|
108 |
var p = element.parents('.col-md-9').eq(0); |
|
109 |
var d = p.children('.text-error').eq(0); |
|
110 |
d.css('color', '#D9534F'); |
|
111 |
err.appendTo(d); |
|
112 |
} |
|
113 |
}) |
|
114 |
isValid = iF.valid(); |
|
115 |
return isValid; |
|
116 |
} |