You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/js/WmsFeeCodeEdit.js

617 lines
20 KiB
JavaScript

2 years ago
var commonGridObj_fee;
var addCount = 0;
var pressRecord;
function $(id){
return document.getElementById(id);
}
function refreshList(){
createGrid();
}
function createGrid(){
//header
var headerArgs_fee = new Array("","单价","备注","创建人","创建时间");
//width
var widthArgs_fee= new Array("40","100","100","100","100");
//column align
var colAlignArgs_fee = new Array("center","center","center","center","center");
//column sort
var colSortArgs_fee = new Array("na","str","str","str","str");
//column type
var colTypeArgs_fee = new Array("ch","ed","ed","ro","ro");
commonGridObj_fee = new TGridCommon("mygrid_container_fee","form1",headerArgs_fee,widthArgs_fee,colAlignArgs_fee,colSortArgs_fee,colTypeArgs_fee);
commonGridObj_fee.setResponseUrl("../SeaiFee/WmsRateGridSource.aspx");
var templateID = $("h_templateid").value;
commonGridObj_fee.setRequest("../SeaiFee/WmsRateGridSource.aspx?handle=wmsfeecodelist&show_page=15&cur_page=1&bsno="+escape($("h_bsno").value)+"&uid="+commonGridObj_fee.newGuid());
commonGridObj_fee.setSourceType("json");
commonGridObj_fee.setSkin("xp");
commonGridObj_fee.setImageUrl("../images/");
commonGridObj_fee.initGrid();
commonGridObj_fee.bind();
// commonGridObj_fee.initPageByGID("wmsfeecodelist","&cus="+$("h_cusname").value);
commonGridObj_fee.getGridObj().enableEditEvents(true,false,true);
commonGridObj_fee.getGridObj().enableKeyboardSupport(true);
var pushVal = "";
var pressRecord = "";
var pressRowIndex = -1;
var pressCellIndex = -1;
var pressCount = 0;
var isExchange = false;
var shiftCount = 0;
var isDelete = 0;
var flagFilter = 0;
var flagTab = 0;
var flagEnter = 0;
var flagDelete = 0;
//手动编写Grid控件编辑事件,由于免费控件没有提供完整的编辑判断功能,现特此做更改
commonGridObj_fee.getGridObj().attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){
var newCheckValue = false;
//初始化状态
if(stage == 0){
return true;
}
var txtEdit;
if(stage == 1){
for(i = 0; i < document.all.length; i++){
if(document.all(i).tagName == "TEXTAREA"){
txtEdit = document.all(i);
txtEdit.focus();
txtEdit.select();
break;
}
}
}
//如果编辑结束
if(stage == 2){
if(oValue==null || oValue=="" || oValue=="0"){
return true;
}
if( cInd == 1 ){
commonGridObj_fee.getGridObj().cellById(rId,cInd).setValue(nValue);
}
else if(cInd==2)
{
commonGridObj_fee.getGridObj().cellById(rId,cInd).setValue(nValue);
}
}
});//end onEditCell
//键盘操作事件+
commonGridObj_fee.getGridObj().attachEvent("onKeyPress", function(code,cFlag,sFlag){
//onKeyPress begin
//获取当前RowID
var selectedId = commonGridObj_fee.getGridObj().getSelectedRowId();
//获取当前RowIndex
var rowIndex = commonGridObj_fee.getGridObj().getRowIndex(selectedId);
//获取当前CellIndex(ind)
var ind = commonGridObj_fee.getGridObj().getSelectedCellIndex();
//触发操作事件前获取单元值
var oldVal = commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).getValue();
//获取编辑单元
var txtEdit;
for(i = 0; i < document.all.length; i++){
if(document.all(i).tagName == "TEXTAREA"){
txtEdit = document.all(i);
break;
}
}
//enter 键
if(code == 13){
if(ind == 1 || ind == 2 ){
if(ind==1){
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).setValue(oldVal);
}else if(ind==2){
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).setValue(oldVal);
}
return true;
}
}//enter 键 end
//Tab键
if(code == 9){
//code9 begin
setTimeout(function(){
if(ind==1){
commonGridObj_fee.getGridObj().editStop(true);
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).setValue(oldVal);
commonGridObj_fee.getGridObj().selectCell(rowIndex,2,true,true);
commonGridObj_fee.getGridObj().editCell();
}
else if(ind==2){
commonGridObj_fee.getGridObj().editStop(true);
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).setValue(oldVal);
commonGridObj_fee.getGridObj().selectCell(rowIndex,1,true,true);
commonGridObj_fee.getGridObj().editCell();
}
},150);
} //cdoe9 end
//左箭头
if(code == 37){
//code37 begin
setTimeout(function(){
if(ind == 1){
commonGridObj_fee.getGridObj().editStop(true);
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).setValue(oldVal);
commonGridObj_fee.getGridObj().selectCell(rowIndex,2,true,true);
commonGridObj_fee.getGridObj().editCell();
}
else if(ind == 2){
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).setValue(oldVal);
commonGridObj_fee.getGridObj().selectCell(rowIndex,1,true,true);
commonGridObj_fee.getGridObj().editCell();
}
},150);
}//code37 end
//右箭头
if(code == 39){
//code39 begin
setTimeout(function(){
if(ind == 1){
commonGridObj_fee.getGridObj().editStop(true);
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).setValue(oldVal);
commonGridObj_fee.getGridObj().selectCell(rowIndex,2,true,true);
commonGridObj_fee.getGridObj().editCell();
}
else if(ind == 2){
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).setValue(oldVal);
commonGridObj_fee.getGridObj().selectCell(rowIndex,1,true,true);
commonGridObj_fee.getGridObj().editCell();
}
},150);
}//code39 end
//键盘输入数字
if(code >= 48 && code <= 57|| code >= 96 && code <= 105 || code == 188|| code == 110|| code == 190 || code == 229){
if( ind == 1 || ind == 2){
return true;
}
}
if (code >= 65 && code <= 90) {//如果是输入英文字符
if( ind == 1 || ind==2 ){
return true;
}
}
if(code == 8){
//code8 begin
if(ind == 1 || ind == 2 ){
var start=0;
var end=0;
if(document.selection){
var range = document.selection.createRange();
if(range.parentElement().className == txtEdit.className){
var range_all = document.body.createTextRange();
range_all.moveToElementText(txtEdit);
for (start=0; range_all.compareEndPoints("StartToStart", range) < 0; start++){
range_all.moveStart('character', 1);
}
for (var i = 0; i <= start; i ++){
if (txtEdit.value.charAt(i) == '\n')
start++;
}
var range_all = document.body.createTextRange();
range_all.moveToElementText(txtEdit);
for (end = 0; range_all.compareEndPoints('StartToEnd', range) < 0; end ++)
range_all.moveStart('character', 1);
for (var i = 0; i <= end; i ++){
if (txtEdit.value.charAt(i) == '\n')
end ++;
}
}
}
// alert(start);alert(end);
//未选中多个字符
if(start == end){
if(start != 0){
if(pressRecord!=null){
var firstVal = pressRecord.substring(0,start - 1);
var endVal = pressRecord.substring(start + 1,txtEdit.value.length - 1);
pressRecord = firstVal;
}
}
}
//选中多个字符
if(start != end){
if(pressRecord!=null){
var firstVal = pressRecord.substring(0,start);
var endVal = pressRecord.substring(end - 1,txtEdit.value.length - 1);
pressRecord = firstVal+endVal;
}
}
setTimeout(function(){
if(pressRecord!=null){
if(pressRecord.trim().length > 0){
var combo = commonGridObj_fee.getCustomCombo(selectedId,ind);
var comboArg = combo.getKeys();
var count = 0;
for(var i = 0;i<comboArg.length;i++){
if(combo.get(comboArg[i]).toUpperCase().trim().indexOf(pressRecord) == 0){
count++;
var oldVal = comboArg[i];
var oldLab = combo.get(comboArg[i]);
pressCount = 3;
commonGridObj_fee.editStop(true);
commonGridObj_fee.cellByIndex(rowIndex,ind).setValue(oldVal);
commonGridObj_fee.selectCell(rowIndex,ind,true,true);
commonGridObj_fee.editCell();
var old_length = oldLab.length;
for(i = 0; i < document.all.length; i++){
if(document.all(i).tagName == "TEXTAREA"){
txtEdit = document.all(i);
var rt = txtEdit.createTextRange();
rt.collapse();
rt.select();//光标置最前
var r = document.selection.createRange();
r.collapse(false);
r.moveStart("character", pressRecord.length);//从m位开始
r.moveEnd("character", old_length);//选取n位
//txtEdit.focus();
r.select();
}
}
break;
}
}
}}
},500);
return true;
}else{
return true;
}
//code8 end
}
});
} //end createGrid()
//添加费用
function addFee(){
if(commonGridObj_fee != null){
var newRowID = commonGridObj_fee.newGuid();
commonGridObj_fee.getGridObj().addRow(newRowID,["0","","",""],commonGridObj_fee.getGridObj().getRowsNum());
commonGridObj_fee.getGridObj().clearSelection();
addCount++;
setTimeout(function(){
commonGridObj_fee.getGridObj().editStop(true);
commonGridObj_fee.getGridObj().selectCell(commonGridObj_fee.getGridObj().getRowIndex(newRowID),1,true,true);
commonGridObj_fee.getGridObj().editCell();
},150);
}
}
function setCurrencyCombo(obj){
var url = "../FeeCodes/CurrencyAdapter.aspx?handle=drate&uid="+commonGridObj_fee.newGuid();
var loader = dhtmlxAjax.getSync(url);
var currencyInfo = loader.xmlDoc.responseText;
var jsonCacheObj = eval('(' + currencyInfo + ')');
if(jsonCacheObj.drate.length > 0){
for(var i = 0;i < jsonCacheObj.drate.length;i++){
obj.put(jsonCacheObj.drate[i].code,jsonCacheObj.drate[i].code);
}
}
}
function setFeeLbCombo(obj){//FeeLbCombo
obj.put("收费","收费");
obj.put("付费","付费");
}
function setCustomerCombo(obj){
var customerInfo = "";
if($("h_custcache").value.trim() != ""){
customerInfo = $("h_custcache").value.trim();
}else{
var url = "../FeeCodes/CRMClientInfo.aspx?handle=client&uid="+newGuid();
var loader = dhtmlxAjax.getSync(url);
customerInfo = loader.xmlDoc.responseText;
}
var jsonCacheObj = eval('(' + customerInfo + ')');
if(jsonCacheObj.customer.length > 0){
for(var i = 0;i < jsonCacheObj.customer.length;i++){
obj.put(jsonCacheObj.customer[i].name,jsonCacheObj.customer[i].code + ' '+jsonCacheObj.customer[i].name);
}
}
}
function setFeeNameCombo(obj){
var feeCodeInfo = "";
if($("h_feenamecache").value.trim() != ""){
feeCodeInfo = $("h_feenamecache").value.trim();
}else{
var url = "../FeeCodes/FeeCodeService.aspx?handle=feecode&uid="+newGuid();
var loader = dhtmlxAjax.getSync(url);
feeCodeInfo = loader.xmlDoc.responseText;
}
var jsonCacheObj = eval('(' + feeCodeInfo + ')');
if(jsonCacheObj.feecode.length > 0){
for(var i = 0;i < jsonCacheObj.feecode.length;i++){
obj.put(jsonCacheObj.feecode[i].name,jsonCacheObj.feecode[i].code);
}
}
}
function setUnitCombo(obj) {
obj.put("单票", "单票");
obj.put("重量", "重量");
//obj.put("净重", "净重");
obj.put("尺码", "尺码");
obj.put("TEU", "TEU");
obj.put("箱型", "箱型");
obj.put("CBM", "CBM");
obj.put("BILL", "BILL");
var feeCodeCtnObj = null;
var url = "../FeeCodes/FeeCodeCtnService.aspx?handle=getallctn&uid="+commonGridObj_fee.newGuid();
var loader = dhtmlxAjax.getSync(url);
var ctnInfo = loader.xmlDoc.responseText;
if(ctnInfo.trim() != ""){
feeCodeCtnObj = eval('(' + ctnInfo + ')');
if(feeCodeCtnObj.ctns.length > 0){
for(var i=0;i<feeCodeCtnObj.ctns.length;i++){
if(feeCodeCtnObj.ctns[i].name.trim() != ""){
obj.put(feeCodeCtnObj.ctns[i].name,feeCodeCtnObj.ctns[i].name);
}
}
}
}
}
function setClientCombo(obj){
obj.put("船公司","船公司");
obj.put("订舱代理","订舱代理");
obj.put("场站","场站");
obj.put("车队","车队");
obj.put("委托单位","委托单位");
obj.put("报关行","报关行");
obj.put("代理","代理");
obj.put("航空公司","航空公司");
obj.put("发货人","发货人");
obj.put("收货人","收货人");
obj.put("通知人","通知人");
obj.put("船代","船代");
obj.put("码头","码头");
obj.put("其他","其他");
}
function isObjNaN(Obj){
if(Obj.toString().toLowerCase() == "nan"){
return 0;
}else{
return Obj;
}
}
function clearNoNum(valObj)
{
//先把非数字的都替换掉,除了数字和.
valObj = valObj.replace(/[^\d.]/g,"");
//必须保证第一个为数字而不是.
valObj = valObj.replace(/^\./g,"");
//保证只有出现一个.而没有多个.
valObj = valObj.replace(/\.{2,}/g,".");
//保证.只出现一次,而不能出现两次以上
valObj = valObj.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
return valObj;
}
function ConvertToMoney(strObj){
var result = strObj.replace(",","");
return result;
}
function saveFee(){
if(commonGridObj_fee != null){
if(commonGridObj_fee.getGridObj().getRowsNum() > 0){
var jsonCacheObj = null;
for(var i=0;i<commonGridObj_fee.getGridObj().getRowsNum();i++){
var gID = commonGridObj_fee.getGridObj().getRowId(i);
var bsno=$("h_bsno").value;
// var fname = commonGridObj_fee.getGridObj().cellByIndex(i,2).getValue();
// var Feetype =commonGridObj_fee.getGridObj().cellByIndex(i,1).getValue();
// var unit = commonGridObj_fee.getGridObj().cellByIndex(i,3).getValue();
var price = commonGridObj_fee.getGridObj().cellByIndex(i,1).getValue() == ""?0:clearNoNum(isObjNaN(ConvertToMoney(commonGridObj_fee.getGridObj().cellByIndex(i,1).getValue())));
// var currency = commonGridObj_fee.getGridObj().cellByIndex(i,5).getValue();
// var exchange = commonGridObj_fee.getGridObj().cellByIndex(i,6).getValue() == ""?0:clearNoNum(isObjNaN(ConvertToMoney(commonGridObj_fee.getGridObj().cellByIndex(i,6).getValue())));
var remark = commonGridObj_fee.getGridObj().cellByIndex(i,2).getValue();
if(i == 0){
var result = "";
var cacheBuffer = "";
result += "{\"caches\":[";
cacheBuffer += "{";
cacheBuffer += "\"id\":\""+gID+"\",";
// cacheBuffer += "\"type\":\""+Feetype+"\",";
// cacheBuffer += "\"fname\":\""+fname+"\",";
cacheBuffer += "\"bsno\":\""+bsno+"\",";
// cacheBuffer += "\"unit\":\""+unit+"\",";
cacheBuffer += "\"price\":"+price+",";
// cacheBuffer += "\"cur\":\""+currency+"\",";
// cacheBuffer += "\"exchange\":"+exchange+",";
cacheBuffer += "\"remark\":\""+remark+"\"";
cacheBuffer += "}"
result += cacheBuffer;
result += "]}";
jsonCacheObj = eval('(' + result + ')');
}else{
var newCache = jsonCacheObj.caches;
newCache = {id:gID,bsno:bsno,price:price,remark:remark};
jsonCacheObj.caches.push(newCache);
}
}
$("h_feecache").value = JSON.stringify(jsonCacheObj);
postEnterFee();
}else{
postEnterFee();
}
}
}
function saveTemplate(iState){
addCount=0;
$("h_post").value = 1;
saveFee();
}
function postEnterFee(){
var myForm = document.getElementById("form1");
myForm.submit() ;
}
function outputMoney(number) {
number= number.replace(/\,/g,"");
if (isNaN(number)||number=="") return "";
number = Math.round( number*100) /100;
if(number<0)
return '-'+outputDollars(Math.floor(Math.abs(number)-0) + '') + outputCents(Math.abs(number) - 0);
else
return outputDollars(Math.floor(number-0) + '') + outputCents(number - 0);
}
function outputDollars(number)
{
if (number.length<= 3)
return (number == '' ? '0' : number);
else
{
var mod = number.length%3;
var output = (mod == 0 ? '' : (number.substring(0,mod)));
for (i=0 ; i< Math.floor(number.length/3) ; i++)
{
if ((mod ==0) && (i ==0))
output+= number.substring(mod+3*i,mod+3*i+3);
else
output+= ',' + number.substring(mod+3*i,mod+3*i+3);
}
return (output);
}
}
function outputCents(amount)
{
amount = Math.round( ( (amount) - Math.floor(amount) ) *100);
return (amount<10 ? '.0' + amount : '.' + amount);
}
function deleteFee(){
var iCount = 0;
var iDelCount = 0;
var iFailure = 0;
if(commonGridObj_fee != null){
for(var i=0;i<commonGridObj_fee.getGridObj().getRowsNum();i++){
var gID = commonGridObj_fee.getGridObj().getRowId(i);
var isCheckState = commonGridObj_fee.getGridObj().cellByIndex(i,0).getValue();
var createname=commonGridObj_fee.getGridObj().cellByIndex(i,3).getValue();
if(isCheckState == 1){
if(createname!=""){
var url = "../SeaiFee/WmsRateGridSource.aspx?handle=deleteWmsFeeCode&gid="+gID+"&uid="+commonGridObj_fee.newGuid();
var loader = dhtmlxAjax.getSync(url);
var deleteState = parseInt(loader.xmlDoc.responseText);
if(deleteState == 1){
iDelCount++;
addCount--;
}
else{
iFailure++;
}
}
else
{
commonGridObj_fee.getGridObj().deleteRow(gID);
iDelCount++;
addCount--;
}
iCount++;
}
}
if (iCount>0){
alert("提交费率删除 "+iCount+" 条 成功 "+iDelCount+" 条 失败 "+iFailure+" 条");
}
}
createGrid();
}
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,""); }
function initDownFeeName(){
var url = "../FeeCodes/FeeCodeService.aspx?handle=feecode&uid="+newGuid();
var loader = dhtmlxAjax.getSync(url);
var feeCodeInfo = loader.xmlDoc.responseText;
//var jsonCacheObj = eval('(' + feeCodeInfo + ')');
if($("h_feenamecache").value.trim() == ""){
$("h_feenamecache").value = feeCodeInfo;
}
var url = "../FeeCodes/CRMClientInfo.aspx?handle=client&uid="+newGuid();
var loader = dhtmlxAjax.getSync(url);
var customerInfo = loader.xmlDoc.responseText;
if($("h_custcache").value.trim() == ""){
$("h_custcache").value = customerInfo;
}
}
//获取GUID
function newGuid()
{
var guid = "";
for (var i = 1; i <= 32; i++){
var n = Math.floor(Math.random()*16.0).toString(16);
guid += n;
if((i==8)||(i==12)||(i==16)||(i==20))
guid += "-";
}
return guid.toUpperCase();
}