Extjs2.2 开始时间,结束时间,工期 联动(选二补一),包含日期,天数的互转
选择任意两个, 则第三个自动填写
文本框代码:
var downtime_root_simple = { xtype : 'numberfield', fieldLabel : '工期(天)', name : 'plan_hours', id : 'plan_hours', allowBlank : true, readOnly : flag == 4 ? true : false, maxLength : 11, anchor : '95%', listeners : { change : function(){ var plan_hours = Ext.getCmp("plan_hours"); var plan_hours_value = Ext.getCmp("plan_hours").getValue(); var plan_end_time = Ext.getCmp("plan_end_time"); var plan_end_time_value = Ext.getCmp("plan_end_time").getValue(); var plan_start_time = Ext.getCmp("plan_start_time"); var plan_start_time_value = Ext.getCmp("plan_start_time").getValue(); if (plan_start_time.isValid()) { var date_S = new Date(plan_start_time_value); plan_end_time.setValue(new Date(date_S.getTime() + (plan_hours_value-1)*24*60*60*1000)); } else if(plan_end_time.isValid()){ var date_E = new Date(plan_end_time_value); plan_start_time.setValue(new Date(date_E.getTime() - (plan_hours_value-1)*24*60*60*1000)); } } } };
开始时间代码:
var start_time_root = { xtype : 'datefield', fieldLabel : '开始时间<font color="red">*</font>', name : 'plan_start_time', id : 'plan_start_time', format : "Y-m-d", allowBlank : false, editable : false, anchor : '95%', listeners : { "change" : function() { var plan_hours = Ext.getCmp("plan_hours"); var plan_hours_value = Ext.getCmp("plan_hours").getValue(); var plan_end_time = Ext.getCmp("plan_end_time"); var plan_end_time_value = Ext.getCmp("plan_end_time").getValue(); var plan_start_time = Ext.getCmp("plan_start_time"); var plan_start_time_value = Ext.getCmp("plan_start_time").getValue(); if (plan_start_time.isValid()) { var date_S = new Date(plan_start_time_value); plan_end_time.setMinValue(plan_start_time_value); if(plan_end_time_value){ var date_E = new Date(plan_end_time_value); plan_hours.setValue((date_E.getTime() - date_S.getTime())/(24*60*60*1000)+1); }else{ if(plan_hours_value){ plan_end_time.setValue(new Date(date_S.getTime() + plan_hours_value*24*60*60*1000)); } } } else { plan_end_time.setMinValue(null); } } } };
结束时间代码:
var end_time_root = { xtype : 'datefield', fieldLabel : '结束时间<font color="red">*</font>', name : 'plan_end_time', id : 'plan_end_time', allowBlank : false, format : "Y-m-d", maxLength : 12, anchor : '95%', listeners : { "change" : function() { var plan_hours = Ext.getCmp("plan_hours"); var plan_hours_value = Ext.getCmp("plan_hours").getValue(); var plan_end_time = Ext.getCmp("plan_end_time"); var plan_end_time_value = Ext.getCmp("plan_end_time").getValue(); var plan_start_time = Ext.getCmp("plan_start_time"); var plan_start_time_value = Ext.getCmp("plan_start_time").getValue(); if (plan_end_time.isValid()) { var date_E = new Date(plan_end_time_value); plan_start_time.setMaxValue(plan_end_time_value); if(plan_start_time_value){ var date_S = new Date(plan_start_time_value); plan_hours.setValue((date_E.getTime() - date_S.getTime())/(24*60*60*1000)+1); }else{ if(plan_hours_value){ plan_start_time.setValue(new Date(date_E.getTime() - plan_hours_value*24*60*60*1000)); } } } else { plan_start_time.setMaxValue(null); } show_change_reason(); } } };