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("", "费用名称", "结算对象类型", "客户名称", "标准", "单价", "币别", "汇率", "备注", "序号"); //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;i0 && cellVal.indexOf(" ") < cellVal.length){ cellVal = cellVal.substring(0,cellVal.indexOf(" ")); for(var i = 0;i 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;i0 && cellVal.indexOf(" ") < cellVal.length) { cellVal = cellVal.substring(0,cellVal.indexOf(" ")); for(var i = 0;i 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 0){ var combo = commonGridObj_fee.getGridObj().getCustomCombo(selectedId,ind); var comboArg = combo.getKeys(); var count = 0; for(var i = 0;i 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 0){ var jsonCacheObj = null; for(var i=0;i