博客
关于我
react 中 如何给日期加条件并传值
阅读量:394 次
发布时间:2019-03-05

本文共 3081 字,大约阅读时间需要 10 分钟。

日期查询原先是这样实现的:

  {/* 日期 */}

 

    {getFieldDecorator('range-time-picker', rangeConfig)(

            

        )}

 

            {getFieldDecorator('rangtime', {

                    rules: [{

                        type: 'array',

                        message: '请选择时间范围'

                }]

                })(

                        

                           '7天': [moment(), moment().add(7, 'days')],

                           '15天': [moment(), moment().add(15, 'days')],

                           '自然月': [moment(), moment().add(1, 'month')],

                           '半年': [moment(), moment().add(183, 'days')],

                            '一年': [moment(), moment().add(366, 'days')],

                            '一季度': [moment(), moment().add(3, 'month')],

                              '两季度': [moment(), moment().add(6, 'month')],

                              '三季度': [moment(), moment().add(9, 'month')],

                              '至月底': [moment(), moment().endOf('month')],

                              '至年底': [moment(), moment().endOf('year')]

                        }}

现在需要实现默认显示最近30天的日期范围怎么办?

  {/* 日期范围默认设置 */}

 

            {getFieldDecorator('rangtime', {

                    rules: [{

                        type: 'array',

                        message: '请选择时间范围'

                }]

                })(

                              

                                           '30天': [moment(), moment().add(29, 'days')]

                                           }}

  {/* 查询处理 */}

 

{

        e.preventDefault();

        const { dispatch, form } = this.props;

        form.validateFields((err, fieldsValue) => {

            if (err) return;

            const rangeTimeValue = fieldsValue['rangtime'] ? fieldsValue['rangtime'] : [];

            if (rangeTimeValue.length > 0) {

                const values = { ...fieldsValue,

                    'starttime': '',

                 'endtime': '',

                'customercode': this.state.customerID,

                'commoditycode': fieldsValue['commoditycode'],

                'billcode': fieldsValue['billcode'],

                'searchtype': fieldsValue['searchtype'],

            };

            if (rangeTimeValue.length > 0) {

                values['starttime'] = rangeTimeValue[0].format("Y-M-d");

                values['endtime'] = rangeTimeValue[1].format("Y-M-d");

            }

            this.props.handleSetState({ formValues: values });

            dispatch({ type: 'xxxxx/fetch', payload: values });

        });

  {/* 无条件查询处理 */}

 

{

        e.preventDefault();

        const { dispatch, form } = this.props;

        form.validateFields((err, fieldsValue) => {

            if (err) return;

            const values = { ...fieldsValue,

            };

            dispatch({ type: 'xxxxx/fetch', payload: values });

        });

转载地址:http://lobzz.baihongyu.com/

你可能感兴趣的文章
nacos自动刷新配置
查看>>
nacos运行报错问题之一
查看>>
Nacos部署中的一些常见问题汇总
查看>>
NACOS部署,微服务框架之NACOS-单机、集群方式部署
查看>>
Nacos配置Mysql数据库
查看>>
Nacos配置中心中配置文件的创建、微服务读取nacos配置中心
查看>>
Nacos配置中心集群原理及源码分析
查看>>
nacos配置在代码中如何引用
查看>>
nacos配置新增不成功
查看>>
nacos配置自动刷新源码解析
查看>>
nacos集成分布式事务插件Seata的序列化问题,实际上是Seata本身存在bug!!
查看>>
Nacos集群搭建
查看>>
nacos集群搭建
查看>>
nacos集群网络分区对的影响和运维方式
查看>>
nacos集群节点故障对应用的影响以及应急方法
查看>>
nacos集群配置详解
查看>>
Nagios 3.0 Jumpstart Guide For Linux – Overview, Installation and Configuration
查看>>
nagios 实时监控 iptables 状态
查看>>
WAP短信格式解析及在Linux下用C语言实现
查看>>
nagios+cacti整合
查看>>