BasicList.js 4.06 KB
Newer Older
1 2 3
import React, { PureComponent } from 'react';
import moment from 'moment';
import { connect } from 'dva';
jim's avatar
jim committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17
import {
  List,
  Card,
  Row,
  Col,
  Radio,
  Input,
  Progress,
  Button,
  Icon,
  Dropdown,
  Menu,
  Avatar,
} from 'antd';
18 19 20 21 22 23 24

import PageHeaderLayout from '../../layouts/PageHeaderLayout';

import styles from './BasicList.less';

const RadioButton = Radio.Button;
const RadioGroup = Radio.Group;
afc163's avatar
afc163 committed
25
const { Search } = Input;
26

Andreas Cederström's avatar
Andreas Cederström committed
27 28 29
@connect(({ list, loading }) => ({
  list,
  loading: loading.models.list,
30 31 32 33 34 35 36 37 38 39 40 41
}))
export default class BasicList extends PureComponent {
  componentDidMount() {
    this.props.dispatch({
      type: 'list/fetch',
      payload: {
        count: 5,
      },
    });
  }

  render() {
陈帅's avatar
陈帅 committed
42 43 44 45
    const {
      list: { list },
      loading,
    } = this.props;
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

    const Info = ({ title, value, bordered }) => (
      <div className={styles.headerInfo}>
        <span>{title}</span>
        <p>{value}</p>
        {bordered && <em />}
      </div>
    );

    const extraContent = (
      <div className={styles.extraContent}>
        <RadioGroup defaultValue="all">
          <RadioButton value="all">全部</RadioButton>
          <RadioButton value="progress">进行中</RadioButton>
          <RadioButton value="waiting">等待中</RadioButton>
        </RadioGroup>
jim's avatar
jim committed
62
        <Search className={styles.extraContentSearch} placeholder="请输入" onSearch={() => ({})} />
63 64 65 66 67 68 69 70 71 72 73 74
      </div>
    );

    const paginationProps = {
      showSizeChanger: true,
      showQuickJumper: true,
      pageSize: 5,
      total: 50,
    };

    const ListContent = ({ data: { owner, createdAt, percent, status } }) => (
      <div className={styles.listContent}>
afc163's avatar
afc163 committed
75
        <div className={styles.listContentItem}>
76 77 78
          <span>Owner</span>
          <p>{owner}</p>
        </div>
afc163's avatar
afc163 committed
79
        <div className={styles.listContentItem}>
80
          <span>开始时间</span>
spiritree's avatar
spiritree committed
81
          <p>{moment(createdAt).format('YYYY-MM-DD HH:mm')}</p>
82
        </div>
afc163's avatar
afc163 committed
83 84
        <div className={styles.listContentItem}>
          <Progress percent={percent} status={status} strokeWidth={6} style={{ width: 180 }} />
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
        </div>
      </div>
    );

    const menu = (
      <Menu>
        <Menu.Item>
          <a>编辑</a>
        </Menu.Item>
        <Menu.Item>
          <a>删除</a>
        </Menu.Item>
      </Menu>
    );

    const MoreBtn = () => (
      <Dropdown overlay={menu}>
        <a>
          更多 <Icon type="down" />
        </a>
      </Dropdown>
    );

    return (
      <PageHeaderLayout>
        <div className={styles.standardList}>
111
          <Card bordered={false}>
112 113
            <Row>
              <Col sm={8} xs={24}>
niko's avatar
niko committed
114
                <Info title="我的待办" value="8个任务" bordered />
115 116 117 118 119 120 121 122 123 124 125
              </Col>
              <Col sm={8} xs={24}>
                <Info title="本周任务平均处理时间" value="32分钟" bordered />
              </Col>
              <Col sm={8} xs={24}>
                <Info title="本周完成任务数" value="24个任务" />
              </Col>
            </Row>
          </Card>

          <Card
niko's avatar
niko committed
126
            className={styles.listCard}
127
            bordered={false}
niko's avatar
niko committed
128
            title="标准列表"
nikogu's avatar
nikogu committed
129
            style={{ marginTop: 24 }}
niko's avatar
niko committed
130
            bodyStyle={{ padding: '0 32px 40px 32px' }}
131 132
            extra={extraContent}
          >
afc163's avatar
afc163 committed
133
            <Button type="dashed" style={{ width: '100%', marginBottom: 8 }} icon="plus">
afc163's avatar
afc163 committed
134
              添加
135 136
            </Button>
            <List
niko's avatar
niko committed
137
              size="large"
nikogu's avatar
nikogu committed
138
              rowKey="id"
139 140
              loading={loading}
              pagination={paginationProps}
nikogu's avatar
nikogu committed
141 142
              dataSource={list}
              renderItem={item => (
jim's avatar
jim committed
143
                <List.Item actions={[<a>编辑</a>, <MoreBtn />]}>
nikogu's avatar
nikogu committed
144 145 146 147 148 149 150 151 152
                  <List.Item.Meta
                    avatar={<Avatar src={item.logo} shape="square" size="large" />}
                    title={<a href={item.href}>{item.title}</a>}
                    description={item.subDescription}
                  />
                  <ListContent data={item} />
                </List.Item>
              )}
            />
153 154 155 156 157 158
          </Card>
        </div>
      </PageHeaderLayout>
    );
  }
}