zoukankan      html  css  js  c++  java
  • 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();
                    }
                }
            };
  • 相关阅读:
    6-查看centos中的用户和用户组
    23-python用BeautifulSoup用抓取a标签内所有数据
    22-python爬虫解决gbk乱码问题
    21-py3 发邮件
    20-调用百度AI的文字识别
    6-Ubuntu与Windows不能相互复制
    2018.4.18 Ubuntu 的telnet命令详解
    2018.4.17 java多线程练习二模拟开场仪式进场
    2018.4.16 Java多线程实现龟兔赛跑
    2018.4.15 Mac系统下如何使用StartUml画好需求分析的类图 (同样适用于windows)
  • 原文地址:https://www.cnblogs.com/mr-level/p/4605634.html
Copyright © 2011-2022 走看看