/**
|
* date:
|
* author: neeler
|
*/
|
|
//test data start
|
// var data_getList = Mock.mock('/basicconfig/gates/getList.htm', {code: 0, list: [{id: 1, gatesNo: '0001', name: '门禁1', cantruck: true, canperson: false, cancar: true, cancar2: true, departname: '部门1', depart: 1}], pages: 12})
|
// var data_getDepartList = Mock.mock('/enterprise/depart/getList.htm', {code: 0, list: [
|
// {id: 1,bianhao: '01',name: '河南明泰',note: '',address: '河南省巩义市', level: 1, pid: 0},
|
// {id: 2,bianhao: '0101',name: '企管部',note: '',address: '办公大楼1楼右', level: 2, pid: 1},
|
// {id: 3,bianhao: '010101',name: '铝锭库',note: '',address: '南门挨着磅房', level: 3, pid: 2},
|
// {id: 4,bianhao: '0102',name: '政务部',note: '',address: '办公大楼1楼左', level: 2, pid: 1},
|
// {id: 5,bianhao: '0103',name: '信息中心',note: '',address: '办公大楼4楼最西', level: 2, pid: 1},
|
// {id: 6,bianhao: '02',name: '高精板带',note: '',address: '河南省巩义市', level: 1, pid: 0},
|
// {id: 7,bianhao: '0201',name: '企管部',note: '',address: '办公大楼1楼左', level: 2, pid: 6},
|
// {id: 8,bianhao: '0202',name: '政务部',note: '',address: '办公大楼', level: 2, pid: 6},
|
// {id: 9,bianhao: '03',name: '郑州明泰',note: '',address: '河南省郑州市', level: 1, pid: 0},
|
// {id: 10,bianhao: '0301',name: '企管部',note: '',address: '办公大楼1楼右', level: 2, pid: 9}
|
// ]})
|
// var data_doDel = Mock.mock('/basicconfig/gates/delItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'})
|
// var data_doSave = Mock.mock('/basicconfig/gates/saveItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'})
|
//test data end
|
|
window.I = {
|
PZ: 30,
|
keyword: $('#keyword'),
|
searchBtn: $('#searchBtn'),
|
pageValue: !!$('#p').val() ? $('#p').val() - 1 : 0,
|
keywordValue: $('#k').val(),
|
dValue: parseInt($('#d').val()) || null,
|
newObj: $('#newObj'),
|
modal: $('#modal'),
|
save: $('#save'),
|
departName: $('#departName'),
|
departModal: $('#departModal'),
|
search: $('#search'),
|
saveDepart: $('#saveDepart')
|
}
|
|
var GateObj = {
|
id: 0,
|
gatesNo: '',
|
name: '',
|
cantruck: false,
|
canperson: false,
|
cancar: false,
|
cancar2: false,
|
departname: '',
|
depart: '',
|
password: ''
|
}
|
|
var ViewModel = function() {
|
var self = this;
|
self.o = ko.observable(ko.mapping.fromJS(GateObj));
|
|
self.keyword = ko.observable(I.keywordValue);
|
self.list = ko.observableArray();
|
|
self.dList = ko.observableArray();
|
|
self.edit = function(item) {
|
doEdit(item);
|
}
|
self.del = function(item) {
|
delConfirm(item);
|
}
|
self.did = ko.observable(I.dValue);
|
|
self.change = function() {
|
doOpen();
|
}
|
|
self.mclient = function(item) {
|
parent.closableTab.addTab({
|
'id': new Date().getTime(),
|
'name': '门禁客户端配置',
|
'url': '/basicinfo/gates_mclient.jsf?relationno=' + item.gatesNo + '&name=' + item.name,
|
'closable': true
|
});
|
}
|
self.cequipment = function(item) {
|
parent.closableTab.addTab({
|
'id': new Date().getTime(),
|
'name': '门禁客户端配置',
|
'url': '/basicinfo/gates_cequipmentList.jsf?relationno=' + item.gatesNo + '&name=' + item.name,
|
'closable': true
|
});
|
}
|
}
|
|
$(function () {
|
window.vm = new ViewModel();
|
ko.applyBindings(vm);
|
doSearch();
|
getDepartList();
|
pageInit();
|
});
|
|
function pageInit() {
|
I.saveDepart.click(function(event) {
|
vm.o().depart(I.selected.id);
|
vm.o().departname(I.selected.text);
|
});
|
I.search.keyup(function(event) {
|
var to = false;
|
if(to) {
|
clearTimeout(to);
|
}
|
to = setTimeout(function () {
|
var v = I.search.val();
|
$('#jstree_Enterprise').jstree(true).search(v);
|
}, 250);
|
});
|
I.departName.click(function(event) {
|
I.departModal.modal('show');
|
});
|
I.save.click(function(event) {
|
if (valid()) {
|
doSave();
|
}
|
});
|
I.newObj.click(function(event) {
|
vm.o(ko.mapping.fromJS(GateObj));
|
getNewNo();
|
I.modal.modal('show');
|
});
|
I.searchBtn.click(function(event) {
|
doOpen();
|
});
|
I.modal.on('hidden.bs.modal', function (e) {
|
clearError();
|
});
|
I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) {
|
if (event.keyCode == 13) {
|
doOpen();
|
}
|
});
|
}
|
|
function doOpen() {
|
var k = $.trim(vm.keyword());
|
k = !!k ? '?keyword=' + k : '';
|
var d = $.trim(vm.did());
|
d = !!d ? 'd=' + d : '';
|
d = (!!k ? '&' : '?') + d;
|
window.open('gates.jsf' + k + d, '_self');
|
}
|
|
function doSearch() {
|
getList(vm.keyword(), vm.did() || I.dValue, I.pageValue, I.PZ, 1);
|
}
|
|
|
function getList(keyword, depart, page, pagesize, pages) {
|
$.post('/basicconfig/gates/getList.htm', {
|
keyword: keyword,
|
depart: depart,
|
page: page,
|
pagesize: pagesize,
|
pages: pages
|
}, function(data, textStatus, xhr) {
|
vm.list.removeAll();
|
if (data.code >= 1) {
|
//parent.showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
if (isList(data.list)) {
|
$.each(data.list, function(index, val) {
|
vm.list.push(val);
|
});
|
}
|
if (!!pages) {
|
pages = data.pages;
|
$('#pagdiv').unbind('page').empty();
|
if (pages > 1) {
|
$('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){
|
var k = !!I.keywordValue ? '&keyword=' + I.keywordValue : '';
|
var d = !!I.dValue ? '&d=' + I.dValue : '';
|
window.open('gates.jsf?page=' + num + k + d, '_self');
|
});
|
}
|
}
|
return;
|
}
|
}, 'json');
|
}
|
|
function valid(){
|
var isValid = false;
|
var iF = $('#form');
|
iF.validate({
|
rules: {
|
'name': {
|
required: true
|
},
|
/*
|
'password': {
|
required: true
|
},
|
*/
|
'departName': {
|
required: true
|
},
|
'gatesNo': {
|
required: true
|
}
|
},
|
messages: {
|
'name': {
|
required: '不能为空!'
|
},
|
/*
|
'password': {
|
required: '密码不能为空!'
|
},
|
*/
|
'departName': {
|
required: '没有所属部门!'
|
},
|
'gatesNo': {
|
required: '不能为空!'
|
}
|
},
|
errorPlacement: function (err, element) {
|
var p = element.parents('.form-group').eq(0);
|
var d = p.find('.text-error').eq(0);
|
d.css('color', '#D9534F');
|
err.appendTo(d);
|
}
|
})
|
isValid = iF.valid();
|
return isValid;
|
}
|
|
function doEdit(item) {
|
vm.o(ko.mapping.fromJS(item));
|
I.modal.modal('show');
|
}
|
|
function delConfirm(item) {
|
$("#modalContent").html('确定要删除【' + item.name + '】吗?');
|
$("#dialog-confirm").removeClass('hide').dialog({
|
resizable: false,
|
width: '320',
|
modal: true,
|
title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>",
|
title_html: true,
|
position: { my: "center", at: "center", of: window },
|
buttons: [
|
{
|
html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> 确定",
|
"class" : "btn btn-danger btn-minier",
|
click: function() {
|
$( this ).dialog( "close" );
|
doDel(item);
|
}
|
}
|
,
|
{
|
html: "<i class='ace-icon fa fa-times bigger-110'></i> 取消",
|
"class" : "btn btn-minier",
|
click: function() {
|
$( this ).dialog( "close" );
|
}
|
}
|
]
|
});
|
}
|
|
function doDel(item) {
|
if (!!I.AjaxDelItem) return;
|
I.AjaxDelItem = true;
|
$.post('/basicconfig/gates/delItem.htm', {id: item.id}, function(data, textStatus, xhr) {
|
I.AjaxDelItem = false;
|
if (data.code >= 1) {
|
// parent.showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
vm.list.remove(item);
|
location.replace(location.href);
|
return;
|
}
|
}, 'json');
|
}
|
|
function doSave() {
|
if (!I.AjaxSaveItem &&valid()) {
|
I.AjaxSaveItem = true;
|
var o = ko.mapping.toJS(vm.o());
|
$.post('/basicconfig/gates/saveItem.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);
|
return;
|
}
|
}, 'json');
|
}
|
}
|
|
function clearError() {
|
$('#form input').removeClass('error');
|
$('#form .text-error').html('');
|
}
|
|
function getDepartList(keyword, page, pagesize, pages) {
|
$.post('/enterprise/depart/getList.htm', {
|
keyword: keyword,
|
page: page,
|
pagesize: pagesize,
|
pages: pages
|
}, function(data, textStatus, xhr) {
|
var allId = [];
|
vm.dList.removeAll();
|
if (data.code >= 1) {
|
// parent.showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
if (!!$('#jstree_Enterprise').jstree(true)) {
|
$('#jstree_Enterprise').jstree(true).refresh();
|
}
|
I.DB_ep = {};
|
if (isList(data.list)) {
|
var Arr = [];
|
var level = 0;
|
$.each(data.list, function(index, val) {
|
vm.dList.push(val);
|
allId.push(val.id);
|
I.DB_ep[val.id] = val;
|
if (val.level === 2) {
|
Arr.push({
|
text: val.name,
|
id: val.id,
|
children: [],
|
state: index === 0 ? {selected: true} : ''
|
});
|
} else {
|
var j = 3;
|
var children = Arr[Arr.length - 1].children;
|
while (j < val.level) {
|
children = children[children.length - 1].children;
|
j++;
|
}
|
children.push({
|
text: val.name,
|
id: val.id,
|
children: []
|
})
|
}
|
});
|
// console.log(allId);
|
if (allId.indexOf(I.dValue) != -1) {
|
vm.did(I.dValue);
|
}
|
$('#jstree_Enterprise')
|
.jstree({
|
core: {
|
check_callback : true,
|
data: Arr
|
},
|
"plugins" : [
|
'search'
|
]
|
})
|
.on("changed.jstree", function (e, data) {
|
if(data.selected.length) {
|
// console.log(data.instance.get_node(data.selected[0]));
|
var selected = data.instance.get_node(data.selected[0]);
|
I.selected = selected;
|
}
|
})
|
}
|
return;
|
}
|
}, 'json');
|
}
|
|
|
function getNewNo() {
|
$.post("/basicconfig/prefix/getNewNo.htm", {type: 'gates'},
|
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().visitNo(data.number);
|
$('#gatesNo').val(data.number);
|
return;
|
}
|
},
|
"json"
|
);
|
}
|