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.
HENGCHENG/DSWeb/js/jsGridCodeFeeTemplateSetEdi...

943 lines
35 KiB
JavaScript

var commonGridObj_fee;
var addCount = 0;
function $(id){
return document.getElementById(id);
}
//全选框
function checkall() {
var checkStatus = $("ck_all").checked;
if (checkStatus == 1) {
var iCount = mygrid_log.getRowsNum();
for (var i = 0; i < iCount; i++) {
mygrid_log.cellByIndex(i, 0).setValue(1);
}
}
else {
var iCount = mygrid_log.getRowsNum();
for (var i = 0; i < iCount; i++) {
mygrid_log.cellByIndex(i, 0).setValue(0);
}
}
}
function createGrid(){
//header
var headerArgs_fee = new Array("<input type=\"checkbox\" id=\"ck_all\" onclick=\"checkall()\"/>", "费用名称", "结算对象类型", "客户名称", "标准", "单价", "币别", "汇率", "备注", "序号");
//width
var widthArgs_fee= new Array("30","150","100","100","100","120","120","120","120","0");
//column align
var colAlignArgs_fee = new Array("center","center","center","center","center","center","center","center","center","center");
//column sort
var colSortArgs_fee = new Array("na","str","str","str","str","str","str","str","str","str");
//column type
var colTypeArgs_fee = new Array("ch","co","co","co","co","ed","co","co","txt","ro");
commonGridObj_fee = new TGridCommon("mygrid_container_fee","form1",headerArgs_fee,widthArgs_fee,colAlignArgs_fee,colSortArgs_fee,colTypeArgs_fee);
commonGridObj_fee.setResponseUrl("CodeFeeTemplateSetGridSource.aspx");
var templateID = $("h_templateid").value;
commonGridObj_fee.setRequest("CodeFeeTemplateSetGridSource.aspx?handle=detaillist&show_page=15&cur_page=1&id=" + templateID + "&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("detaillist","&id="+templateID);
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;
// for(var i=0;i<commonGridObj_fee.getGridObj().getRowsNum();i++){}
commonGridObj_fee.getGridObj().attachEvent("onSelectStateChanged", function(id){
var rId = id;
var combo_feename;
combo_feename = commonGridObj_fee.getGridObj().getCustomCombo(rId,1);
setFeeNameCombo(combo_feename);
var combo_clientname;
combo_clientname = commonGridObj_fee.getGridObj().getCustomCombo(rId,2);
setClientCombo(combo_clientname);
var combo_cust;
combo_cust = commonGridObj_fee.getGridObj().getCustomCombo(rId,3);
setCustomerCombo(combo_cust);
var combo_unit;
combo_unit = commonGridObj_fee.getGridObj().getCustomCombo(rId,4);
setUnitCombo(combo_unit);
var combo_currency;
combo_currency = commonGridObj_fee.getGridObj().getCustomCombo(rId,6);
setCurrencyCombo(combo_currency);
});
//手动编写Grid控件编辑事件,由于免费控件没有提供完整的编辑判断功能,现特此做更改
commonGridObj_fee.getGridObj().attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){
var newCheckValue = false;
//初始化状态
if(stage == 0){
if(cInd == 0){
return true;
}
}
if(stage == 1){
var selectedId = commonGridObj_fee.getGridObj().getSelectedRowId();
var rowIndex = commonGridObj_fee.getGridObj().getRowIndex(selectedId);
var txtEdit
for(i = 0; i < document.all.length; i++){
if(document.all(i).tagName == "TEXTAREA"){
txtEdit = document.all(i);
txtEdit.focus();
txtEdit.select();
break;
}
}
if(cInd == 1 || cInd == 2){
if(flagFilter == 0){
//alert(txtEdit.value);
}
}
}
//如果编辑结束
if(stage == 2){
if(cInd == 5){
var rowIndex = commonGridObj_fee.getGridObj().getRowIndex(rId);
var unitPrice = clearNoNum(isObjNaN(ConvertToMoney(commonGridObj_fee.getGridObj().cellByIndex(rowIndex,5).getValue())));
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,5).setValue(outputMoney(unitPrice.toString()));
return true;
}
else if(cInd == 1 || cInd == 3)
{
var rowIndex = commonGridObj_fee.getGridObj().getRowIndex(rId);
if(pressCount == 1)
{
if(flagFilter == 1)
{
//commonGridObj_fee.getGridObj().editStop();
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setLabel(oValue);
return true;
}
else
{
var cellVal = commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).getValue();
var combo = commonGridObj_fee.getGridObj().getCustomCombo(rId,cInd);
var comboArg = combo.getKeys();
var tempCount = 0;
if(cellVal.indexOf(" ") >0 && cellVal.indexOf(" ") < cellVal.length){
cellVal = cellVal.substring(0,cellVal.indexOf(" "));
for(var i = 0;i<comboArg.length;i++){
//if(combo.get(comboArg[i]).trim().indexOf(cellVal) == 0){
if (combo.get(comboArg[i]).trim() == cellVal) {
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setValue(comboArg[i]);
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setLabel(comboArg[i]);
tempCount++;
break;
}
}
}else{
for(var i = 0;i<comboArg.length;i++){
//if(combo.get(comboArg[i]).trim().indexOf(cellVal) > 0){
if (combo.get(comboArg[i]).trim() == cellVal) {
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setValue(comboArg[i]);
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setLabel(comboArg[i]);
tempCount++;
break;
}
}
}//alert(tempCount)
if(tempCount == 0){
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setValue("");
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setLabel("");
}
isExchange = false;
pressRecord = "";
pressRowIndex = -1;
pressCellIndex = -1;
pressCount = 0;
flagFilter = 0;
return true;
}
}
else if(pressCount == 2)
{
if(flagFilter == 1)
{
commonGridObj_fee.getGridObj().editStop();
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setLabel(oValue);
}
else
{
if(pressRowIndex != rowIndex && pressCellIndex != cInd)
{
return true;
}
else
{
isExchange = false;
pressRecord = "";
pressRowIndex = -1;
pressCellIndex = -1;
pressCount = 0;
flagFilter = 0;
var cellVal = commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).getValue();
var combo = commonGridObj_fee.getGridObj().getCustomCombo(rId,cInd);
var comboArg = combo.getKeys();
var tempCount = 0;
if(cellVal.indexOf(" ") >0 && cellVal.indexOf(" ") < cellVal.length){
cellVal = cellVal.substring(0,cellVal.indexOf(" "));
for(var i = 0;i<comboArg.length;i++){
//if(combo.get(comboArg[i]).trim().indexOf(cellVal) == 0){
if (combo.get(comboArg[i]).trim() == cellVal) {
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setValue(comboArg[i]);
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setLabel(comboArg[i]);
tempCount++;
break;
}
}
}
if(tempCount == 0){
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setValue("");
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setLabel("");
}
return true;
}
}
}
else
{
var cellVal = commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).getValue();
var combo = commonGridObj_fee.getGridObj().getCustomCombo(rId,cInd);
var comboArg = combo.getKeys();
if(cellVal.indexOf(" ") >0 && cellVal.indexOf(" ") < cellVal.length)
{
cellVal = cellVal.substring(0,cellVal.indexOf(" "));
for(var i = 0;i<comboArg.length;i++)
{
//if(combo.get(comboArg[i]).trim().indexOf(cellVal) == 0){
if (combo.get(comboArg[i]).trim() == cellVal) {
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setValue(comboArg[i]);
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setLabel(comboArg[i]);
break;
}
}
}
else
{
for(var i = 0;i<comboArg.length;i++)
{
//if(combo.get(comboArg[i]).trim().indexOf(cellVal) > 0){
if (combo.get(comboArg[i]).trim() == cellVal) {
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setValue(comboArg[i]);
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,cInd).setLabel(comboArg[i]);
break;
}
}
}
return true;
}
}
else
{
return true;
}
}
});
//键盘操作事件
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;
}
}
if(code == 13){
if (ind == 1 || ind == 2 || ind == 3 || ind == 4 || ind == 6) {
//如果是检索失败,
if(pressCount == 2){
commonGridObj_fee.getGridObj().editStop();
//将value写入cell(触发 stage2)
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).setValue(oldVal);
//重新打开cell(触发stage0 stage1)
commonGridObj_fee.getGridObj().selectCell(rowIndex,ind,true,true);
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).setLabel(oldVal);
commonGridObj_fee.getGridObj().editCell();
return true;
}else{
}
return true;
}else{
return true;
}
}
//Tab键
if(code == 9){
//code9 begin
var colCount = commonGridObj_fee.getGridObj().getColumnsNum();
var rowCount = commonGridObj_fee.getGridObj().getRowsNum();
if(ind < colCount){
isExchange = false;
pressRecord = "";
pressRowIndex = -1;
pressCellIndex = -1;
commonGridObj_fee.getGridObj().editStop(true);
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).setLabel(oldVal);
var cInd = ind;
var rId = selectedId;
commonGridObj_fee.getGridObj().selectCell(rowIndex,ind+1,true,true);
commonGridObj_fee.getGridObj().editCell();
if(ind == colCount - 2){
if(rowIndex < rowCount){
commonGridObj_fee.getGridObj().editStop(true);
commonGridObj_fee.getGridObj().clearSelection();
commonGridObj_fee.getGridObj().selectCell(rowIndex+1,1,true,true);
commonGridObj_fee.getGridObj().editCell();
}else{
return;
}
}
}
//cdoe9 end
}
if ((code >= 65 && code <= 90) || (code >= 48 && code <= 57) || (code >= 96 && code <= 105)) {//如果是输入英文字符
if (ind == 1 || ind == 2 || ind == 3 || ind == 4 || ind == 6) {
//获取键盘输入字符
var pressVal = String.fromCharCode(code);
var start=0;
var end=0;
if(document.selection){
var range = document.selection.createRange();
if(range.parentElement().className == txtEdit.className){
// create a selection of the whole textarea
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 ++;
}
}
}
//如果是当前检索位置
if(rowIndex == pressRowIndex && ind == pressCellIndex){
//未选中多个字符
if(start == end){
if(start != pressRecord.length){
if(start != 0){
var firstVal = pressRecord.substring(0,start - 1);
var endVal = pressRecord.substring(start + 1,txtEdit.value.length - 1);
// alert(firstVal);alert(endVal);
pressRecord = firstVal+pressVal+endVal;
}
}else{
pressRecord = pressRecord+pressVal;
}
}
//选中多个字符
if(start != end){
var firstVal = pressRecord.substring(0,start);
var endVal = pressRecord.substring(end - 1,txtEdit.value.length - 1);
// alert(firstVal);alert(endVal);
pressRecord = firstVal+pressVal+endVal;
}
}else{
pressRecord = pressVal;
pressRowIndex = rowIndex;
pressCellIndex = ind;
}
// alert(pressRecord);alert(start);alert(end);alert(txtEdit.value);
//获取combo下拉列表
var combo = commonGridObj_fee.getGridObj().getCustomCombo(selectedId,ind);
var comboArg = combo.getKeys();
var count = 0;
//开始遍历检索
//如果检索成功 状态pressCount=1 如果不成功应为pressCount=2
for(var i = 0;i<comboArg.length;i++){
if(combo.get(comboArg[i]).toUpperCase().trim().indexOf(pressRecord) == 0){
//计数
count++;
//获取value
var oldVal = comboArg[i];
//获取label
var oldLab = combo.get(comboArg[i]);
//记录状态值 检索到数据项
pressCount = 1;
flagFilter = 1;
//关闭编辑
commonGridObj_fee.getGridObj().editStop();
//将value写入cell(触发 stage2)
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).setValue(oldVal);
flagFilter = 0;
//重新打开cell(触发stage0 stage1)
commonGridObj_fee.getGridObj().selectCell(rowIndex,ind,true,true);
commonGridObj_fee.getGridObj().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位
r.select();
break;
}
}
break;
}
}
//如果检索不能成功 pressCount=2
if(count == 0){
pressCount = 2;
txtEdit.value = pressRecord;
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(true);
r.moveStart("character", pressRecord.length);//从m位开始
r.moveEnd("character", pressRecord.length);//选取n位
r.select();
break;
}
}
}
}
}
//delete
if(code == 8){
//code8 begin
if (ind == 1 || ind == 2 || ind == 3 || ind == 4 || ind == 6) {
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){
var firstVal = pressRecord.substring(0,start - 1);
var endVal = pressRecord.substring(start + 1,txtEdit.value.length - 1);
pressRecord = firstVal;
// alert(firstVal);alert(endVal);alert(pressRecord);
}
}
//选中多个字符
if(start != end){
var firstVal = pressRecord.substring(0,start);
var endVal = pressRecord.substring(end - 1,txtEdit.value.length - 1);
pressRecord = firstVal+endVal;
}
setTimeout(function(){
if(pressRecord.trim().length > 0){
var combo = commonGridObj_fee.getGridObj().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.getGridObj().editStop();
commonGridObj_fee.getGridObj().cellByIndex(rowIndex,ind).setValue(oldVal);
commonGridObj_fee.getGridObj().selectCell(rowIndex,ind,true,true);
commonGridObj_fee.getGridObj().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
}
//向下方向键
if(code == 40){
//code40 begin
if(ind == 5 || ind == 7|| ind == 8){
var rowCount = commonGridObj_fee.getGridObj().getRowsNum();
commonGridObj_fee.getGridObj().clearSelection();
commonGridObj_fee.getGridObj().editStop();
if(rowIndex == (rowCount - 1)){
addFee();
}else{
commonGridObj_fee.getGridObj().selectCell(rowIndex+1,1,true,true);
commonGridObj_fee.getGridObj().editCell();
}
}else{
pressCount = 0;
return true;
}
//code40 end
}
//向上箭头
if(code == 38){
//code38 begin
if (ind == 5 || ind == 7 || ind == 8) {
if(rowIndex > 0){
commonGridObj_fee.getGridObj().clearSelection();
commonGridObj_fee.getGridObj().editStop();
commonGridObj_fee.getGridObj().selectCell(rowIndex-1,1,true,true);
commonGridObj_fee.getGridObj().editCell();
}
}else{
pressCount = 0;
return true;
}
//code38 end
}
//键盘输入数字
if(code >= 48 && code <= 57|| code >= 96 && code <= 105 || code == 188|| code == 110|| code == 190){
if( ind == 1 || ind == 2|| ind == 3 || ind == 4 || ind == 5|| ind == 6 || ind == 7 || ind == 8 || ind == 9){
return true;
}
}
//onKeyPress end
});
}
//添加费用
function addFee(){
if(commonGridObj_fee != null){
var newRowID = commonGridObj_fee.newGuid();
var rowIndex = commonGridObj_fee.getGridObj().getRowIndex(newRowID);
var sort = rowIndex + 1;
commonGridObj_fee.getGridObj().addRow(newRowID, ["0", "", "", "", "", "", "", "", "", sort], commonGridObj_fee.getGridObj().getRowsNum());
var combo_cust;
var combo_feename;
var combo_clientname;
combo_feename = commonGridObj_fee.getGridObj().getCustomCombo(newRowID,1);
combo_cust = commonGridObj_fee.getGridObj().getCustomCombo(newRowID,3);
combo_client = commonGridObj_fee.getGridObj().getCustomCombo(newRowID,2);
combo_unit = commonGridObj_fee.getGridObj().getCustomCombo(newRowID,4);
combo_currency = commonGridObj_fee.getGridObj().getCustomCombo(newRowID,6);
setFeeNameCombo(combo_feename);
setCustomerCombo(combo_cust);
setUnitCombo(combo_unit);
setCurrencyCombo(combo_currency);
setClientCombo(combo_client);
addCount++;
}
}
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 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 rowIndex = commonGridObj_fee.getGridObj().getRowIndex(gID);
var feeType = $("sel_feetype").value;
var feeName = commonGridObj_fee.getGridObj().cellByIndex(rowIndex,1).getValue();
var customerName = commonGridObj_fee.getGridObj().cellByIndex(rowIndex,3).getValue();
var clientName = commonGridObj_fee.getGridObj().cellByIndex(rowIndex,2).getValue();
var unit = commonGridObj_fee.getGridObj().cellByIndex(rowIndex,4).getValue();
var unitPrice = commonGridObj_fee.getGridObj().cellByIndex(rowIndex,5).getValue() == ""?0:clearNoNum(isObjNaN(ConvertToMoney(commonGridObj_fee.getGridObj().cellByIndex(rowIndex,5).getValue())));
var currency = commonGridObj_fee.getGridObj().cellByIndex(rowIndex,6).getValue();
var exchange = commonGridObj_fee.getGridObj().cellByIndex(rowIndex,7).getValue() == ""?0:clearNoNum(isObjNaN(ConvertToMoney(commonGridObj_fee.getGridObj().cellByIndex(rowIndex,7).getValue())));
var remark = commonGridObj_fee.getGridObj().cellByIndex(rowIndex, 8).getValue();
var sort = rowIndex + 1;// commonGridObj_fee.getGridObj().cellByIndex(rowIndex, 9).getValue();
if(i == 0){
var result = "";
var cacheBuffer = "";
result += "{\"caches\":[";
cacheBuffer += "{";
cacheBuffer += "\"id\":\""+gID+"\",";
cacheBuffer += "\"type\":"+feeType+",";
cacheBuffer += "\"fname\":\""+feeName+"\",";
cacheBuffer += "\"cust\":\""+customerName+"\",";
cacheBuffer += "\"client\":\""+clientName+"\",";
cacheBuffer += "\"unit\":\""+unit+"\",";
cacheBuffer += "\"price\":" + unitPrice + ",";
cacheBuffer += "\"cur\":\"" + currency + "\",";
cacheBuffer += "\"exchange\":" + exchange + ",";
cacheBuffer += "\"remark\":\"" + remark + "\",";
cacheBuffer += "\"sort\":\"" + sort + "\"";
cacheBuffer += "}"
result += cacheBuffer;
result += "]}";
jsonCacheObj = eval('(' + result + ')');
}else{
var newCache = jsonCacheObj.caches;
newCache = { id: gID, type: feeType, fname: feeName, cust: customerName, client: clientName, unit: unit, price: unitPrice, cur: currency, exchange: exchange, remark: remark, sort: sort };
jsonCacheObj.caches.push(newCache);
}
}
$("h_feecache").value = JSON.stringify(jsonCacheObj);
postEnterFee();
}else{
postEnterFee();
}
}
}
function saveTemplate(iState){
var opType = $("sel_optype").value;
var feeType = $("sel_feetype").value;
var templateId = $("h_templateid").value.trim();
if(iState == 1 && templateId != ""){
$("h_post").value = "1";//保存费用模板明细信息
saveFee();
//postEnterFee();
}else if(iState == 1 && templateId == ""){
$("h_post").value = "3";//保存费用模板主信息
saveFee();
}else{
if(window.confirm("是否将已经添加的费用一起保存")){
$("h_post").value = "3";//保存费用模板主信息以及费用明细信息
saveFee();
//postEnterFee();
}else{
$("h_post").value = "2";//保存费用模板主信息
postEnterFee();
//window.opener.location.href=window.opener.location.href;
}
}
// setTimeout(function(){
// createGrid();
// },200);
}
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;
if(commonGridObj_fee != null){
for(var i=0;i<commonGridObj_fee.getGridObj().getRowsNum();i++){
var gID = commonGridObj_fee.getGridObj().getRowId(i);
var rowIndex = commonGridObj_fee.getGridObj().getRowIndex(gID);
var isCheckState = commonGridObj_fee.getGridObj().cellByIndex(rowIndex,0).getValue();
if(isCheckState == 1){
var url = "CodeFeeTemplateSetGridSource.aspx?handle=deletedetail&detailid=" + gID + "&uid=" + commonGridObj_fee.newGuid();
var loader = dhtmlxAjax.getSync(url);
var deleteState = parseInt(loader.xmlDoc.responseText);
if(deleteState == 1){
iDelCount++;
}
iCount++;
}
}
}
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;
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();
}