/**
|
* date:
|
* author: neeler
|
*/
|
|
//test data start
|
// var data_getList = Mock.mock('/business/getItem.htm', { "item": { "td_shrq": "YYYY-MM-DD", "td_bmbh": "0601", "td_bmmc": null, "td_djrq": "20170626", "td_khmc": "巩义市贝思特贸易有限公司", "td_bz": "发上海 不开票 不带清单", "td_ywrq": "20170626", "td_zdr": "王雅", "td_tdbh": "TD-17060001", "td_tdls": "43" }, "code": 0, "list|3-50": [{"tdmx_wlbh": "D8F001","tdmx_wlmc": "8系热轧箔","tdmx_tdfl": "0000000001","tdmx_tdls": "43","tdmx_hjzt": null,"tdmx_dwmx": "吨","tdmx_fdcph": "GFC1706N80075-1","tdmx_bhse": 15372.56,"tdmx_mz": 0.764,"tdmx_pz": 0,"tdmx_jz": 0.679,"tdmx_shdw": "巩义市贝思特贸易有限公司","tdmx_fhdw": "河南眀泰","tdmx_tdlx": "欠款提货","tdmx_sl": 17,"tdmx_ggxh": "0.04*500*C","tdmx_sfzc": "0.0","tdmx_fdcph": "豫C555555", "tdmx_bz": "tdmx_bz", "tdmx_hw": "tdmx_hw"}]})
|
// 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_doUnbind = Mock.mock('/business/doUnbind.htm', {code: 0, })
|
// var data_doBind = Mock.mock('/business/doBind.htm', {code: 0, })
|
// var data_getallList = Mock.mock('/vehicle/getallList.htm', {"rowCount":0,"pagesize":0,"pages":0,"page":0,"items":null,"list":[{"note":null,"companyNo":"009","driver":"九阳神功","loadweight":15.0,"phone":"13007607721","companyName":"运输部","rownumber":1,"id|+1": 1,"state":1,"vehicleId":"豫A11111","vehicleweight":10.0}],"hint":null,"errmsg":null,"code":0})
|
// var data_saveItem = Mock.mock('/business/saveItem.htm', {code: 0, })
|
// var data_doDel = Mock.mock('/transport/yscompany/del.htm', {code: 0, errmsg: 'errmsg'})
|
// var data_doSave = Mock.mock('/transport/yscompany/save.htm', {code: 0, errmsg: 'errmsg'})
|
//test data end
|
|
var SORT = [
|
{key: '批次号', value: 'tdmx_fdcph', visible: ko.observable(true)},
|
{key: '规格型号', value: 'tdmx_ggxh', visible: ko.observable(true)},
|
{key: '包装', value: 'tdmx_zpbz', visible: ko.observable(true)},
|
{key: '货位', value: 'tdmx_hwbh', visible: ko.observable(true)},
|
{key: '毛重', value: 'tdmx_mz', visible: ko.observable(true)},
|
{key: '净重', value: 'tdmx_jz', visible: ko.observable(true)}
|
]
|
|
window.I = {
|
_lastIndex: 0,
|
nowVehicle: null,
|
no: $('#no').val(),
|
vehicleKeyword: $('#vehicleKeyword'),
|
searchVehicleBtn: $('#searchVehicleBtn'),
|
refreshVehicleBtn: $('#refreshVehicleBtn'),
|
tempVehicleModal: $('#tempVehicleModal'),
|
addTempVehicle: $('#addTempVehicle'),
|
selectAllBtn: $('#selectAllBtn'),
|
selectNoBtn: $('#selectNoBtn'),
|
clearSelectBtn: $('#clearSelectBtn'),
|
piciKeyword:$('#piciKeyword'),
|
searchpiciBtn:$('#searchpiciBtn'),
|
SortBtn:$('#SortBtn'),
|
clearSortBtn: $('#clearSortBtn'),
|
ssortBtn:$('#searchSortBtn'),
|
sxBtn:$('#sxBtn'),
|
companyKeyword: $('#companyKeyword'),
|
companyModal: $("#companyModal"),
|
companyButton: $("#companyButton"),
|
companyBindBtn: $("#companyBindBtn"),
|
changeCompanyButton: $("#changeCompanyButton"),
|
modal: $("#modal")
|
|
}
|
|
var Obj = {
|
vehicleId: '豫A',
|
driver: '',
|
phone: '',
|
IDNum: '',
|
vehicleweight: '',
|
loadweight: '',
|
note: '',
|
feature: ''
|
}
|
|
var TD = {
|
td_bmbh: '',
|
td_bmmc: '',
|
td_bz: '',
|
td_djrq: '',
|
td_khmc: '',
|
td_tdbh: '',
|
td_tdls: '',
|
td_ywrq: '',
|
td_zdr: '',
|
td_shrq: '',
|
td_shsj: '',
|
td_fpbh:''
|
}
|
|
var ViewModel = function() {
|
var self = this;
|
self.o = ko.observable(ko.mapping.fromJS(Obj));
|
self.td = ko.observable(TD);
|
self.vList = ko.observableArray();
|
self.list = ko.observableArray();
|
self.mxWlgs = ko.observableArray();
|
self.companyName = ko.observable('');
|
self.companyNo = ko.observable('');
|
|
self.isAdmin = ko.observable(typeof(parent.G) != 'undefined' ? parent.G.isAdmin : false);
|
|
self.isSelectAll = ko.observable(false);
|
self.allNum = ko.observable(0);
|
self.bindNum = ko.observable(0);
|
self.unbindNum = ko.observable(0);
|
|
self.selectedNum = ko.observable(0);
|
self.selectedMZ = ko.observable(0);
|
self.selectedJZ = ko.observable(0);
|
|
self.select = function (item) {
|
I.nowVehicle = {};
|
for(attr in item) {
|
I.nowVehicle[attr] = item[attr];
|
}
|
}
|
self.oList = ko.observableArray(SORT);
|
self.soList = ko.observableArray();
|
self.addSort = function (item) {
|
addSort(item);
|
}
|
self.removeSort = function (item) {
|
removeSort(item);
|
}
|
}
|
|
$(function () {
|
window.vm = new ViewModel();
|
ko.applyBindings(vm);
|
autoHeight();
|
// getVehicleList();
|
getCompanyList();
|
if (!!I.no) {
|
getList(I.no);
|
}
|
pageInit();
|
});
|
function doCompanyButtonBind(){
|
vm.mxWlgs.removeAll();
|
$.each($('.mitem.info'), function (index, value) {
|
let val = vm.list()[$(this).attr('data-indx')]
|
vm.mxWlgs.push({tdmxTdfl:val.tdmx_tdfl, tdTdls: val.tdmx_tdls, wlgsNo: vm.companyNo()});
|
});
|
I.changeCompanyButton.prop('disabled', true);
|
$.ajax({
|
url: '/business/changeWlgs.htm',
|
type: 'post',
|
data: JSON.stringify(vm.mxWlgs()),
|
success: function (data, textstatus, xhr) {
|
if (data.code >= 1) {
|
//parent.showerrmsg(data.errmsg);
|
swal({title: '', text: data.errmsg, type: 'error', confirmbuttontext: '确定'});
|
return;
|
}
|
if (data.code == 0) {
|
showErrmsg('操作提示!');
|
getList(I.no);
|
setTimeout( _=>{
|
I.changeCompanyButton.removeAttr("disabled");
|
},2000)
|
}
|
},
|
contentType: "application/json",
|
dataType: "json"
|
});
|
}
|
function objToFormDate(obj) {
|
return obj
|
}
|
function pageInit() {
|
I.sxBtn.click(function (e) {
|
getList(I.no)
|
})
|
I.companyBindBtn.click(function (e) {
|
e.preventDefault();
|
if ($('.vitem.info').length) {
|
// validMessage('确定要取消配车吗?', doUnbind)
|
I.companyModal.modal('hide',doCompanyBind());
|
} else {
|
parent.showErrmsg('请选择一个公司!');
|
}
|
})
|
I.changeCompanyButton.click(function (e) {
|
e.preventDefault();
|
if ($('.mitem.info').length) { // 提交代码
|
doCompanyButtonBind()
|
} else {
|
parent.showErrmsg('请选择一个提单物资!');
|
}
|
})
|
I.companyButton.click(function (e) {
|
e.preventDefault();
|
// vm.o(ko.mapping.fromJS(Obj));
|
I.companyModal.modal('show');
|
});
|
I.companyModal.on('hidden.bs.modal', function (e) {
|
clearError();
|
});
|
I.companyKeyword.keyup(function (e) {
|
// updateVList();
|
getCompanyList();
|
});
|
I.searchVehicleBtn.click(function (e) {
|
e.preventDefault();
|
// updateVList();
|
getCompanyList();
|
});
|
I.refreshVehicleBtn.click(function (e) {
|
e.preventDefault();
|
getCompanyList();
|
});
|
|
I.selectAllBtn.click(function (e) {
|
e.preventDefault();
|
/*for(var i=0;i<I._MDB.length;i++){
|
if(I.bindNumBtn.hasClass('btn-info')){
|
if (I._MDB[i].tdmx_fdcph() !== '') {
|
if($('#piciKeyword').val()=='' || I._MDB[i].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
|
I._MDB[i].chooseCli=true;
|
}
|
}
|
}else if(I.unbindNumBtn.hasClass('btn-info')){
|
if (I._MDB[i].tdmx_fdcph() == '') {
|
if($('#piciKeyword').val()=='' || I._MDB[i].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
|
I._MDB[i].chooseCli=true;
|
}
|
}
|
}else{
|
if($('#piciKeyword').val()=='' || I._MDB[i].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
|
I._MDB[i].chooseCli=true;
|
}
|
}
|
}*/
|
$.each($('.mitem'), function (index, value) {
|
// let val = vm.list()[$(this).attr('data-indx')]
|
if (vm.list()[index].fkStatus > 0){
|
return;
|
}
|
$(this).addClass('info');
|
});
|
// $('.mitem').addClass('info');
|
// computedSelect();
|
});
|
I.selectNoBtn.click(function (e) {
|
e.preventDefault();
|
for(var i=0;i<I._MDB.length;i++){
|
if(I.bindNumBtn.hasClass('btn-info')){
|
if (I._MDB[i].tdmx_fdcph() !== '') {
|
if($('#piciKeyword').val()=='' || I._MDB[i].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
|
I._MDB[i].chooseCli=false;
|
}
|
}
|
}else if(I.unbindNumBtn.hasClass('btn-info')){
|
if (I._MDB[i].tdmx_fdcph() == '') {
|
if($('#piciKeyword').val()=='' || I._MDB[i].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
|
I._MDB[i].chooseCli=false;
|
}
|
}
|
}else{
|
if($('#piciKeyword').val()=='' || I._MDB[i].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
|
I._MDB[i].chooseCli=false;
|
}
|
}
|
}
|
$('.mitem').removeClass('info');
|
computedSelect();
|
});
|
I.searchpiciBtn.click(function (e) {
|
e.preventDefault();
|
if($('#piciKeyword').val()!=''){
|
vm.list.removeAll();
|
$.each(I._MDB, function (index, value) {
|
if(value.tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
|
if(I.bindNumBtn.hasClass('btn-info')){
|
if (value.tdmx_fdcph() !== '') {
|
vm.list.push(value);
|
if(value.chooseCli){
|
$('.mitem:last').addClass("info");
|
}
|
}
|
}else if(I.unbindNumBtn.hasClass('btn-info')){
|
if (value.tdmx_fdcph() == '') {
|
vm.list.push(value);
|
if(value.chooseCli){
|
$('.mitem:last').addClass("info");
|
}
|
}
|
}else{
|
vm.list.push(value);
|
if(value.chooseCli){
|
$('.mitem:last').addClass("info");
|
}
|
}
|
}
|
});
|
setMaterialTableEvent();
|
computedSelect();
|
}else{
|
vm.list.removeAll();
|
$('.mStatus').removeClass('btn-info');
|
I.unbindNumBtn.addClass('btn-info');
|
$.each(I._MDB, function (index, value) {
|
if (value.tdmx_fdcph()== '') {
|
vm.list.push(value);
|
if(value.chooseCli){
|
$('.mitem:last').addClass("info");
|
}
|
}
|
});
|
setMaterialTableEvent();
|
computedSelect();
|
}
|
|
});
|
I.clearSelectBtn.click(function (e) {
|
e.preventDefault();
|
for(var i=0;i<I._MDB.length;i++){
|
I._MDB[i].chooseCli=false;
|
}
|
$('.mitem').removeClass('info');
|
computedSelect();
|
});
|
I.SortBtn.click(function (e) {
|
e.preventDefault();
|
I.modal.modal('show');
|
});
|
I.clearSortBtn.click(function (e) {
|
e.preventDefault();
|
vm.soList.removeAll();
|
$.each(vm.oList(), function (index, value) {
|
value.visible(true);
|
});
|
});
|
I.ssortBtn.click(function(e){
|
e.preventDefault();
|
vm.list.removeAll();
|
I._MDB.sort(SortList);
|
$.each(I._MDB, function (index, value) {
|
// console.log('排序后:::'+value);
|
if(I.bindNumBtn.hasClass('btn-info')){
|
if (value.tdmx_fdcph() !== '') {
|
if($('#piciKeyword').val()=='' || value.tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
|
vm.list.push(value);
|
if(value.chooseCli){
|
$('.mitem:last').addClass("info");
|
}
|
}
|
}
|
}else if(I.unbindNumBtn.hasClass('btn-info')){
|
if (value.tdmx_fdcph() == '') {
|
if($('#piciKeyword').val()=='' || value.tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
|
vm.list.push(value);
|
if(value.chooseCli){
|
$('.mitem:last').addClass("info");
|
}
|
}
|
}
|
}else{
|
if($('#piciKeyword').val()=='' || value.tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
|
vm.list.push(value);
|
if(value.chooseCli){
|
$('.mitem:last').addClass("info");
|
}
|
}
|
}
|
});
|
setMaterialTableEvent();
|
computedSelect();
|
});
|
|
}
|
|
function getList(keyword) {
|
$.post('/business/getBillofLadingItem.htm', {
|
keyword: keyword
|
}, 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) {
|
I._MDB = [];
|
data.item.td_shsj = data.item.td_shsj;//.slice(0, 19);
|
vm.td(data.item);
|
if (isList(data.list)) {
|
$.each(data.list, function (index, value) {
|
value.tdmx_fdcph = ko.observable(value.tdmx_fdcph);
|
value.indx = index + '';
|
vm.list.push(value);
|
value.chooseCli=false;
|
I._MDB.push(value);
|
});
|
}
|
setMaterialTableEvent();
|
computedSelect();
|
updateNum();
|
return;
|
}
|
}, 'json');
|
}
|
|
function updateNum() {
|
var allNum = I._MDB.length;
|
var unbindNum = 0;
|
$.each(I._MDB, function (index, value) {
|
value.tdmx_fdcph() === '' && unbindNum++;
|
});
|
vm.allNum(allNum);
|
vm.bindNum(allNum - unbindNum);
|
vm.unbindNum(unbindNum);
|
}
|
|
function setMaterialTableEvent() {
|
$('.mitem').unbind('click').click(function (e) {
|
var index = $('.mitem').index($(this));
|
e.preventDefault();
|
if (vm.list()[index].fkStatus > 0){
|
return;
|
}
|
if (e.shiftKey) {
|
setMaterialTrSelected(Math.min(index, I._lastIndex), Math.max(index, I._lastIndex))
|
} else {
|
I._lastIndex = index;
|
var pchcc=vm.list()[index].tdmx_fdcph;
|
for(var mdblg=0;mdblg<I._MDB.length;mdblg++){
|
var pchmdb=I._MDB[mdblg].tdmx_fdcph;
|
if(pchmdb==pchcc){
|
I._MDB[mdblg].chooseCli=I._MDB[mdblg].chooseCli?false:true;
|
break;
|
}
|
}
|
$(this).toggleClass('info');
|
}
|
computedSelect();
|
});
|
}
|
|
function setMaterialTrSelected(start, end) {
|
$.each($('.mitem'), function (index, value) {
|
if (index >= start && index <= end) {
|
if (vm.list()[index].fkStatus > 0){
|
return;
|
}
|
var pchcc=vm.list()[index].tdmx_fdcph;
|
for(var mdblg=0;mdblg<I._MDB.length;mdblg++){
|
var pchmdb=I._MDB[mdblg].tdmx_fdcph;
|
if(pchmdb==pchcc){
|
I._MDB[mdblg].chooseCli=I._MDB[mdblg].chooseCli?false:true;
|
break;
|
}
|
}
|
$(this).addClass('info');
|
}
|
});
|
}
|
|
function computedSelect() {
|
/* var selectedNum = 0;
|
var selectedPZ = 0;
|
$.each($('.bitem.info'), function (index, value) {
|
var indx = $(this).attr('data-indx');
|
var obj = vm.list()[indx];
|
selectedNum += obj.td_wfdsl;
|
selectedPZ += obj.td_wfdzl;
|
});
|
vm.selectedNum(selectedNum);
|
vm.selectedPZ(selectedPZ.toFixed(3));*/
|
}
|
|
|
function getCompanyList() {
|
$.post("/company/getList.htm", {
|
searchword: I.companyKeyword.val(),
|
page: 0,
|
pagesize: 10,
|
pages: 1,
|
},
|
function (data, textStatus, jqXHR) {
|
I.VDB = [];
|
if (data.code >= 1) {
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
vm.vList.removeAll();
|
if (isList(data.list)) {
|
$.each(data.list, function (index, value) {
|
value.indx = index + '';
|
value.ywdyNames ='';
|
value.ywList.forEach(yw=> {
|
value.ywdyNames += yw.name + ","
|
})
|
value.ywdyNames = value.ywdyNames.replace(/,$/,'')
|
vm.vList.push(value);
|
});
|
}
|
$('.vitem').click(function (e) {
|
$('.vitem').removeClass('info');
|
$(this).addClass('info');
|
});
|
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 clearError() {
|
$('#form input').removeClass('error');
|
$('#form .text-error').html('');
|
}
|
|
function autoHeight() {
|
$('.page-content').css('min-height', $(parent.window).height() - 117);
|
$('.table-responsive').css('height', $(parent.window).height() - 275);
|
$('.split').css('left', $('.table-vehicle').width() + 12);
|
}
|
|
function validMessage(message, cb, cbparams) {
|
$("#modalContent").html(message);
|
$("#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" );
|
cb(cbparams);
|
}
|
}
|
,
|
{
|
html: "<i class='ace-icon fa fa-times bigger-110'></i> 取消",
|
"class" : "btn btn-minier",
|
click: function() {
|
$( this ).dialog( "close" );
|
}
|
}
|
]
|
});
|
}
|
|
|
function doCompanyBind() {
|
$.each($('.vitem.info'), function (index, value) {
|
let val = vm.vList()[$(this).attr('data-indx')]
|
vm.companyNo(val.companyNo);
|
vm.companyName(val.name);
|
});
|
$(".vitem.info").removeClass("info");
|
// I.companyBindBtn.prop('disabled', true);
|
|
// var arr = getSelectBiz();
|
// var company = ko.mapping.toJS(vm.o());
|
|
}
|
|
function SortList(Obj1,Obj2){
|
var reval=0;
|
$.each(vm.soList(), function (index, value) {
|
var ASCStr=value.result();
|
var fieLd=value.target;
|
if(ASCStr==null||ASCStr==''){
|
ASCStr="asc";
|
}
|
if(fieLd==null||fieLd==''){
|
reval=0;
|
}
|
if("asc"==ASCStr){
|
if(!isNaN(Obj1[fieLd])){
|
if(Obj1[fieLd]-Obj2[fieLd]>0){
|
reval=1;
|
return false;
|
}else if(Obj1[fieLd]-Obj2[fieLd]<0){
|
reval=-1;
|
return false;
|
}else{
|
reval=0;
|
}
|
}else{
|
if(Obj1[fieLd]> Obj2[fieLd]){
|
reval=1;
|
return false;
|
}else if(Obj1[fieLd]< Obj2[fieLd]){
|
reval=-1;
|
return false;
|
}else{
|
reval=0;
|
}
|
}
|
}else{
|
if(!isNaN(Obj1[fieLd])){
|
if(Obj2[fieLd]-Obj1[fieLd]>0){
|
reval=1;
|
return false;
|
}else if(Obj2[fieLd]-Obj1[fieLd]<0){
|
reval=-1;
|
return false;
|
}else{
|
reval=0;
|
}
|
}else{
|
if(Obj2[fieLd]> Obj1[fieLd]){
|
reval=1;
|
return false;
|
}else if(Obj2[fieLd]< Obj1[fieLd]){
|
reval=-1;
|
return false;
|
}else{
|
reval=0;
|
}
|
}
|
|
}
|
});
|
return reval;
|
|
}
|
function addSort(item) {
|
item.visible(false);
|
var obj = {
|
key: item.key,
|
target: item.value,
|
result: ko.observable('asc')
|
}
|
vm.soList.push(obj);
|
}
|
|
function removeSort(item) {
|
vm.soList.remove(item);
|
$.each(vm.oList(), function (index, value) {
|
value.key === item.key && value.visible(true);
|
});
|
}
|