teams.js 6.57 KB
import React, { PureComponent, Fragment  } from 'react';
import { connect } from 'dva';
import { Link } from 'dva/router';
import { Row, Col, Card, Form, Input, Select, Icon, Button, Dropdown, Menu, InputNumber, DatePicker, Modal, message } from 'antd';
import { Table, Alert, Badge, Divider } from 'antd';

import StandardTable from '../../components/StandardTableM';
import PageHeaderLayout from '../../layouts/PageHeaderLayout';

import styles from './teams.less';

import moment from 'moment';

const FormItem = Form.Item;
const { Option } = Select;

const getValue = obj => Object.keys(obj).map(key => obj[key]).join(',');


@connect(({ fb, loading }) => ({
  fb,
  loading: loading.models.schools,
}))
@Form.create()
export default class schoollist extends PureComponent {
  state = {
    addInputValue: '',
    selectedRows: [],
    formValues: {},
    analyse_out:{},
  };

  componentDidMount() {
    const { dispatch } = this.props;

    dispatch({
      type: 'fb/seasons',
      payload:2017,
    });
  }

  handleStandardTableChange = (pagination, filtersArg, sorter) => {
    const { dispatch } = this.props;
    const { formValues } = this.state;

    const filters = Object.keys(filtersArg).reduce((obj, key) => {
      const newObj = { ...obj };
      newObj[key] = getValue(filtersArg[key]);
      return newObj;
    }, {});

    const params = {
      currentPage: pagination.current,
      pageSize: pagination.pageSize,
      ...formValues,
      ...filters,
    };
    if (sorter.field) {
      params.sorter = `${sorter.field}_${sorter.order}`;
    }

    dispatch({
      type: 'fb/teams',
      payload: params,
    });

  }

  handleFormReset = () => {
    const { form, dispatch } = this.props;
    form.resetFields();
    this.setState({
      formValues: {},
    });
    dispatch({
      type: 'fb/teams',
      payload: {},
    });
  }

  toggleForm = () => {
    this.setState({
      expandForm: !this.state.expandForm,
    });
  }

  handleMenuClick = (e) => {


  }

  handleSelectRows = (rows) => {
    this.setState({ selectedRows:rows });
   
  }

  handleModalVisible = (flag) => {
    this.setState({
      modalVisible: !!flag,
    });
  }

  handleAnRun = ()=>{
    
    const{selectedRows} = this.state;
    let checkItems = [];
    let rowindex = null;
    for(rowindex in selectedRows){
      checkItems.push(selectedRows[rowindex].key);
    }
    let teamsStr=checkItems.join(',');

    this.props.dispatch({
      type: 'fb/analyse',
      payload: {
        teams: teamsStr,
      },
      callback:(response)=>{
          this.handleModalVisible(true);
          this.setState({analyse_out:response.pic_path});
      },
    });

  }

  handleSearch = (e) => {

    e.preventDefault();

    const { dispatch, form } = this.props;

    form.validateFields((err, fieldsValue) => {
      if (err) return;

      const values = {
        ...fieldsValue,
        updatedAt: fieldsValue.updatedAt && fieldsValue.updatedAt.valueOf(),
      };

      this.setState({
        formValues: values,
      });

      dispatch({
        type: 'fb/teams',
        payload: values,
      });
    });

  }

  //地区信息的排序控制
  leaguesort = (a,b) =>( a.caption<b.caption ? -1:1) 

  //加载地区属性的下来选择项目
  renderSellectOption=(datas)=>{
    return datas.map((item)=>{
      return <Option key={`option_${item.id}`} value={item.id}>{item.caption}</Option>
    });
  } 

  renderSimpleForm() {
    const { getFieldDecorator } = this.props.form;
    const { fb:{seasons}} = this.props;
    let seasons_SellectOption = (seasons==null || seasons==undefined)?[]:seasons;
    return (
      <Form onSubmit={this.handleSearch} layout="inline">
        <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
           <Col md={8} sm={24}>
              <FormItem label="联赛">
                  {getFieldDecorator('league_id')(
                    <Select placeholder="请选择对应的联赛队伍" style={{ width: '100%' }}>
                      {this.renderSellectOption(seasons_SellectOption.sort(this.leaguesort))}
                    </Select>
                  )}
              </FormItem>
            </Col>
            <Col md={8} sm={24}>
            <span className={styles.submitButtons}>
              <Button type="primary" htmlType="submit">查询</Button>
              <Button style={{ marginLeft: 8 }} onClick={this.handleFormReset}>重置</Button>
            </span>
          </Col>
        </Row>
        <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
        </Row>   
      </Form>
    );
  }



  renderForm() {
    return this.renderSimpleForm();
  }

  render() {
        
    const { fb: {teams}, loading } = this.props;
    const { selectedRows, modalVisible,addInputValue,analyse_out} = this.state;

    const columns = [
      {
        title: '球队名称',
        dataIndex: 'team_name',
      },
      {
        title: 'team_id',
        dataIndex: 'key',
      },
      {
        title:'sc_name',
        dataIndex : 'sc_name',
        render:val => <span> {val} </span>,
      },
      {
        title: '操作',
        dataIndex: 'team_id',
        render: (val) => (
          <Fragment>
            <Divider type="vertical" />
            <Link to={`/devutil/schoolmgr/${val}`} className={styles.logo} key="logo">
              <span>查看</span>
            </Link>
          </Fragment>
        ),
      },
    ];


    return (
      <PageHeaderLayout title="球队">
        <Card bordered={false}>
          <div className={styles.tableList}>
            <div className={styles.tableListForm}>
              {this.renderForm()}
            </div>
            <div className={styles.tableListOperator}>
              {
                selectedRows.length > 0 && (
                  <span>
                    <Button icon="plus" type="primary" onClick={() => this.handleAnRun()}>
                       处理
                    </Button>
                  </span>
                )
              }
            </div>
            <StandardTable
              selectedRows={selectedRows}
              loading={loading}
              data={teams}
              columns={columns}
              onSelectRow={this.handleSelectRows}
              onChange={this.handleStandardTableChange}
            />
          </div>
        </Card>
        <Modal
          title="分析结果"
          visible={modalVisible}
          width='320'
          onOk={() => this.handleModalVisible()}
          onCancel={() => this.handleModalVisible()}
        >
         <Card bordered={false}>
            <div>
                <img src={analyse_out}></img>
            </div>
          </Card>
        </Modal>
      </PageHeaderLayout>
    );
  }
}