/** * date: * author: neeler */ //test data start // var data_getList = Mock.mock('/business/getList.htm', {code: 0, 'list|5-20': [{td_companyName: 'td_companyName', td_tdbh: 'td_tdbh', td_djrq: 'td_djrq', td_bmbh: 'td_bmbh', td_bmmc: 'td_bmmc', td_khmc: 'td_khmc', td_bz: 'td_bz', td_zdr: 'td_zdr', td_tdls: 'td_tdls', td_ywrq: 'td_ywrq', td_shdd: 'td_shdd', td_wfds: 1, td_wfdl: 1.001, td_shsj: 'td_shsj', companyName: 'companyName'}],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_doBindByList = Mock.mock('/business/doBindByList.htm', {code: 0, }) // var data_doUnbindByList = Mock.mock('/business/doUnbindByList.htm', {code: 0, }) // var data_doDel = Mock.mock('/company/delItem.htm', {code: 0, errmsg: 'errmsg'}) // var data_doSave = Mock.mock('/company/saveItem.htm', {code: 0, errmsg: 'errmsg'}) //test data end var TYPE = [ {key: '提单编号', value: 'tdbh'}, {key: '客户名称', value: 'khmc'}, {key: '收货地点', value: 'shdd'}, {key: '制单部门', value: 'zdbm'}, {key: '制单人', value: 'zdr'}, {key: '发票编号', value: 'fpbh'} ] var SORT = [ {key: '提单编号', value: 'td_tdbh', visible: ko.observable(true)}, {key: '客户名称', value: 'td_khmc', visible: ko.observable(true)}, {key: '收货地点', value: 'td_shdd', visible: ko.observable(true)}, {key: '未分单数量', value: 'td_wfdsl', visible: ko.observable(true)}, {key: '未分单重量', value: 'td_wfdzl', visible: ko.observable(true)}, {key: '制单时间', value: 'td_djrq', visible: ko.observable(true)}, {key: '制单部门', value: 'td_bmmc', visible: ko.observable(true)}, {key: '制单人', value: 'td_zdr', visible: ko.observable(true)}, // {key: '业务日期', value: 'ywrq', visible: ko.observable(true)}, {key: '提单类型', value: 'td_ztbz', visible: ko.observable(true)} ] // {key: '提单编号', target: 'tdbh', result: ko.observable('cancel')}, var Obj = { vehicleId: '豫A', driver: '', phone: '', IDNum: '', vehicleweight: '', loadweight: '', note: '', feature: '' } window.I = { PZ: 30, keyword: $('#keyword'), searchBtn: $('.searchBtn'), moreSearchCondition: $('#moreSearchCondition'), searchBox: $('#searchBox'), sDate: $('#sDate'), eDate: $('#eDate'), sortBtn: $('#sortBtn'), modal: $('#modal'), clearSortBtn: $('#clearSortBtn'), vehicleBtn: $('#vehicleBtn'), vehicleModal: $('#vehicleModal'), refreshVehicleBtn: $('#refreshVehicleBtn'), vehicleKeyword: $('#vehicleKeyword'), searchVehicleBtn: $('#searchVehicleBtn'), vehicleBindBtn: $('#vehicleBindBtn'), addTempVehicle: $('#addTempVehicle'), tempVehicleModal: $('#tempVehicleModal'), tempVehicleBindBtn: $('#tempVehicleBindBtn'), unbindBtn: $('#unbindBtn'), btwcSign:$('#wcSign'), ssortBtn:$('#searchSortBtn'), closefdModel: $('#closefdModel'), fdqxclosefdBtn: $('#fdqxclosefdBtn'), fdqxopenfdBtn: $('#fdqxopenfdBtn'), fdqxclosefdmBtn: $('#fdqxclosefdmBtn') } var ViewModel = function() { var self = this; self.keyword = ko.observable(); self.o = ko.observable(ko.mapping.fromJS(Obj)); self.list = ko.observableArray(); self.tList = ko.observableArray(); self.sList = ko.observableArray(TYPE); self.oList = ko.observableArray(SORT); self.soList = ko.observableArray(); self.companyNo = ko.observable(); self.type = ko.observable(); self.isAdmin = ko.observable(typeof(parent.G) != 'undefined' ? parent.G.isAdmin : false); self.edit = function(item) { newTab(item); } self.print=function(item){ // console.log(item.td_tdbh); newPrintTab(item.td_tdbh); } self.addSort = function (item) { addSort(item); } self.removeSort = function (item) { removeSort(item); } self.selectedNum = ko.observable(0); self.selectedPZ = ko.observable(0); self.fendanChoose=function(){ if($('#wcSign').val()==1){//分单完成 $('#vehicleBtn').hide(); $('#unbindBtn').show(); $('#fdqxclosefdBtn').hide(); $('#fdqxopenfdBtn').hide(); self.selectedNum(0); self.selectedPZ(0); self.fdqxbgType(true); }else if($('#wcSign').val()==0){//未分单完成 $('#vehicleBtn').show(); $('#unbindBtn').show(); $('#fdqxclosefdBtn').show(); $('#fdqxopenfdBtn').hide(); self.selectedNum(0); self.selectedPZ(0); self.fdqxbgType(true); }else{//已关闭 $('#vehicleBtn').hide(); $('#unbindBtn').hide(); $('#fdqxclosefdBtn').hide(); $('#fdqxopenfdBtn').show(); self.selectedNum(0); self.selectedPZ(0); self.fdqxbgType(false); } doOpen(); } self.vList = ko.observableArray(); self.fdqxbgType=ko.observable(true); self.fdqxvehcileId=ko.observable(); self.fdqxdriver=ko.observable(); self.fdqxphone=ko.observable(); //厂区 self.cqVal=ko.observable(0); self.cqList=ko.observableArray(); self.cqchange=function(){ doOpen(); } self.change=function(){ doOpen(); } } $(function () { window.vm = new ViewModel(); ko.applyBindings(vm); I.sDate.val(new Date((new Date().getTime() - 30*24*3600*1000)).Format('yyyy-MM-dd')); I.eDate.val(new Date().Format('yyyy-MM-dd')); if (vm.isAdmin()) { getCompanyList(); } getVehicleList(); getcqList(); autoHeight(); // doOpen(); pageInit(); }); function pageInit() { I.unbindBtn.click(function (e) { e.preventDefault(); if ($('.bitem.info').length) { // doUnbindByList(getSelectBiz()); validMessage('确定要取消配车吗?', doUnbindByList, getSelectBiz()); } else { parent.showErrmsg('请选择一个提单!'); } }); I.tempVehicleBindBtn.click(function (e) { e.preventDefault(); if (valid()) { validVehicle(); } }); 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.vehicleBindBtn.click(function (e) { e.preventDefault(); if ($('.vitem.info').length) { doVehicleBind(); } else { parent.showErrmsg('请选择一个车辆!'); } }); I.vehicleKeyword.keyup(function (e) { // updateVList(); getVehicleList(); }); I.searchVehicleBtn.click(function (e) { e.preventDefault(); getVehicleList(); // updateVList(); }); I.refreshVehicleBtn.click(function (e) { e.preventDefault(); getVehicleList(); }); I.vehicleBtn.click(function (e) { e.preventDefault(); if ($('.bitem.info').length) { I.vehicleModal.modal('show'); } else { parent.showErrmsg('请选择一个提单!'); } }); 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){ doOpen(); }); $('.main-table').scroll(function() { $('.th').css('top', $(this).scrollTop()); }) I.moreSearchCondition.click(function(event) { if ($(this).hasClass('active')) { I._complexSearch = false; $(this).removeClass('active'); $('i', $(this)).addClass('fa-chevron-down').removeClass('fa-chevron-up'); I.searchBox.slideUp(); } else { I._complexSearch = true; $(this).addClass('active'); $('i', $(this)).removeClass('fa-chevron-down').addClass('fa-chevron-up'); I.searchBox.slideDown(); } }); I.searchBtn.click(function(event) { doOpen(); }); // I.btwcSign.(function(event){ // if(){ // doOpen(); // } // }) I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) { if (event.keyCode == 13) { doOpen(); } }); I.fdqxclosefdBtn.click(function(event){ //判断选择了多个只能选择一个 if($('.bitem.info').length>1){ swal({title:'',text:'不能选择多个销售提单同时关闭,请选择一个销售提单!',type:'error',confirmButtonText:'确定'}); return ; } if($('.bitem.info').length<1){ swal({title:'',text:'未选择需要关闭的销售提单,请先选择一个销售提单!',type:'error',confirmButtonText:'确定'}); return ; } //弹出层显示出来 vm.fdqxvehcileId(''); vm.fdqxdriver(''); vm.fdqxphone(''); I.closefdModel.modal('show'); }); I.fdqxopenfdBtn.click(function(){ //判断选择了多个只能选择一个 if($('.bitem.info').length>1){ swal({title:'',text:'不能选择多个销售提单同时恢复,请保留一个销售提单!',type:'error',confirmButtonText:'确定'}); return ; } if($('.bitem.info').length<1){ swal({title:'',text:'未选择需要恢复的销售提单,请先选择一个销售提单!',type:'error',confirmButtonText:'确定'}); return ; } var xstdcc=''; $.each($('.bitem.info'), function (index, value) { xstdcc=vm.list()[$(this).attr('data-indx')].td_tdbh; }); //显示出来确认框 $("#modalContent").html('确定要恢复'+xstdcc+'销售提单吗?该销售提单恢复之后,您可以对该销售提单进行分单操作!'); $("#dialog-confirm").removeClass('hide').dialog({ resizable: false, width: '320', modal: true, title: "

