import React, { PureComponent } from "react";
import { connect } from "dva";
import { Button, Form, Col, Row, Input } from "antd";
import styles from "./index.less";

const FormItem = Form.Item;

@Form.create()
class DetailList extends PureComponent {
  constructor(props) {
    super(props);
  }
  // 生成组件
  getFields() {
    const { getFieldDecorator } = this.props.form;
    const { fieldList, detailList } = this.props;
    const children = [];
    for (let i = 0; i < fieldList.length; i++) {
      children.push(
        <Col key={i} className={styles.searchFormCol}>
          <FormItem label={fieldList[i].label}>
            {getFieldDecorator(fieldList[i].field, {
              initialValue: detailList[fieldList[i].field]
            })(this.parseEdit(fieldList[i].isEdit))}
          </FormItem>
        </Col>
      );
    }
    return children;
  }
  // 解析详情项是否可编辑
  parseEdit(isEdit) {
    if (isEdit) {
      return <Input />;
    } else {
      return <Input className={styles.detailIpt} disabled />;
    }
  }
  render() {
    const detailHtml = this.getFields();
    return (
      <div>
        <div>
          <Form layout="inline">
            <Row>{detailHtml}</Row>
          </Form>
        </div>
      </div>
    );
  }
}
// export default connect(() => ({}))(DetailList);
export default DetailList;
