king
2020-10-21 5423c7caa9723e0b232ea6c5ef4aaf90bd7a3334
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Col, Row } from 'antd'
 
import './index.scss'
 
class CheckCard extends Component {
  static propTpyes = {
    multiple: PropTypes.bool,    // 是否可多选
    ratio: PropTypes.string,     // 图片比例
    width: PropTypes.number,     // 宽度
    display: PropTypes.string,   // 显示为:text(文本)、picture(图片)
    fields: PropTypes.array,     // 字段集
    options: PropTypes.array,    // 数据列表
    onChange: PropTypes.func,    // 数据切换
  }
 
  state = {}
 
  getCards = () => {
    const { display, width, options, fields, ratio } = this.props
 
    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%'
    }
 
    if (display !== 'picture') {
      return options.map(item => {
        return <Col span={width} key={item.key}>
          <div className="card-cell">
            {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 {
      return options.map(item => {
        return <Col span={width} key={item.key}>
          <div className="card-pic-cell" 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