确认信息

", title_html: true, position: { my: "center", at: "center", of: window }, buttons: [ { html: "  确定", "class" : "btn btn-danger btn-minier", click: function() { fdqxopenBt(); } } , { html: "  取消", "class" : "btn btn-minier", click: function() { $( this ).dialog( "close" ); } } ] }); }); //关闭分单弹出层--点击确认 I.fdqxclosefdmBtn.click(function(){ var xstdcc=''; $.each($('.bitem.info'), function (index, value) { xstdcc=vm.list()[$(this).attr('data-indx')].td_tdbh; }); $("#modalContent").html('确定要关闭'+xstdcc+'提单吗?关闭该提单之后,您将不能对该提单进行分单操作!'); $("#dialog-confirm").removeClass('hide').dialog({ resizable: false, width: '320', modal: true, title: "

确认信息

", title_html: true, position: { my: "center", at: "center", of: window }, buttons: [ { html: "  确定", "class" : "btn btn-danger btn-minier", click: function() { fdqxcloseBt(); } } , { html: "  取消", "class" : "btn btn-minier", click: function() { $( this ).dialog( "close" ); } } ] }); }); } function doOpen() { var k = $.trim(vm.keyword()); var sort = []; $.each(vm.soList(), function (index, value) { sort.push({ name: value.target, value: value.result() }) }); // console.log("cccc:::"+$('#wcSign').val()); getList(k, vm.companyNo(), vm.type(), $.toJSON(sort), I.sDate.val(), I.eDate.val(), 0, I.PZ, 1); } function doSearch() { doOpen(); } function getList(keyword, companyNo, type, sort, sdate, edate, page, pagesize, pages) { I._page = page; $.post('/business/getList.htm', { keyword: keyword, companyNo: vm.isAdmin() ? companyNo : (typeof(parent.G) != 'undefined' ? parent.G.loginCompanyNo : 'ABCDEFG'), type: type, sort: sort, sdate: sdate, edate: edate, wcSign:$("#wcSign").val(), 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) { // if($('#wcSign').val()==1){ val.indx = index + ''; val.fdqxbgType=vm.fdqxbgType(); val.td_gbsj=val.td_gbsj==null?'':val.td_gbsj; val.td_gbr=val.td_gbr==null?'':val.td_gbr; val.td_gbsl=val.td_gbsl==null?'':val.td_gbsl; val.td_gbzl=val.td_gbzl==null?'':val.td_gbzl; // if(val.td_wfdsl==0){ vm.list.push(val); // } // }else{ // val.indx = index + ''; // if(val.td_wfdsl>0){ // vm.list.push(val); // } // } }); $('.bitem').click(function (e) { $(this).toggleClass('info'); computedSelect(); }); } 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, type, sort, sdate, edate, num - 1, pagesize, 0); }); } } return; } }, 'json'); } 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 doVehicleBind() { I.vehicleBindBtn.prop('disabled', true); var arr = getSelectBiz(); var vehicle = null; var indx = $('.vitem.info').attr('data-indx'); $.each(vm.vList(), function (index, value) { if (value.indx === indx) { vehicle = value; } }); doBindByList(arr, vehicle); } function doTempVehicleBind() { I.tempVehicleBindBtn.prop('disabled', true); var arr = getSelectBiz(); var vehicle = ko.mapping.toJS(vm.o()); doBindByList(arr, 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 doBindByList(list, vehicle) { if (!!I.AjaxdoBindByList) { return; } I.AjaxdoBindByList = true; $.post("/business/doBindByList.htm", {list: $.toJSON(list), vehicle: $.toJSON(vehicle)}, function (data, textStatus, jqXHR) { I.AjaxdoBindByList = false; I.vehicleBindBtn.prop('disabled', false); I.tempVehicleBindBtn.prop('disabled', false); if (data.code >= 1) { swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { showErrmsg('配车成功!'); I.vehicleModal.modal('hide'); I.tempVehicleModal.modal('hide'); return; } }, "json" ); } function doUnbindByList(list) { if (!!I.AjaxdoUnbindByList) { return; } I.AjaxdoUnbindByList = true; I.unbindBtn.prop('disabled', true); $.post("/business/doUnbindByList.htm", {list: $.toJSON(list)}, function (data, textStatus, jqXHR) { I.AjaxdoUnbindByList = false; I.unbindBtn.prop('disabled', false); if (data.code >= 1) { swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { showErrmsg('取消配车成功!'); return; } }, "json" ); } function getSelectBiz() { var arr = []; $.each($('.bitem.info'), function (index, value) { arr.push($(this).attr('data-td_tdbh')); }); return arr; } 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 getVehicleList() { $.post("/business/getVehicleList.htm", { companyNo: vm.isAdmin() ? '' : (typeof(parent.G) != 'undefined' ? parent.G.loginCompanyNo : 'ABCDEFG'), vehicleId:I.vehicleKeyword.val()==undefined?'':I.vehicleKeyword.val(), }, 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 { if(I.VDB!=undefined&&I.VDB!=null && I.VDB.length>0){ $.each(I.VDB, function (index, value) { vm.vList.push(value); }); } // } $('.vitem').click(function (e) { $('.vitem').removeClass('info'); $(this).addClass('info'); }); } 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); }); } 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 validMessage(message, cb, cbparams) { $("#modalContent").html(message); $("#dialog-confirm").removeClass('hide').dialog({ resizable: false, width: '320', modal: true, title: "

