import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Col, Row } from 'antd'
|
|
import './index.scss'
|
|
class CheckCard extends Component {
|
static propTpyes = {
|
config: PropTypes.object, // 表单配置信息
|
onChange: PropTypes.func, // 数据切换
|
}
|
|
state = {}
|
|
getCards = () => {
|
const { display, width, options, fields, ratio, picratio, backgroundColor, borderColor } = this.props.config
|
|
let _ratio = picratio || ratio
|
let paddingTop = '100%'
|
if (_ratio === '4:3') {
|
paddingTop = '75%'
|
} else if (_ratio === '3:2') {
|
paddingTop = '66.7%'
|
} else if (_ratio === '16:9') {
|
paddingTop = '56.25%'
|
}
|
|
let style = {}
|
|
if (borderColor) {
|
style.borderColor = borderColor
|
}
|
|
if (display !== 'picture') {
|
if (backgroundColor) {
|
style.backgroundColor = backgroundColor
|
}
|
if (!options || options.length === 0) {
|
return <Col span={width}>
|
<div className="card-cell" style={style}>
|
{fields ? fields.map(col => {
|
return <span key={col.key} style={{color: col.color, fontSize: col.fontSize + 'px', height: col.fontSize * 1.5 + 'px', textAlign: col.align}}>{col.field}</span>
|
}) : null}
|
{!fields || fields.length === 0 ? <span style={{color: '#000000', fontSize: '14px', height: '21px'}}>示例</span> : null}
|
</div>
|
</Col>
|
}
|
return options.map(item => {
|
return <Col span={width} key={item.key}>
|
<div className="card-cell" style={style}>
|
{fields.map(col => {
|
return <span key={col.key} style={{color: col.color, fontSize: col.fontSize + 'px', height: col.fontSize * 1.5 + 'px', textAlign: col.align}}>{item[col.field]}</span>
|
})}
|
</div>
|
</Col>
|
})
|
} else {
|
if (!options || options.length === 0) {
|
return <Col span={width}>
|
<div className="card-pic-cell" style={{...style, paddingTop, background: '#91d5ff'}}>
|
</div>
|
</Col>
|
}
|
return options.map(item => {
|
return <Col span={width} key={item.key}>
|
<div className="card-pic-cell" style={{...style, paddingTop, backgroundImage: `url(${item.$url})`}}>
|
</div>
|
</Col>
|
})
|
}
|
}
|
|
render() {
|
return (
|
<div className="check-card-edit-box" style={{marginTop: '10px'}}>
|
<Row gutter={12}>{this.getCards()}</Row>
|
</div>
|
)
|
}
|
}
|
|
export default CheckCard
|