| | |
| | | import React, {Component} from 'react' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Row, Col, Icon, Radio, Input, Button } from 'antd' |
| | | import './index.scss' |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | const { card } = this.state |
| | | |
| | | if (nextProps.card.origin !== card.origin) { |
| | | this.setState({ |
| | | card: {...card, origin: nextProps.card.origin} |
| | | }) |
| | | } |
| | | } |
| | | |
| | | changeSelect = () => { |
| | | const { card } = this.state |
| | | |
| | | if (card.origin) return |
| | | |
| | | this.setState({ |
| | | card: {...card, selected: !card.selected} |
| | | }, () => { |
| | |
| | | |
| | | changeType = (e) => { |
| | | const { card } = this.state |
| | | |
| | | if (card.origin) return |
| | | |
| | | this.setState({ |
| | | card: {...card, type: e.target.value} |
| | | }, () => { |
| | | this.props.changeCard(this.state.card) |
| | | this.props.changeCard(this.state.card, 'update') |
| | | }) |
| | | } |
| | | |
| | | render() { |
| | | const { card, type } = this.state |
| | | return ( |
| | | <div className={'ant-card ant-card-bordered ' + (card.selected ? 'selected' : '')} > |
| | | <div className={'ant-card ant-card-bordered ' + (card.selected ? 'selected' : '') + (card.origin ? ' fixed' : '')} > |
| | | <div className="base" onClick={this.changeSelect}> |
| | | <Icon type="check" /> |
| | | <p title={card.field}>{this.props.dict['model.form.field']}: <span>{card.field}</span></p> |
| | | <p title={card.label}>{this.props.dict['model.name']}: <span>{card.label}</span></p> |
| | | <p title={card.field}>字段: <span>{card.field}</span></p> |
| | | <p title={card.label}>名称: <span>{card.label}</span></p> |
| | | </div> |
| | | {type === 'search' ? |
| | | <Radio.Group onChange={this.changeType} value={card.type} disabled={!card.selected}> |
| | | <Radio.Group onChange={this.changeType} value={card.type} disabled={!card.selected || card.origin}> |
| | | <Radio value="text">text</Radio> |
| | | <Radio value="select">select</Radio> |
| | | <Radio value="daterange">dateRange</Radio> |
| | | </Radio.Group> : null |
| | | } |
| | | {type === 'columns' ? |
| | | <Radio.Group onChange={this.changeType} value={card.type} disabled={!card.selected}> |
| | | <Radio.Group onChange={this.changeType} value={card.type} disabled={!card.selected || card.origin}> |
| | | <Radio value="text">text</Radio> |
| | | <Radio value="number">number</Radio> |
| | | <Radio value="picture">picture</Radio> |
| | | </Radio.Group> : null |
| | | } |
| | | {type === 'form' ? |
| | | <Radio.Group onChange={this.changeType} value={card.type} disabled={!card.selected}> |
| | | <Radio.Group onChange={this.changeType} value={card.type} disabled={!card.selected || card.origin}> |
| | | <Radio value="text">text</Radio> |
| | | <Radio value="number">number</Radio> |
| | | <Radio value="select">select</Radio> |
| | |
| | | super(props) |
| | | |
| | | this.state = { |
| | | dataSource: props.data, |
| | | selectCards: props.data.filter(item => item.selected), |
| | | selectCards: [], |
| | | type: props.type, |
| | | searchKey: '', |
| | | loading: false |
| | | } |
| | | } |
| | | |
| | | changeCard = (item) => { |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | const { data } = this.props |
| | | |
| | | if (!is(fromJS(nextProps.data), fromJS(data))) { |
| | | this.setState({selectCards: []}) |
| | | } |
| | | } |
| | | |
| | | changeCard = (item, m) => { |
| | | let cards = JSON.parse(JSON.stringify(this.state.selectCards)) |
| | | |
| | | if (!item.selected) { |
| | | if (m === 'update') { |
| | | cards = cards.map(card => { |
| | | if (card.field === item.field) { |
| | | return item |
| | | } |
| | | return card |
| | | }) |
| | | } else if (!item.selected) { |
| | | cards = cards.filter(card => card.field !== item.field) |
| | | } else { |
| | | cards.push(item) |
| | |
| | | |
| | | this.setState({ |
| | | selectCards: cards |
| | | }, () => { |
| | | this.props.onChange(cards) |
| | | }) |
| | | } |
| | | |
| | | reset = () => { |
| | | this.setState({ |
| | | searchKey: '', |
| | | loading: true |
| | | }, () => { |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | render() { |
| | | const { dict } = this.props |
| | | const { dataSource, type, loading } = this.state |
| | | const { data } = this.props |
| | | const { type } = this.state |
| | | |
| | | return ( |
| | | <div className="common-modal-edit-card"> |
| | | <Row className="search-row"> |
| | | <Col span={8}> |
| | | {!loading ? <Search placeholder={dict['form.required.input'] + dict['model.form.field']} onSearch={value => {this.setState({searchKey: value})}} enterButton /> : null} |
| | | <Search placeholder="请输入字段" onSearch={value => {this.setState({searchKey: value})}} enterButton /> |
| | | </Col> |
| | | <Col span={8}> |
| | | <Button onClick={this.reset}> |
| | | {this.props.dict['header.reset']} |
| | | </Button> |
| | | <Button onClick={this.reset}>重置</Button> |
| | | </Col> |
| | | </Row> |
| | | <Row> |
| | | {dataSource.map((item, index) => { |
| | | {data.map((item, index) => { |
| | | if (item.field.toLowerCase().indexOf(this.state.searchKey.toLowerCase()) >= 0 || item.label.indexOf(this.state.searchKey) >= 0) { |
| | | return ( |
| | | <Col key={index} span={8}> |
| | | <EditCardCell ref={'cellCard' + index} type={type} card={item} dict={this.props.dict} changeCard={this.changeCard} /> |
| | | <EditCardCell type={type} card={item} changeCard={this.changeCard} /> |
| | | </Col> |
| | | ) |
| | | } else { |