`
taiwei.peng
  • 浏览: 234514 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

ext js 事前监听

    博客分类:
  • js
阅读更多
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="ext" uri="/ext-tags"%>
<%@ taglib prefix="app" uri="/app-tags"%>
<ext:ui>
<ext:script>
//查询
function onSearch(){
   var start=Ext.get("startDate").getValue();
   var end=Ext.get("endDate").getValue();
   if(start!=""&&end!=""){
    if(start>end){
       Ext.Msg.alert("${app:i18n('prompt')}","结束日期必须大于开始日期");
       return;
    }
   }
   var srcZonearea=Ext.get("srcZonearea").getValue();
   if(srcZonearea.length>30){
      Ext.Msg.alert("${app:i18n('prompt')}","不能超过30个字符");
      return;
   }
   Ext.Msg.wait('正在查询,请稍等...');
   gridView.getStore().baseParams = queryView.getForm().getValues();
   pagingBar.pageSize = 20;
   gridView.getStore().baseParams["limit"] = pagingBar.pageSize;
   gridView.getStore().load({callback: searchCallback});
}

function searchCallback(r,options,success){
Ext.Msg.hide();
if (success == true) {
Ext.message.msg('${app:i18n('prompt')}', '${app:i18n('searchSuccess')}');
} else {
Ext.message.msg('${app:i18n('prompt')}', '${app:i18n('searchFailure')}');
}
}

function dateRenderer(value){
   if(null!=value){
      return Ext.util.Format.substr(value,0,10);
   }
}

function timeRenderer(value){
   if(null!=value){
     var time=value.replace('T',' ');
     return Ext.util.Format.substr(time,11,5);  
   }
}

function dtRenderer(value){
  if(null!=value){
return value.replace('T',' ');
  }
}

function TypeByNameRenderer(value){
  if(value==4){
     return "干支线";
  }else if(value==2){
     return "散航";
  }else{
     return "";
  }
}

function loadRateRenderer(value){
  if(null!=value){
     return value+"%";
  }
}

function showDataValue(value){
if(null!=value){
return "<div>"+value+"</div>";
}
return;
}

function TimelyRenderer(value, cellmeta, record, rowIndex, columnIndex, store){
   var departDate=record.data["departTime"];
   var updateDate=record.data["updateTime"];
   if(null!=updateDate){  
      var departDateFmt=departDate.replace('T',' ');
      var updateDateFmt=updateDate.replace('T',' ');
      var begintime_ms = Date.parse(new Date(departDateFmt.replace(/-/g, "/")));  
      var endtime_ms = Date.parse(new Date(updateDateFmt.replace(/-/g, "/")));
  var result = endtime_ms - begintime_ms;
  var hours=Math.floor(result/(60*1000))  
      if(hours<=30){
        return "是";
      }else{
        return "否";
      }
   }else{
      return "";
   }
}

//编辑前监听器
function beforeEdit(e){
  var flag=true;
  var row = e.row;
  var column = e.column;
  var record = e.record;
  var columnModel = e.grid.getColumnModel();
  var dataIndex = columnModel.getDataIndex(column);
  var orgAuthFlg = record.data.orgAuthFlg;
  var deleteFlg = record.data.deleteFlg;
  var dataRe=gridStore.reader.jsonData.tempConveyanceInfos;
  var conveyId=record.get("conveyId");
  //判断有实际到车时间不允许录入
  var actualArrivetime=record.get("actualArrivetime");
  if(null!=actualArrivetime){
     flag=false; 
  }else{
     //判断昨天和今天的数据可以录入
     var curDate=new Date();
     var timeToday = curDate.format("Y") +"-" +curDate.format("m") + "-"+(curDate.format("d"));
     var preDate = new Date(curDate.getTime() - 24*60*60*1000);
     var timeYesterday = preDate.format("Y") +"-" +preDate.format("m") + "-"+(preDate.format("d"));
     var departTimeStr=record.get("departTime");
     var departDate=Ext.util.Format.substr(departTimeStr,0,10);
     if((timeToday==departDate)||(timeYesterday==departDate)){
         if(e.field=="planUnloadcode"||e.field=="transportLength"){
            flag=true;
         } 
        if(e.field=="vehiclePlateno"){
        if(null==dataRe[row].vehiclePlateno){
           flag=true; 
        }else{
           if(null==record.get("vehiclePlatenoSys")){
             flag=true;
           }else{
             flag=false;
           }
        }
       }else if(e.field=="loadCapacity"){
         if(null==dataRe[row].loadCapacity){
            flag=true; 
         }else{
           if(null==record.get("loadCapacitySys")){
              flag=true;
           }else{
              flag=false;
            }
         }
       }else if(e.field=="loadRate"){
        if(null==dataRe[row].loadRate){
            flag=true;
        }else{
            if(null==record.get("loadRateSys")){
              flag=true;
            }else{
              flag=false;
            }
        }
      }else if(e.field=="manageArea"){
       if(null==dataRe[row].manageArea){
          flag=true;
        }else{
          if(null==record.get("manageAreaSys")){
            flag=true;
          }else{
            flag=false; 
          }
        }
      }
     }else{
       flag=false; 
     }
  }
  return flag;


//编辑后监听器
function afterEdit(e){
if(e.field == "planUnloadcode") {
var deptCode=e.value;
if(deptCode!=""){
    Ext.Ajax.request({
url: 'findDepartmentByCode.action',
params: { deptCode: deptCode},
async: false,
success: function (response) {
var result = Ext.util.JSON.decode(response.responseText);
if(result.msg == 'fail'){
    Ext.MessageBox.alert('${app:i18n('prompt')}', '您输入的网点不存在!');
    //gridView.startEditing(e.row, e.column); 
}
},
failure:function () {
   Ext.Msg.alert("${app:i18n('prompt')}","获取失败");
}
});
}
}else if(e.field=="transportLength"){
    var timeLength=e.value;
    if(timeLength!=""){
      var value=timeLength.split(":");
      if(value.length<2){
        Ext.MessageBox.alert('${app:i18n('prompt')}', '您输入的时长格式不对!');
      }else{
        if(/^[0-9]{1,}$/.test(value[0])== false){
   Ext.MessageBox.alert('${app:i18n('prompt')}', '您输入的时长格式不对!');
    }
    if(/^[0-9]{1,}$/.test(value[1])== false){
  Ext.MessageBox.alert('${app:i18n('prompt')}', '您输入的时长格式不对!');
    }
    if(!(value[1]>=0&&value[1]<=59)){
       Ext.MessageBox.alert('${app:i18n('prompt')}', '您输入的时长格式不对!');
    }
      } 
    }
  }
}

//保存
function onUpdate(){
   gridView.startEditing(1,1);
   if (gridView.getSelectionModel().getSelections().length < 1) {
Ext.MessageBox.alert("${app:i18n('prompt')}","请选择需要提交的数据!");
return;
   }
   var record=selectionModel.getSelections();
   var modified = gridStore.modified;
   var rowCount=record.length;
   var json = [];
   //Ext.each(modified, function(item){
   //   json.push(item.data);
   //});
    for(var i=0;i<rowCount;i++){
        json.push(record[i].data);
        var r=checkValidate(record[i]);
        if(!r){
           return;
        }
    }
   if(json.length <=0){
      Ext.Msg.alert('${app:i18n('prompt')}', "没有任何需要更新的数据!");
   }else{
         Ext.Msg.confirm("${app:i18n('prompt')}", "确定要保存吗?", function(button) {  
               if (button == "yes") {
               Ext.Ajax.request({
                url: "updateTempConveyanceInfo.action",
                params: { data: Ext.util.JSON.encode(json) },
                method: "POST",
                success: function(response) {
                var result = Ext.util.JSON.decode(response.responseText);
if(result.msg == 'success'){
                   Ext.Msg.alert('${app:i18n('prompt')}', "数据更新成功!", function() {
                   onSearch();
                  });
                }else{
                   Ext.Msg.alert('${app:i18n('prompt')}', "数据更新失败,请重新再试!");
                }
                },
                failure: function(response) {
                    Ext.Msg.alert('${app:i18n('prompt')}', "数据更新失败,请重新再试!");
                 }
               });
              }
         });
    }
}

//验证是否输入的数据是有效的 
var checkValidate=function(record){
   var result=true;
   var loadCapacity=record.get("loadCapacity");
   if(null!=loadCapacity&&loadCapacity!=""){
     if(/^\d*(?:\.\d{0,3})?$/.test(loadCapacity)== false){
        Ext.MessageBox.alert('${app:i18n('prompt')}',"您只能输入不超过3位小数的数字的载位,不能提交!");     
        result = false;
        return result;
     }
   }
   var loadRate=record.get("loadRate");
   if(null!=loadRate&&loadRate!=""){ 
     if(!(loadRate>0&&loadRate<=100)){  
        Ext.MessageBox.alert('${app:i18n('prompt')}',"您只能输入不大于100的装载率,不能提交!");   
        result = false; 
        return result;
    }
   }
   var manageArea=record.get("manageArea"); 
   if(null!=manageArea&&manageArea!=""){ 
      Ext.Ajax.request({
url: 'findDepartmentByCode.action',
params: { deptCode:manageArea}, 
async: false,
success: function (response) {
var result = Ext.util.JSON.decode(response.responseText);
if(result.msg == 'fail'){
    Ext.MessageBox.alert('${app:i18n('prompt')}', '您输入的车辆管理区不存在,不能提交!');
    result = false;
    return result;   
}
},
failure:function () {
   Ext.Msg.alert("${app:i18n('prompt')}","获取失败");
}
});
   }
   var planUnloadcode=record.get("planUnloadcode");
   if(null!=planUnloadcode&&planUnloadcode!=""){
        Ext.Ajax.request({
url: 'findDepartmentByCode.action',
params: { deptCode:planUnloadcode}, 
async: false,
success: function (response) {
var result = Ext.util.JSON.decode(response.responseText);
if(result.msg == 'fail'){
    Ext.MessageBox.alert('${app:i18n('prompt')}', '您输入的计划卸车网点不存在,不能提交!');
    result = false;  
    return result; 
}
},
failure:function () {
   Ext.Msg.alert("${app:i18n('prompt')}","获取失败");
}
});
   }
   var transportLength=record.get("transportLength");
   if(null!=transportLength&&transportLength!=""){
    var transport=transportLength.split(":");
if(transport.length<2){
Ext.MessageBox.alert('${app:i18n('prompt')}', '您输入的时长格式不对,不能提交!');
result = false;   
return result;
     }else{
           if(/^[0-9]{1,}$/.test(transport[0])== false){
       Ext.MessageBox.alert('${app:i18n('prompt')}', '您输入的时长格式不对,不能提交!');
   result = false; 
   return result; 
      }
     if(/^[0-9]{1,}$/.test(transport[1])== false){
       Ext.MessageBox.alert('${app:i18n('prompt')}', '您输入的时长格式不对,不能提交!');
       result = false;
       return result;  
        }
  if(!(transport[1]>=0&&transport[1]<=59)){
      Ext.MessageBox.alert('${app:i18n('prompt')}', '您输入的时长格式不对,不能提交!');
      result = false;
      return result;  
   }
         }
     }
     return result;
}


//导出
function onExport(){
    Ext.MessageBox.wait("正在导出...");
    var allParam = queryView.getForm().getValues();
Ext.Ajax.request({
params:allParam,
url: "createConveyanceInfoFile.action",
timeout: 10*60*1000,
method:'post',
success: successFn,
failure: failureFn,
callback: exportCallback,
urlExport: "ConveyanceInfoExport.action"
});


function successFn(response,options ){
dataSource = Ext.util.JSON.decode(response.responseText);
fileName=dataSource.fileName;
window.location = encodeURI(encodeURI(options.urlExport + "?fileName=" + fileName));
}

function failureFn(response){
Ext.message.msg('提示','导出失败!' );
}

function exportCallback(){
Ext.MessageBox.hide();
}

var globleVar = {};
function storeLoad(store,records,options){
for(var i=0;i<records.length;i++){
var data = records[i]['data'];
var conveyId = data['conveyId'];
if(globleVar[conveyId] == null){

var vehiclePlateno = data['vehiclePlateno'];
var loadCapacity = data['loadCapacity'];
var loadRate = data['loadRate'];
var manageArea = data['manageArea'];

var obj = {};
obj['vehiclePlateno'] = vehiclePlateno;
obj['loadCapacity'] = loadCapacity;
obj['loadRate'] = loadRate;
obj['manageArea'] = manageArea;
globleVar[conveyId] = obj;
}
}
}

</ext:script>

<ext:viewport layout="border">
<ext:items>
    <ext:panel region="center" layout="border" frame="true">
       <ext:tbar var="searchTbar">
           <ext:button text="查询" var="btnSearch" handler="onSearch" />
           <ext:button text="导出" var="btnExport" handler="onExport" />
           <ext:button text="保存" var="btnEdit"   handler="onUpdate" />
       </ext:tbar>
   
       <ext:items>
        <ext:formPanel region="north" var="queryView"   frame="true" border="0" autoHeight="true" labelAlign="right"  labelWidth="80">
          <ext:items>
             <ext:fieldSet layout="column" title="查询条件" >
              <ext:items>
          <ext:panel width="200" layout="form">
<ext:items>
<ext:dateField id="startDate" name="query.startDate" var="field_startDate" fieldLabel="开始日期" width="100" format="Y-m-d"  /> 
</ext:items>
</ext:panel>

<ext:panel width="200" layout="form">
<ext:items>
<ext:dateField id="endDate" name="query.endDate" var="field_endDate" fieldLabel="结束日期" width="100" format="Y-m-d" />
</ext:items>
</ext:panel>

<ext:panel width="200" layout="form">
<ext:items>
  <ext:textField  id="srcZonearea" name="query.srcZonearea" var="field_srcZonearea" fieldLabel="始发网点" width="100" maxLength="100"/>
</ext:items>
</ext:panel>

<ext:panel width="200" layout="form">
<ext:items>
  <ext:textField  id="planUnloadcode" name="query.planUnloadcode" var="field_planUnloadcode" fieldLabel="计划卸车网点" width="100" maxLength="100"/>
</ext:items>
</ext:panel>

<ext:panel width="200" layout="form">
<ext:items>
   <ext:textField  id="vehicleCode" name="query.vehicleCode" var="field_vehicleCode" fieldLabel="车标号" width="100" maxLength="100"/>
</ext:items>
</ext:panel>

<ext:panel width="200" layout="form" >
<ext:items>
   <ext:textField  id="vehiclePlateno" name="query.vehiclePlateno" var="field_vehiclePlateno" fieldLabel="车牌号" width="100" maxLength="100"/>
</ext:items>
</ext:panel>

<ext:panel width="200" layout="form" >
<ext:items>
   <ext:comboBox name="query.istoArrive" hiddenName="query.istoArrive" var="field_istoArrive" fieldLabel="是否到达"
data="['0','全部'],['1','已到'],['2','未到']" triggerAction="all" valueField="value" displayField="display" mode="local" editable="false" value="0" width="100"
listWidth="100">
</ext:comboBox>
</ext:items>
</ext:panel>
              </ext:items>
             </ext:fieldSet>
          </ext:items>
        </ext:formPanel>
       
         <ext:editorGridPanel var="gridView" region="center" frame="true" border="0"  clicksToEdit="1" loadMask="true" listeners="{beforeedit : beforeEdit,afteredit : afterEdit}">
         <ext:store var="gridStore" url="findPageByTempConveyanceInfo.action" remoteSort="true" pruneModifiedRecords="true" >
            <ext:jsonReader totalProperty="total" root="tempConveyanceInfos">
              <ext:fields type="com.sf.module.ompshare.domain.TempConveyanceInfo" /> 
            </ext:jsonReader>
         </ext:store>
         <ext:pagingToolbar var="pagingBar" pageSize="20" store="gridStore" displayInfo="true"  />
         <ext:checkboxSelectionModel var="selectionModel" singleSelect="false"/>
         <ext:columnModel sortable="true">
           <ext:propertyColumnModel dataIndex="conveyId" id="grid_conveyIde"  hidden="true"></ext:propertyColumnModel>
           <ext:propertyColumnModel dataIndex="departTime" id="grid_departTime" header="日期" width="70" renderer="dateRenderer">
   </ext:propertyColumnModel>
   <ext:propertyColumnModel dataIndex="lineCode" id="grid_lineCode" header="线路编码" width="110" renderer="showDataValue"> 
   </ext:propertyColumnModel>
   <ext:propertyColumnModel dataIndex="vehicleCode" id="grid_vehicleCode" header="车标号" width="80" renderer="showDataValue" >
   </ext:propertyColumnModel>  
   <ext:propertyColumnModel dataIndex="vehiclePlateno" id="grid_vehiclePlateno" header="车牌号" width="70" renderer="showDataValue">
<ext:textField var="grid_vehiclePlateno" maxLength="30" ></ext:textField> 
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="conveyanceType" id="conveyanceType" header="运力类型" width="60" renderer="TypeByNameRenderer">
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="loadCapacity" id="grid_loadCapacity" header="载位(T)" width="62" >
<ext:textField var="grid_loadCapacity" maxLength="30" ></ext:textField>
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="loadRate" id="grid_loadRate" header="装载率" width="60" renderer="loadRateRenderer">
<ext:textField var="grid_loadRate" maxLength="30" ></ext:textField>
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="manageArea" id="grid_manageArea" header="车辆管理区" width="70" >
<ext:textField var="grid_manageArea" maxLength="30" ></ext:textField>
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="srcZonecode" id="grid_srcZonecode" header="始发网点" width="60" >
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="srcZonearea" id="grid_srcZonearea" header="始发地区" width="60" >
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="planUnloadcode" id="grid_planUnloadcode" header="计划卸车网点" width="80">
<ext:textField var="grid_planUnloadcode" maxLength="30" ></ext:textField>
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="actualUnloadcode" id="grid_actualUnloadcode" header="实际卸车网点" width="80" >
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="destArea" id="grid_destArea" header="目的地地区" width="80" > 
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="departBatch" id="grid_departBatch" header="发出班次" width="80" renderer="showDataValue">
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="departTime" id="grid_departTime" header="发车时间" width="60" renderer="timeRenderer">
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="transportLength" id="grid_transportLength" header="运输时长(h/m)" width="80" >
<ext:textField var="grid_transportLength" maxLength="30" ></ext:textField>
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="planArrivetime" id="grid_planArrivetime" header="预计到车日期" width="80" renderer="dateRenderer">
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="planArrivetime" id="grid_planArrivetime" header="预计到车时间" width="80" renderer="timeRenderer">
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="actualArrivetime" id="grid_actualArrivetime" header="实际到车日期" width="80" renderer="dateRenderer">
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="actualArrivetime" id="grid_actualArrivetime" header="实际到车时间" width="80" renderer="timeRenderer">
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="plandistributebatch" id="grid_plandistributebatch" header="预计散货班次" width="80" renderer="showDataValue">
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="actualdistributebatch" id="grid_actualdistributebatch" header="实际散货班次" width="80" renderer="showDataValue">
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="loadwaybillcnt" id="grid_loadwaybillcnt" header="装车票数" width="60" >
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="unloadwaybillcnt" id="grid_unloadwaybillcnt" header="卸车票数" width="60" >
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="empNo" id="grid_empNo" header="录入人工号" width="60" > 
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="updateTime" id="grid_updateTime" header="录入时间" width="120" renderer="dtRenderer">
</ext:propertyColumnModel>
<ext:propertyColumnModel dataIndex="isTimely" id="grid_isTimely" header="是否及时录入" width="80" >
</ext:propertyColumnModel>
         </ext:columnModel>
        </ext:editorGridPanel>
       </ext:items>
      </ext:panel>
    </ext:items>
</ext:viewport>
</ext:ui>
分享到:
评论

相关推荐

    ext学习文档

    - **响应事件**: 讲述了如何使用EXT来监听和处理用户事件。 - **使用Widgets**: 介绍了EXT提供的各种小部件,如MessageBox、Grid等。 - **使用Ajax**: 指导如何使用EXT进行Ajax调用,包括与不同服务器端技术的集成。...

    asp.net ext 中文手册

    ASP.NET Ext 是一款强大的服务器端框架与客户端JavaScript库的结合体,旨在简化Web应用程序的开发过程,尤其在处理复杂的用户界面时更为突出。组件的建立涉及多个层面,从初始化组件到渲染其视图,再到处理用户交互...

    EXT 中文手册

    - **事前准备**:在开始使用EXT之前,确保理解JavaScript的基本概念,尤其是作用域和变量可见度。 ### EXT程序规划入门 - **事前准备**:在规划EXT应用程序之前,需要准备好必要的工具和环境,包括编辑器、浏览器...

    Ext中文手册

    - **定义与背景**:Ext是一套基于JavaScript的用户界面库,它提供了丰富的组件和工具,帮助开发者快速构建高质量的Web应用程序。Ext最初由Extensible Software开发,后被Sencha公司收购。其目标是为了简化前端开发...

    EXTJS经典教程

    - **事件绑定**:介绍如何在Ext中绑定事件监听器,处理用户的交互行为。 - **作用域问题**:探讨在处理事件时常见的作用域问题及解决方案。 - **传递参数**:解释如何在事件处理函数中传递额外的参数。 - **类...

Global site tag (gtag.js) - Google Analytics