/**
|
* date:
|
* author: neeler
|
*/
|
|
//test data start
|
// var data_getList = Mock.mock('/basicconfig/weighthouse/getList.htm', {code: 0, list: [{id: 22, weighthNo: 'wh0001', name: '磅房1', address: '南门旁边', note: 'nnnnn', status: '正常', departname: '铝锭库', departID: '22'}], pages: 12})
|
// var data_doDel = Mock.mock('/basicconfig/weighthouse/del.htm', {code: 0, })
|
// var data_getGid = Mock.mock('/basicconfig/weighthouse/getGid.htm', {code: 0, item: '1' })
|
//test data end
|
|
var STATUS = [ '正常', '维修', '停止'];
|
|
var Obj = {
|
id: 0,
|
weighthNo: '',
|
name: '',
|
address: '',
|
note: '',
|
status: '',
|
departname: '',
|
departID: '',
|
}
|
|
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'),
|
gatesModal: $('#gatesModal'),
|
saveGid: $('#saveGid')
|
}
|
|
var ViewModel = function() {
|
var self = this;
|
self.o = ko.observable(ko.mapping.fromJS(Obj));
|
|
self.keyword = ko.observable(I.keywordValue);
|
self.sList = ko.observableArray(STATUS); //磅房状态
|
self.dList = ko.observableArray(); //部门列表
|
self.did = ko.observable(I.dValue); //选择的部门的值
|
self.list = ko.observableArray();
|
self.change = function() {
|
doOpen();
|
}
|
|
self.edit = function(item) {
|
doEdit(item);
|
}
|
self.del = function(item) {
|
delConfirm(item);
|
}
|
|
self.gList = ko.observableArray(); //门禁列表
|
|
self.gates = function(item) {
|
setGates(item);
|
}
|
|
self.rList = ko.observableArray();
|
|
self.mclient = function(item) {
|
parent.closableTab.addTab({
|
'id': new Date().getTime(),
|
'name': '磅房客户端配置',
|
'url': '/basicinfo/weighthouse_mclient.jsf?relationno=' + item.weighthNo + '&name=' + item.name,
|
'closable': true
|
});
|
}
|
}
|
|
$(function () {
|
window.vm = new ViewModel();
|
ko.applyBindings(vm);
|
getDepartList();
|
getGatesList();
|
doSearch();
|
pageInit();
|
});
|
|
function pageInit() {
|
I.saveGid.click(function (e) {
|
e.preventDefault();
|
saveGid();
|
});
|
I.save.click(function(event) {
|
if (valid()) {
|
doSave();
|
}
|
});
|
I.searchBtn.click(function(event) {
|
doOpen();
|
});
|
I.saveDepart.click(function(event) {
|
vm.o().departID(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.newObj.click(function(event) {
|
vm.o(ko.mapping.fromJS(Obj));
|
getNewNo();
|
I.modal.modal('show');
|
});
|
I.modal.on('hidden.bs.modal', function (e) {
|
clearError();
|
});
|
I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) {
|
if (event.keyCode == 13) {
|
doOpen();
|
}
|
});
|
}
|
|
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/weighthouse/del.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 valid(){
|
var isValid = false;
|
var iF = $('#form');
|
iF.validate({
|
rules: {
|
'weighthNo': {
|
required: true
|
},
|
'name': {
|
required: true
|
},
|
'departname': {
|
required: true
|
}
|
},
|
messages: {
|
'weighthNo': {
|
required: '不能为空!'
|
},
|
'name': {
|
required: '不能为空!'
|
},
|
'departname': {
|
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 doSave() {
|
if (!I.AjaxSaveItem &&valid()) {
|
I.AjaxSaveItem = true;
|
var o = ko.mapping.toJS(vm.o());
|
$.post('/basicconfig/weighthouse/save.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 doSearch() {
|
getList(vm.keyword(), vm.did() || I.dValue, I.pageValue, I.PZ, 1);
|
}
|
|
function getList(keyword, depart, page, pagesize, pages) {
|
$.post('/basicconfig/weighthouse/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 doOpen() {
|
var k = $.trim(vm.keyword());
|
k = !!k ? '?keyword=' + k : '';
|
var d = $.trim(vm.did());
|
d = !!d ? 'd=' + d : '';
|
d = (!!k ? '&' : '?') + d;
|
window.open('weighthouse.jsf' + k + d, '_self');
|
}
|
|
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 setGates(item) {
|
getGid(item.id);
|
$('#dp').val(vm.rList()).trigger("chosen:updated");
|
I.gatesModal.modal('show');
|
}
|
|
function getGid(sid) {
|
I._sid = sid;
|
$.post("/basicconfig/weighthouse/getGid.htm", {sid: sid},
|
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) {
|
if (data.item) {
|
vm.rList(data.item.split(','));
|
} else {
|
vm.rList([]);
|
}
|
$('#dp').val(vm.rList()).trigger("chosen:updated");
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function saveGid() {
|
$.post("/basicconfig/weighthouse/saveGid.htm", {sid: I._sid, gid: vm.rList().join(',')},
|
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) {
|
parent.showErrmsg('保存成功!');
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function getGatesList() {
|
$.post('/basicconfig/gates/getList.htm', {
|
keyword: null,
|
depart: null,
|
page: 0,
|
pagesize: null,
|
pages: 0
|
}, function(data, textStatus, xhr) {
|
vm.gList.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.gList.push(val);
|
});
|
$('.chosen-select').chosen({search_contains: true});
|
}
|
return;
|
}
|
}, 'json');
|
}
|
|
function getNewNo() {
|
$.post("/basicconfig/prefix/getNewNo.htm", {type: 'weighthouse'},
|
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);
|
$('#weighthNo').val(data.number);
|
return;
|
}
|
},
|
"json"
|
);
|
}
|