提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
* date: |
|
3 |
* author: neeler |
|
4 |
*/ |
|
5 |
|
|
6 |
//test data start |
|
7 |
// var data_doDel = Mock.mock('/enterprise/position/delItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'}) |
|
8 |
// var data_doSave = Mock.mock('/enterprise/position/saveItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'}) |
|
9 |
// var data_doBind = Mock.mock('/basicconfig/mapcompany/bind.htm', {code: 0, }) |
|
10 |
// var data_doUnbind = Mock.mock('/basicconfig/mapcompany/unbind.htm', {code: 0, }) |
|
11 |
//test data end |
|
12 |
|
|
13 |
var TYPE = [{key: '全部', value: 0}, {key: '已映射', value: 1}, {key: '未映射', value: 2}] |
|
14 |
|
|
15 |
var Obj = { |
|
16 |
// sysDepartNo: '', |
|
17 |
sysCompanyNo: '', |
|
18 |
sysname: '', |
|
19 |
companyNo: '', |
|
20 |
cname: '' |
|
21 |
} |
|
22 |
|
|
23 |
window.I = { |
|
24 |
PZ: 30, |
|
25 |
keyword: $('#keyword'), |
|
26 |
searchBtn: $('#searchBtn'), |
|
27 |
newObj: $('#newObj') |
|
28 |
} |
|
29 |
|
|
30 |
var ViewModel = function() { |
|
31 |
var self = this; |
|
32 |
self.tList = ko.observableArray(TYPE); |
|
33 |
self.skeyword = ko.observable(); |
|
34 |
self.ckeyword = ko.observable(); |
|
35 |
self.type = ko.observable(); |
|
36 |
self.list = ko.observableArray(); |
|
37 |
|
|
38 |
self.del = function(item) { |
|
39 |
doDel(item); |
|
40 |
} |
|
41 |
self.unbind = function(item) { |
|
42 |
doUnbind(item); |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
$(function () { |
|
47 |
window.vm = new ViewModel(); |
|
48 |
ko.applyBindings(vm); |
|
49 |
doSearch(); |
|
50 |
pageInit(); |
|
51 |
}); |
|
52 |
|
|
53 |
function pageInit() { |
|
54 |
I.newObj.click(function (e) { |
|
55 |
e.preventDefault(); |
|
56 |
vm.list.push(ko.mapping.fromJS(Obj)); |
|
57 |
refreshTypeahead(); |
|
58 |
}); |
|
59 |
I.searchBtn.click(function(event) { |
|
60 |
doSearch(); |
|
61 |
}); |
|
62 |
I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) { |
|
63 |
if (event.keyCode == 13) { |
|
64 |
doSearch(); |
|
65 |
} |
|
66 |
}); |
|
67 |
} |
|
68 |
|
|
69 |
function doSearch() { |
|
70 |
getList(vm.skeyword(), vm.ckeyword(), vm.type(), 0, I.PZ, 1); |
|
71 |
} |
|
72 |
|
|
73 |
function getList(skeyword, ckeyword, type, page, pagesize, pages) { |
|
74 |
$.post('/basicconfig/mapcompany/getList.htm', { |
|
75 |
skeyword: skeyword, |
|
76 |
ckeyword: ckeyword, |
|
77 |
type: type, |
|
78 |
page: page, |
|
79 |
pagesize: pagesize, |
|
80 |
pages: pages |
|
81 |
}, function(data, textStatus, xhr) { |
|
82 |
vm.list.removeAll(); |
|
83 |
if (data.code >= 1) { |
|
84 |
//parent.showErrmsg(data.errmsg); |
|
85 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
86 |
return; |
|
87 |
} |
|
88 |
if (data.code == 0) { |
|
89 |
if (isList(data.items)) { |
|
90 |
$.each(data.items, function(index, val) { |
|
91 |
// val.sysCompanyNo = val.companyNo; |
|
92 |
// val.sysname = val.name; |
|
93 |
val.companyNo = ko.observable(val.companyNo); |
|
94 |
val.cname = ko.observable(val.cname); |
|
95 |
vm.list.push(val); |
|
96 |
}); |
|
97 |
refreshTypeahead(); |
|
98 |
} |
|
99 |
if (!!pages) { |
|
100 |
pages = data.pages; |
|
101 |
$('#pagdiv').unbind('page').empty(); |
|
102 |
if (pages > 1) { |
|
103 |
$('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){ |
|
104 |
getList(skeyword, ckeyword, type, num - 1, pagesize, 0); |
|
105 |
}); |
|
106 |
} |
|
107 |
} |
|
108 |
return; |
|
109 |
} |
|
110 |
}, 'json'); |
|
111 |
} |
|
112 |
|
|
113 |
function valid() { |
|
114 |
return true; |
|
115 |
} |
|
116 |
|
|
117 |
function doSave() { |
|
118 |
} |
|
119 |
|
|
120 |
function doDel(item) { |
|
121 |
var obj = ko.mapping.toJS(item); |
|
122 |
console.log(obj);return; |
|
123 |
$.post("/basicinfo/mapCompany/doDel.htm", {sysCompanyNo: obj.sysCompanyNo}, |
|
124 |
function (data, textStatus, jqXHR) { |
|
125 |
if (data.code >= 1) { |
|
126 |
//showErrmsg(data.errmsg); |
|
127 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
128 |
return; |
|
129 |
} |
|
130 |
if (data.code == 0) { |
|
131 |
vm.list.remove(item); |
|
132 |
return; |
|
133 |
} |
|
134 |
}, |
|
135 |
"json" |
|
136 |
); |
|
137 |
} |
|
138 |
|
|
139 |
function validMsg(msg) { |
|
140 |
$("#modalContent").html(msg); |
|
141 |
$("#dialog-confirm").removeClass('hide').dialog({ |
|
142 |
resizable: false, |
|
143 |
width: '320', |
|
144 |
modal: true, |
|
145 |
title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>", |
|
146 |
title_html: true, |
|
147 |
position: { my: "center", at: "center", of: window }, |
|
148 |
buttons: [ |
|
149 |
// { |
|
150 |
// html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> 确定", |
|
151 |
// "class" : "btn btn-danger btn-minier", |
|
152 |
// click: function() { |
|
153 |
// $( this ).dialog( "close" ); |
|
154 |
// doDel(item); |
|
155 |
// } |
|
156 |
// } |
|
157 |
// , |
|
158 |
{ |
|
159 |
html: "<i class='ace-icon fa fa-times bigger-110'></i> 确定", |
|
160 |
"class" : "btn btn-minier", |
|
161 |
click: function() { |
|
162 |
$( this ).dialog( "close" ); |
|
163 |
} |
|
164 |
} |
|
165 |
] |
|
166 |
}); |
|
167 |
} |
|
168 |
|
|
169 |
function refreshTypeahead() { |
|
170 |
$('.mtableTypeahead').typeahead('destroy'); |
|
171 |
$('.mtableTypeahead').unbind('typeahead:select'); |
|
172 |
// $('.mtableTypeahead').unbind('typeahead:change'); |
|
173 |
var reception = new Bloodhound({ |
|
174 |
datumTokenizer: Bloodhound.tokenizers.whitespace, |
|
175 |
queryTokenizer: Bloodhound.tokenizers.whitespace, |
|
176 |
remote: { |
|
177 |
url: '/basicconfig/mapcompany/typeahead.htm?query=%QUERY', |
|
178 |
wildcard: '%QUERY' |
|
179 |
} |
|
180 |
}); |
|
181 |
|
|
182 |
$('.mtableTypeahead').typeahead(null, { |
|
183 |
display: 'cname', |
|
184 |
limit: 15, |
|
185 |
source: reception, |
|
186 |
templates: { |
|
187 |
header: '<div id="bx"><span class="bh">编号</span><span class="mc">单位名称</span></div>', |
|
188 |
suggestion: function(data) { |
|
189 |
return '<div><span class="bh">' + data.companyNo + '</span><span class="mc">' + data.cname + '</span></div>'; |
|
190 |
}, |
|
191 |
} |
|
192 |
}); |
|
193 |
|
|
194 |
$('.mtableTypeahead').bind('typeahead:select', function(ev, suggestion) { |
|
195 |
var index = $('.mtableTypeahead.tt-input').index($(this)); |
|
196 |
// index = Math.floor(index / 2); |
|
197 |
// console.log(index); |
|
198 |
doBind(index, suggestion); |
|
199 |
// vm.list()[index].cname(suggestion.name); |
|
200 |
// vm.list()[index].companyNo(suggestion.companyNo); |
|
201 |
// $(this).data('_mlname', suggestion.name); |
|
202 |
}); |
|
203 |
} |
|
204 |
|
|
205 |
function doBind(index, obj) { |
|
206 |
var sysCompanyNo = vm.list()[index].sysCompanyNo; |
|
207 |
var companyNo = obj.companyNo; |
|
208 |
$.post("/basicconfig/mapcompany/bind.htm", { |
|
209 |
sysCompanyNo: sysCompanyNo, |
|
210 |
companyNo: companyNo, |
|
211 |
cname: obj.cname |
|
212 |
}, |
|
213 |
function (data, textStatus, jqXHR) { |
|
214 |
if (data.code >= 1) { |
|
215 |
//showErrmsg(data.errmsg); |
|
216 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
217 |
return; |
|
218 |
} |
|
219 |
if (data.code == 0) { |
|
220 |
console.log('映射成功!'); |
|
221 |
vm.list()[index].cname(obj.cname); |
|
222 |
vm.list()[index].companyNo(obj.companyNo); |
|
223 |
return; |
|
224 |
} |
|
225 |
}, |
|
226 |
"json" |
|
227 |
); |
|
228 |
} |
|
229 |
|
|
230 |
function doUnbind(item) { |
|
231 |
var sysCompanyNo = item.sysCompanyNo; |
|
232 |
$.post("/basicconfig/mapcompany/unbind.htm", { |
|
233 |
sysCompanyNo: sysCompanyNo |
|
234 |
}, |
|
235 |
function (data, textStatus, jqXHR) { |
|
236 |
if (data.code >= 1) { |
|
237 |
//showErrmsg(data.errmsg); |
|
238 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
239 |
return; |
|
240 |
} |
|
241 |
if (data.code == 0) { |
|
242 |
item.cname(''); |
|
243 |
item.companyNo(''); |
|
244 |
console.log('解除成功!'); |
|
245 |
return; |
|
246 |
} |
|
247 |
}, |
|
248 |
"json" |
|
249 |
); |
|
250 |
} |