/**
|
* date:
|
* author: neeler
|
*/
|
|
//test data start
|
// var data_getList = Mock.mock('/task/getList.htm', {code: 0, 'list|6-30': [{bussinessNo: 'bussinessNo', vehicleId: 'vehicleId', fdnum: 'fdnum', fdweight: 'fdweight', driver: 'driver', phone: 'phone', dcompany: 'dcompany', rcompany: 'rcompany', invitecode: 'invitecode', hasCard: false}], pages: 12})
|
// var data_getVehicleList = Mock.mock('/business/getVehicleList.htm', {code: 0, 'list|5-30': [{vehicleId: 'vehicleId', feature: 'feature', note: 'note', fdnum: 'fdnum', fdweight: '4.551', vehicleweight: 'vehicleweight', loadweight: '51.111', driver: 'driver', phone: 'phone'}]})
|
// var data_validVehicle = Mock.mock('/business/validVehicle.htm', {code: 0, errmsg: '车牌号不能使用!'})
|
// var data_changeVehicle = Mock.mock('/task/changeVehicle.htm', {code: 0, })
|
// var data_doDel = Mock.mock('/task/delItem.htm', {code: 0, errmsg: '不能删除!'})
|
// var data_send = Mock.mock('/task/send.htm', {code: 0, })
|
// var data_resend = Mock.mock('/task/resend.htm', {code: 0, item: '23333'})
|
//test data end
|
|
var TYPE = ['千克' ,'吨' ]
|
|
window.I = {
|
PZ: 30,
|
keyword: $('#keyword'),
|
searchBtn: $('#searchBtn'),
|
_page: !!$('#p').val() ? $('#p').val() - 1 : 0,
|
keywordValue: $('#k').val(),
|
newObj: $('#newObj'),
|
modal: $('#modal'),
|
save: $('#save'),
|
vehicleModal: $('#vehicleModal'),
|
tempVehicleModal: $('#tempVehicleModal'),
|
vehicleKeyword: $('#vehicleKeyword'),
|
refreshVehicleBtn: $('#refreshVehicleBtn'),
|
searchVehicleBtn: $('#searchVehicleBtn'),
|
addTempVehicle: $('#addTempVehicle'),
|
vehicleBindBtn: $('#vehicleBindBtn'),
|
tempVehicleSaveBtn: $('#tempVehicleSaveBtn'),
|
sendBtn: $('#sendBtn')
|
}
|
|
var Obj = {
|
vehicleId: '豫A',
|
driver: '',
|
phone: '',
|
IDNum: '',
|
vehicleweight: '',
|
loadweight: '',
|
note: '',
|
feature: ''
|
}
|
|
var ViewModel = function() {
|
var self = this;
|
self.isAdmin = ko.observable(typeof(parent.G) != 'undefined' ? parent.G.isAdmin : false);
|
self.tList = ko.observableArray();
|
self.mtid = ko.observable();
|
self.o = ko.observable(ko.mapping.fromJS(Obj));
|
|
self.keyword = ko.observable(I.keywordValue);
|
self.list = ko.observableArray();
|
|
self.edit = function(item) {
|
doEdit(item);
|
}
|
self.del = function(item) {
|
delConfirm(item);
|
}
|
|
self.change = function() {
|
doOpen();
|
}
|
self.mtvalid=function(item){
|
doValid(item);
|
}
|
|
self.tyList = ko.observableArray(TYPE);
|
self.resend = function(item) {
|
doResend(item);
|
}
|
|
self.details = function(item) {
|
newTab(item);
|
}
|
self.vehicleTasks = function(item) {
|
gotoVehicleDetails(item);
|
}
|
self.changeVehicle = function () {
|
I.vehicleModal.modal('show');
|
}
|
self.vList = ko.observableArray();
|
|
|
//厂区
|
self.cqVal=ko.observable(0);
|
self.cqList=ko.observableArray();
|
self.cqchange=function(){
|
doOpen();
|
}
|
|
}
|
|
$(function () {
|
window.vm = new ViewModel();
|
ko.applyBindings(vm);
|
// doSearch();
|
// getVehicleList();
|
getcqList();
|
autoHeight();
|
if (vm.isAdmin()) {
|
getCompanyList();
|
}
|
pageInit();
|
});
|
|
function pageInit() {
|
I.sendBtn.click(function (e) {
|
e.preventDefault();
|
doSend();
|
});
|
I.tempVehicleSaveBtn.click(function (e) {
|
e.preventDefault();
|
if (valid()) {
|
validVehicle();
|
}
|
});
|
I.vehicleBindBtn.click(function (e) {
|
e.preventDefault();
|
if ($('.vitem.info').length) {
|
doVehicleBind();
|
} else {
|
parent.showErrmsg('请选择一个车辆!');
|
}
|
});
|
I.addTempVehicle.click(function (e) {
|
e.preventDefault();
|
vm.o(ko.mapping.fromJS(Obj));
|
I.vehicleModal.modal('hide');
|
I.tempVehicleModal.modal('show');
|
});
|
I.tempVehicleModal.on('hidden.bs.modal', function (e) {
|
clearError();
|
});
|
I.vehicleKeyword.keyup(function (e) {
|
// updateVList();
|
});
|
I.searchVehicleBtn.click(function (e) {
|
e.preventDefault();
|
// updateVList();
|
});
|
I.refreshVehicleBtn.click(function (e) {
|
e.preventDefault();
|
// getVehicleList();
|
});
|
$('.main-table').scroll(function() {
|
$('.th').css('top', $(this).scrollTop());
|
})
|
I.newObj.click(function(event) {
|
vm.o(ko.mapping.fromJS(Obj));
|
// 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() {
|
doSearch();
|
}
|
|
function doSearch() {
|
getList(vm.keyword(), vm.mtid(), I._page, I.PZ, 1);
|
}
|
|
function doSend() {
|
if (!!I.Ajaxsend) {
|
return;
|
}
|
showErrmsg('该方法已取消,不能使用!');
|
return ;
|
I.Ajaxsend = true;
|
I.sendBtn.prop('disabled', true);
|
$.post("/task/send.htm", null,
|
function (data, textStatus, jqXHR) {
|
I.Ajaxsend = false;
|
I.sendBtn.prop('disabled', false);
|
if (data.code >= 1) {
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
showErrmsg('发送成功!');
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function doVehicleBind() {
|
I.vehicleBindBtn.prop('disabled', true);
|
var bussinessNo = $('.titem.info').attr('data-no');
|
var vehicle = null;
|
var indx = $('.vitem.info').attr('data-indx');
|
$.each(vm.vList(), function (index, value) {
|
if (value.indx === indx) {
|
vehicle = value;
|
}
|
});
|
changeVehicle(bussinessNo, vehicle);
|
}
|
|
function changeVehicle(bussinessNo, vehicle) {
|
if (!!I.AjaxchangeVehicle) {
|
return;
|
}
|
I.AjaxchangeVehicle = true;
|
$.post("/task/changeVehicle.htm", {bussinessNo: bussinessNo, vehicle: $.toJSON(vehicle)},
|
function (data, textStatus, jqXHR) {
|
I.AjaxchangeVehicle = false;
|
I.vehicleBindBtn.prop('disabled', false);
|
I.tempVehicleSaveBtn.prop('disabled', false);
|
if (data.code >= 1) {
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
showErrmsg('换车成功!');
|
doSearch();
|
I.vehicleModal.modal('hide');
|
I.tempVehicleModal.modal('hide');
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function getList(keyword, companyNo, page, pagesize, pages) {
|
I._page = page;
|
$.post('/task/getList.htm', {
|
searchword: keyword,
|
companyNo: vm.isAdmin() ? companyNo : (typeof(parent.G) != 'undefined' ? parent.G.loginCompanyNo : 'ABCDEFG'),
|
page: page,
|
pagesize: pagesize,
|
pages: pages,
|
cqV:vm.cqVal()
|
}, 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.invitecode=ko.observable(val.invitecode);
|
val.hasCard = val.hasCard == 'true';
|
vm.list.push(val);
|
});
|
$('.titem').click(function (e) {
|
$('.titem').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){
|
getList(keyword, companyNo, num - 1, pagesize, 0);
|
});
|
}
|
}
|
return;
|
}
|
}, 'json');
|
}
|
|
function getVehicleList() {
|
$.post("/business/getVehicleList.htm", {
|
companyNo: vm.isAdmin() ? '' : (typeof(parent.G) != 'undefined' ? parent.G.loginCompanyNo : 'ABCDEFG'),
|
vehicleId:'111111'
|
},
|
function (data, textStatus, jqXHR) {
|
I.VDB = [];
|
if (data.code >= 1) {
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
if (isList(data.list)) {
|
$.each(data.list, function (index, value) {
|
value.indx = index + '';
|
value.lastweight = '';
|
if ($.isNumeric(value.loadweight) && $.isNumeric(value.fdweight)) {
|
value.lastweight = (parseFloat(value.loadweight) - parseFloat(value.fdweight)).toFixed(3);
|
}
|
I.VDB.push(value);
|
});
|
}
|
updateVList();
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function updateVList() {
|
var str = I.vehicleKeyword.val();
|
vm.vList.removeAll();
|
if (!!str) {
|
var reg = new RegExp(str);
|
$.each(I.VDB, function (index, value) {
|
if (reg.test(value.vehicleId)) {
|
vm.vList.push(value);
|
}
|
});
|
} else {
|
$.each(I.VDB, function (index, value) {
|
vm.vList.push(value);
|
});
|
}
|
$('.vitem').click(function (e) {
|
$('.vitem').removeClass('info');
|
$(this).addClass('info');
|
});
|
}
|
|
function doTempVehicleBind() {
|
I.tempVehicleSaveBtn.prop('disabled', false);
|
var bussinessNo = $('.titem.info').attr('data-no');
|
var vehicle = ko.mapping.toJS(vm.o());
|
changeVehicle(bussinessNo, vehicle);
|
}
|
|
function validVehicle() {
|
$.post("/business/validVehicle.htm", {vehicleId: ko.mapping.toJS(vm.o()).vehicleId.toUpperCase()},
|
function (data, textStatus, jqXHR) {
|
if (data.code >= 1) {
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
doTempVehicleBind();
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function valid(){
|
var isValid = false;
|
var iF = $('#form');
|
iF.validate({
|
rules: {
|
'vehicleId': {
|
required: true,
|
isPlateNumber: true
|
},
|
'driver': {
|
required: true,
|
},
|
'phone': {
|
required: true,
|
isPhone: true
|
},
|
'IDNum':{
|
required:true,
|
}
|
},
|
messages: {
|
'vehicleId': {
|
required: '不能为空!',
|
isPlateNumber: '车牌号不正确!'
|
},
|
'driver': {
|
required: '不能为空!',
|
},
|
'phone': {
|
required: '不能为空!',
|
isPhone: '手机号不正确!'
|
},
|
'IDNum':{
|
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) {
|
if(isFunction(item.valid)){
|
item.valid=item.valid();
|
}
|
vm.o(ko.mapping.fromJS(item));
|
I.modal.modal('show');
|
}
|
|
function delConfirm(item) {
|
$("#modalContent").html('确定要取消【' + item.vehicleId + '】的派车任务吗?');
|
$("#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('/task/delItem.htm', {bussinessNo: item.bussinessNo}, 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);
|
parent.showErrmsg('删除成功!');
|
return;
|
}
|
}, 'json');
|
}
|
|
function doSave() {
|
if (!I.AjaxSaveItem &&valid()) {
|
I.AjaxSaveItem = true;
|
I.save.prop('disabled', true);
|
var o = ko.mapping.toJS(vm.o());
|
o.vehicleId = o.vehicleId.toUpperCase();
|
o.state = $('#state').prop('checked');
|
o.companyNo = vm.isAdmin() ? o.companyNo : (typeof(parent.G) != 'undefined' ? parent.G.loginCompanyNo : 'ABCDEFG')
|
$.post('/vehicle/saveItem.htm', o, function(data, textStatus, xhr) {
|
I.AjaxSaveItem = false;
|
I.save.prop('disabled', false);
|
if (data.code >= 1) {
|
//parent.showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
parent.showErrmsg('保存成功!');
|
I.modal.modal('hide');
|
getList(vm.keyword(), vm.mtid(), I._page, I.PZ, 1);
|
return;
|
}
|
}, 'json');
|
}
|
}
|
|
function clearError() {
|
$('#form input').removeClass('error');
|
$('#form .text-error').html('');
|
}
|
|
function getCompanyList() {
|
$.post('/company/getList.htm', null, 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) {
|
vm.tList.push(val);
|
});
|
}
|
}
|
}, 'json');
|
}
|
|
function doValid(item){
|
var state=true;
|
if(isFunction(item.state)){
|
state=item.state();
|
}else{
|
state=item.state;
|
}
|
jQuery.post('/vehicle/changeState.htm', {vehicleId: item.vehicleId, state: !state}, function(data, textStatus, xhr) {
|
//optional stuff to do after success
|
if(data.code==0){
|
item.state(data.item);
|
}else{
|
//parent.showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
}
|
},'json');
|
}
|
|
function getNewNo() {
|
$.post("/basicconfig/prefix/getNewNo.htm", {type: 'materiel'},
|
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);
|
$('#materielNo').val(data.number);
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function autoHeight() {
|
$('.page-content').css('min-height', $(parent.window).height() - 117);
|
$('.table-responsive').css('height', $(parent.window).height() - 217);
|
}
|
|
function doResend(item) {
|
$.post("/task/resend.htm", {item: item.bussinessNo},
|
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) {
|
item.invitecode(data.item);
|
parent.showErrmsg('重发成功!');
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function newTab(item) {
|
parent.closableTab.addTab({
|
'id': new Date().getTime(),
|
'name': '业务详情',
|
'url': '/basic/bizDetalis.jsf?id=' + item.id + '&businessNo=' + item.bussinessNo,
|
'closable': true
|
});
|
}
|
|
function gotoVehicleDetails(item) {
|
parent.closableTab.addTab({
|
'id': new Date().getTime(),
|
'name': item.vehicleId + '的配车物资',
|
'url': '/basic/vehicleBindMaterials.jsf?numberplates=' + encodeURI(encodeURI(item.vehicleId)) + '&id=' + item.id+'&bsNo=' + item.bussinessNo,
|
'closable': true
|
});
|
}
|
|
//获取物流公司可操作的厂区
|
function getcqList() {
|
$.post('/company/getcqList.htm', null, function(data, textStatus, xhr) {
|
vm.cqList.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.cqList.push(val);
|
});
|
}
|
}
|
}, 'json');
|
}
|