确认信息

", title_html: true, position: { my: "center", at: "center", of: window }, buttons: [ { html: "  确定", "class" : "btn btn-danger btn-minier", click: function() { $( this ).dialog( "close" ); cb(cbparams); } } , { html: "  取消", "class" : "btn btn-minier", click: function() { $( this ).dialog( "close" ); } } ] }); } function newTab(item) { parent.closableTab.addTab({ 'id': new Date().getTime(), 'name': item.td_tdbh + '分单', 'url': '/basic/formSplit.jsf?no=' + item.td_tdbh, 'closable': true }); } function newPrintTab(tdNo) { parent.closableTab.addTab({ 'id': tdNo, 'name': '打印', // 'url': encodeURI('http://' + HOSTNAME + ':9088/ReportServer?reportlet=print%2Fprint_fd_xstd.cpt&vehicleId=' + vehicleId), 'url': encodeURI('/task/printtdall.htm?tdNo=' + tdNo), 'closable': true }); } function autoHeight() { $('.page-content').css('min-height', $(parent.window).height() - 117); $('.table-responsive').css('height', $(parent.window).height() - 260); } function clearError() { $('#form input').removeClass('error'); $('#form .text-error').html(''); } //关闭提单操作 function fdqxcloseBt(){ var tdNo=''; $.each($('.bitem.info'), function (index, value) { tdNo=vm.list()[$(this).attr('data-indx')].td_tdbh; }); $.post("/business/closexstd.htm", {vehicleId: vm.fdqxvehcileId(),driver: vm.fdqxdriver(),phone: vm.fdqxphone(),tdNo:tdNo}, function (data, textStatus, jqXHR) { I.VDB = []; if (data.code >= 1) { swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); $("#dialog-confirm").dialog( "close" ); return; } if (data.code == 0) { showErrmsg('关闭分单成功!'); I.closefdModel.modal('hide'); getList($.trim(vm.keyword()), vm.companyNo(), vm.type(), null, I.sDate.val(), I.eDate.val(), 0, I.PZ, 1); $("#dialog-confirm").dialog( "close" ); return; } }, "json" ); } //打开提单操作 function fdqxopenBt(){ var tdNo=''; $.each($('.bitem.info'), function (index, value) { tdNo=vm.list()[$(this).attr('data-indx')].td_tdbh; }); $.post("/business/openxstd.htm", {tdNo:tdNo}, function (data, textStatus, jqXHR) { I.VDB = []; if (data.code >= 1) { swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); $("#dialog-confirm").dialog( "close" ); return; } if (data.code == 0) { showErrmsg('恢复分单成功!'); getList($.trim(vm.keyword()), vm.companyNo(), vm.type(), null, I.sDate.val(), I.eDate.val(), 0, I.PZ, 1); $("#dialog-confirm").dialog( "close" ); return; } }, "json" ); } //获取物流公司可操作的厂区 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)) { var tmp ;var ind=0; var list=[]; $.each(data.list, function(index, val) { if (val.cqval=='' ) { ind = 1; } if (val.cqval == '103' || val.name == '科技厂区') { tmp = val;return; } list.push(val); }); if (tmp){ list.splice(ind, 0, tmp) } vm.cqList.push(...list) } } }, 'json'); }