aggregateTableConfigForm.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * 总体统计数据表
  3. */
  4. import React from 'react';
  5. import { Form, Select, Checkbox, Row, Col } from 'antd';
  6. import { connect } from 'dva';
  7. import STATISTICS_OPTION from './statisticsOption.json'
  8. const FormItem = Form.Item;
  9. const { Option } = Select;
  10. const CheckboxGroup = Checkbox.Group;
  11. class AggregateTableConfigForm extends React.Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. formItemLayout: {
  16. labelCol: { span: 8 },
  17. wrapperCol: { span: 16 },
  18. },
  19. searchKey: '',
  20. };
  21. }
  22. handleSearch = (value) => {
  23. this.setState({
  24. searchKey: value
  25. });
  26. }
  27. render() {
  28. const props = this.props;
  29. const { autoRefresh, chartDesigner, dispatch } = props;
  30. const{ searchKey, formItemLayout } = this.state;
  31. const { columns, aggregateTableConfig } = chartDesigner;
  32. let options = columns.filter(c => c.label.toLowerCase().indexOf(searchKey.toLowerCase()) !== -1);
  33. return (
  34. <Form>
  35. <FormItem label='分析目标' {...formItemLayout}>
  36. <Select
  37. value={aggregateTableConfig.targetColumn.name}
  38. dropdownMatchSelectWidth={false}
  39. showSearch
  40. filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
  41. onChange={(value) => {
  42. let column = columns.filter(c => c.name === value)[0];
  43. dispatch({ type: 'chartDesigner/changeField', name: 'aggregateTableConfig', value: { ...chartDesigner.aggregateTableConfig, targetColumn: column, statistics: [] }, autoRefresh });
  44. }}
  45. >
  46. {options.map((c, i)=>{
  47. return (<Option key={i} value={c.name}>{c.label}</Option>)
  48. })}
  49. </Select>
  50. </FormItem>
  51. <FormItem label='显示总体数据' {...formItemLayout}>
  52. <CheckboxGroup
  53. className='checkbox-group-statistics'
  54. value={aggregateTableConfig.statistics}
  55. onChange={(value) => {
  56. dispatch({ type: 'chartDesigner/changeField', name: 'aggregateTableConfig', value: { ...props.chartDesigner.aggregateTableConfig, statistics: value }, autoRefresh });
  57. }}
  58. >
  59. <Row>
  60. {STATISTICS_OPTION.map((s)=>{return <Col span={12} key={s.value}><Checkbox disabled={s.columnType.indexOf(aggregateTableConfig.targetColumn.type) === -1} value={s.value}>{s.label}</Checkbox></Col>})}
  61. </Row>
  62. </CheckboxGroup>
  63. </FormItem>
  64. <FormItem label='分组' {...formItemLayout}>
  65. <Select
  66. mode='multiple'
  67. labelInValue={true}
  68. dropdownMatchSelectWidth={false}
  69. placeholder='请选择...'
  70. allowClear={true}
  71. showSearch
  72. filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
  73. onChange={(values) => {
  74. const groupBy = [];
  75. values.forEach(value => {
  76. const column = value.key ? columns.find(c => c.name === value.key) : null;
  77. const g = column ? { ...value, type: column.type } : undefined;
  78. groupBy.push(g);
  79. });
  80. dispatch({ type: 'chartDesigner/changeField', name: 'aggregateTableConfig', value: { ...props.chartDesigner.aggregateTableConfig, groupBy }, autoRefresh });
  81. }}
  82. value={chartDesigner.aggregateTableConfig.groupBy}
  83. >
  84. {columns.filter(c => c.groupable).map((c, i)=>{
  85. return (<Option key={i} value={c.name}>{c.label}</Option>)
  86. })}
  87. </Select>
  88. </FormItem>
  89. </Form>
  90. );
  91. }
  92. }
  93. function mapStateToProps({ present: { chartDesigner } }) {
  94. return { chartDesigner: chartDesigner }
  95. }
  96. export default connect(mapStateToProps)(AggregateTableConfigForm);