博客
关于我
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/

你可能感兴趣的文章
Python+requests+unittest执行接口自动化测试详情
查看>>
python+requests+unittest执行自动化接口测试!
查看>>
Python+Requests编码识别Bug
查看>>
python函数编写_[零基础学python]传说中的函数编写条规
查看>>
Python+selenium —— UI自动化之鼠标操作
查看>>
python函数注释,参数后面加冒号:,函数后面的箭头→是什么?
查看>>
Python+Selenium+Threading进行兼容性测试
查看>>
Python+selenium+unittest的GUI自动化框架实现
查看>>
python函数拟合不规则曲线_Python计算&绘图——曲线拟合问题(转)
查看>>
python函数定义的基本格式_零基础学python-2.19 定义函数、调用函数与默认参数
查看>>
Python+Selenium之数据驱动测试的实现
查看>>
python函数定义与使用+返回值简解
查看>>
Python+Selenium登录
查看>>
Python日期时间模块
查看>>
Python函数合集:足足68个内置函数请收好!
查看>>
Python+Selenium自动化测试项目实战
查看>>
Python+Selenium自动化测试项目实战【建议收藏】
查看>>
Python+Selenium自动化测试:Page Object模式
查看>>
python+selenium进行cnblog的自动化登录测试
查看>>
Python函数只返回第一个值而不是数据框
查看>>