/**
|
* date:
|
* author: neeler
|
*/
|
|
//test data start
|
// var data_getVehicleTypeList = Mock.mock('/enterprise/vehicletype/getList.htm', {code: 0, list: [
|
// {id: 1, name: '货车类型1', note: '货车类型1',},
|
// {id: 2, name: '货车类型2', note: '货车类型2',},
|
// {id: 3, name: '货车类型3', note: '货车类型3',},
|
// {id: 4, name: '货车类型4', note: '货车类型4',},
|
// {id: 5, name: '货车类型5', note: '货车类型5',},
|
// {id: 6, name: '货车类型6', note: '货车类型6',},
|
// {id: 7, name: '货车类型7', note: '货车类型7',},
|
// {id: 8, name: '货车类型8', note: '货车类型8',},
|
// {id: 9, name: '货车类型9', note: '货车类型9',},
|
// {id: 10, name: '货车类型10', note: '货车类型10',},
|
// {id: 11, name: '货车类型11', note: '货车类型11',}
|
// ], pages: 12})
|
// var data_getList = Mock.mock('/enterprise/whitevehicle/getList.htm', {code: 0, 'list|3-19': [
|
// {numberplates: '豫A88888', cardID: '56456465778', vtypename: '厂内车辆', sdate: '2015-07-08', edate: '2030-12-12', departid: '1', departname: '企管部', vtypeid: 3, ctime: '2016-11-11', note: 'nnnnnnnnnote', createid: '1', cname: '顾小白', cdepartid: '1', cdepart: '政务部'}
|
// ], 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('/enterprise/whitevehicle/delItem.htm', {code: 0, errmsg: ''})
|
// var data_doSave = Mock.mock('/enterprise/whitevehicle/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()),
|
newObj: $('#newObj'),
|
modal: $('#modal'),
|
save: $('#save'),
|
departName: $('#departName'),
|
departModal: $('#departModal'),
|
search: $('#search'),
|
saveDepart: $('#saveDepart'),
|
_type: {}, //全部货车类型
|
edate: $('#edate'),
|
sdate: $('#sdate')
|
}
|
|
var Obj = {
|
numberplates: '豫A',
|
cardID: '',
|
vtypeid: '',
|
vtypename: '',
|
sdate: '',
|
edate: '',
|
departid: '',
|
departname: '',
|
ctime: '',
|
note: '',
|
createid: '',
|
cname: '',
|
cdepartid: '',
|
cdepart: '',
|
enState: '',
|
valid: true,
|
driver: '',
|
phone: ''
|
}
|
|
var ViewModel = function() {
|
var self = this;
|
self.o = ko.observable(ko.mapping.fromJS(Obj));
|
|
self.keyword = ko.observable(I.keywordValue);
|
self.list = ko.observableArray();
|
|
self.dList = ko.observableArray();
|
|
self.neworedit=ko.observable(true);
|
|
self.edit = function(item) {
|
self.neworedit(false);
|
doEdit(item);
|
}
|
self.del = function(item) {
|
delConfirm(item);
|
}
|
self.did = ko.observable(I.dValue);
|
|
self.change = function() {
|
doOpen();
|
}
|
|
self.tList = ko.observableArray();
|
|
self.valid = function (item) {
|
doValid(item);
|
}
|
self.tid = ko.observable();
|
}
|
|
$(function () {
|
window.vm = new ViewModel();
|
doSearch();
|
autoHeight();
|
ko.applyBindings(vm);
|
getVehicleTypeList();
|
getDepartList();
|
pageInit();
|
});
|
|
function pageInit() {
|
$('.table-responsive').scroll(function() {
|
$('.th').css('top', $(this).scrollTop());
|
})
|
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.save.click(function(event) {
|
if (valid()) {
|
doSave();
|
}
|
});
|
I.newObj.click(function(event) {
|
vm.neworedit(true);
|
vm.o(ko.mapping.fromJS(Obj));
|
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('whitevehicle.jsf' + k + d, '_self');
|
doSearch();
|
}
|
|
function doSearch() {
|
getList(vm.keyword(), vm.tid(), vm.did(), I.pageValue, I.PZ, 1);
|
}
|
|
|
function getList(keyword, vtypeid, depart, page, pagesize, pages) {
|
$.post('/enterprise/whitevehicle/getList.htm', {
|
keyword: keyword,
|
vtypeid: vtypeid,
|
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) {
|
// val.numberplates += index;
|
val.valid = ko.observable(val.valid);
|
vm.list.push(val);
|
});
|
$('tbody tr').click(function (e) {
|
$('tbody tr').removeClass('info');
|
$(this).addClass('info');
|
});
|
}
|
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('whitevehicle.jsf?page=' + num + k + d, '_self');
|
getList(keyword, vtypeid, depart, num - 1, pagesize, 0);
|
});
|
}
|
}
|
return;
|
}
|
}, 'json');
|
}
|
|
function valid(){
|
var isValid = false;
|
var iF = $('#form');
|
iF.validate({
|
rules: {
|
'numberplates': {
|
required: true,
|
isPlateNumber: true
|
// remote: {
|
// url: '/enterprise/whitevehicle/checkPlateNumber.htm', //后台处理程序
|
// type: 'post', //数据发送方式
|
// dataType: 'json', //接受数据格式
|
// data: { //要传递的数据
|
// // numberplates: $('#numberplates').val().toUpperCase()
|
// numberplates: function() {
|
// return vm.o().numberplates().toUpperCase();
|
// }
|
// }
|
// }
|
},
|
'departName': {
|
required: true
|
},
|
'sdate': {
|
required: true
|
},
|
'edate': {
|
required: true
|
},
|
'cardID': {
|
required: true,
|
remote: {
|
url: '/gates/cardinuse/checkCardno.htm',
|
type: 'post',
|
dataType: 'json',
|
data: {
|
cardno: function() {
|
return vm.o().cardID();
|
}
|
}
|
}
|
}
|
},
|
messages: {
|
'numberplates': {
|
required: '车牌号不能为空!',
|
isPlateNumber: '车牌号不正确!'
|
//remote: '车牌号已存在!'
|
},
|
'departName': {
|
required: '部门未选择!'
|
},
|
'sdate': {
|
required: '起始日期未选择!'
|
},
|
'edate': {
|
required: '截止日期未选择!'
|
},
|
'cardID': {
|
required: '卡号不能为空!',
|
remote: '该卡不能使用!'
|
}
|
},
|
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.numberplates + '】吗?');
|
$("#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('/enterprise/whitevehicle/delItem.htm', {id: item.numberplates}, 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());
|
o.numberplates = o.numberplates.toUpperCase();
|
o.sdate = I.sdate.val();
|
o.edate = I.edate.val();
|
o.vtypename = I._type[o.vtypeid];
|
o.valid = $('#objUsed').prop('checked');
|
$.post('/enterprise/whitevehicle/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) {
|
if (val.level > 1) {
|
for (var i = 1; i < val.level; i++) {
|
val.name = '-' + val.name;
|
}
|
}
|
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: []
|
})
|
}
|
});
|
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 getVehicleTypeList() {
|
$.post('/enterprise/vehicletype/getList.htm', {
|
keyword: null,
|
page: 0,
|
pagesize: null,
|
pages: 0
|
}, function(data, textStatus, xhr) {
|
vm.tList.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) {
|
I._type[val.id] = val.name;
|
vm.tList.push(val);
|
});
|
}
|
}
|
}, 'json');
|
}
|
|
function doValid(item) {
|
if (!I.AjaxChangeUsed) {
|
var valid = !item.valid();
|
I.AjaxChangeUsed = true;
|
$.post('/enterprise/whitevehicle/valid.htm', {vehicleID: item.numberplates, valid: valid}, function(data, textStatus, xhr) {
|
I.AjaxChangeUsed = false;
|
if (data.code >= 1) {
|
//parent.showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
item.valid(valid);
|
return;
|
}
|
}, 'json');
|
}
|
}
|
|
function autoHeight() {
|
$('.page-content').css('min-height', $(parent.window).height() - 117);
|
$('.table-responsive').css('height', $(parent.window).height() - 217);
|
}
|
|
$(window).resize(function() {autoHeight();})
|