From cb9ade2afd2a367ad767bc605ab7086c695dd010 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 09 十二月 2022 15:53:32 +0800
Subject: [PATCH] 2022-12-09

---
 src/tabviews/zshare/mutilform/mkCheckCard/index.jsx |  112 ++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 77 insertions(+), 35 deletions(-)

diff --git a/src/tabviews/zshare/mutilform/mkCheckCard/index.jsx b/src/tabviews/zshare/mutilform/mkCheckCard/index.jsx
index d0b2c65..74100ed 100644
--- a/src/tabviews/zshare/mutilform/mkCheckCard/index.jsx
+++ b/src/tabviews/zshare/mutilform/mkCheckCard/index.jsx
@@ -2,6 +2,7 @@
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
 import { Col, Row } from 'antd'
+import { CheckOutlined } from '@ant-design/icons'
 
 import MKEmitter from '@/utils/events.js'
 import './index.scss'
@@ -19,15 +20,28 @@
   }
 
   UNSAFE_componentWillMount() {
-    const { config } = this.props
+    let config = fromJS(this.props.config).toJS()
 
     let selectKeys = config.initval
     if (config.multiple === 'true') {
       selectKeys = config.initval ? config.initval.split(',') : []
     }
 
+    if (!config.selectStyle && config.backgroundColor) {
+      config.selectStyle = 'custom'
+    } else if (!config.selectStyle) {
+      config.selectStyle = 'background'
+    }
+
+    if (config.display === 'picture' && !config.picratio) { // 鍏煎鏃ф暟鎹�
+      config.picratio = config.ratio || '1:1'
+    }
+
+    config.selectClass = ` mk-${config.selectStyle} `
+    config.fields = config.fields || []
+
     this.setState({
-      config: fromJS(config).toJS(),
+      config: config,
       options: fromJS(config.options).toJS(),
       selectKeys: selectKeys
     })
@@ -46,11 +60,11 @@
   }
 
   UNSAFE_componentWillReceiveProps (nextProps) {
-    const { config } = this.props
+    const { config } = this.state
 
     if (!is(fromJS(config.oriOptions), fromJS(nextProps.config.oriOptions))) {
       this.setState({
-        config: fromJS(nextProps.config).toJS(),
+        config: {...config, oriOptions: nextProps.config.oriOptions},
         options: fromJS(nextProps.config.options).toJS()
       })
     }
@@ -163,54 +177,76 @@
 
   getCards = () => {
     const { selectKeys, options, config } = this.state
-    const { display, width, fields, ratio, multiple, backgroundColor, borderColor } = config
+    const { display, width, fields, picratio, multiple, backgroundColor, selectStyle, selectClass } = config
 
-    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 = borderColor ? {borderColor} : {}
-    let _style = backgroundColor ? {backgroundColor} : null
-
-    if (!options || options.length === 0) {
+    if (options.length === 0) {
       return null
-    } else if (display !== 'picture') {
-      if (!fields || fields.length === 0) {
-        return null
-      }
+    } else if (display === 'color') {
       return options.map(item => {
         let _active = false
-        if (multiple === 'true' && selectKeys.includes(item.$value)) {
-          _active = true
-        } else if (multiple !== 'true' && selectKeys === item.$value) {
-          _active = true
+        if (multiple === 'true') {
+          _active = selectKeys.includes(item.$value)
+        } else {
+          _active = selectKeys === item.$value
         }
 
         return <Col span={width} key={item.key}>
-          <div className={'card-cell' + (_active ? ' active' : '') + (_style ? ' bg-control' : '') + (item.$disabled ? ' disabled' : '')} style={style} onClick={() => this.changeCard(item)}>
+          <div className={'card-color-cell' + (_active ? ' active' : '') + (item.$disabled ? ' disabled' : '')} style={{background: item.$value}} onClick={() => this.changeCard(item)}>
+            {fields.map(col => {
+              return <span className="content-line" key={col.key} style={{color: col.color, fontSize: col.fontSize + 'px', height: col.fontSize * 1.5 + 'px', textAlign: col.align}}>{item[col.field]}</span>
+            })}
+            <CheckOutlined />
+          </div>
+        </Col>
+      })
+    } else if (display !== 'picture') {
+      let _style = selectStyle === 'custom' ? {backgroundColor} : null
+
+      return options.map(item => {
+        let _active = false
+        if (multiple === 'true') {
+          _active = selectKeys.includes(item.$value)
+        } else {
+          _active = selectKeys === item.$value
+        }
+
+        return <Col span={width} key={item.key}>
+          <div className={'card-cell' + (_active ? ' active' : '') + selectClass + (item.$disabled ? ' disabled' : '')} onClick={() => this.changeCard(item)}>
             <div className="bg-mask" style={_style}></div>
             {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>
+              return <span className="content-line" 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 {
+      let paddingTop = '100%'
+      if (picratio === '4:3') {
+        paddingTop = '75%'
+      } else if (picratio === '3:2') {
+        paddingTop = '66.7%'
+      } else if (picratio === '16:9') {
+        paddingTop = '56.25%'
+      }
+
       return options.map(item => {
         let _active = false
-        if (multiple === 'true' && selectKeys.includes(item.$value)) {
-          _active = true
-        } else if (multiple !== 'true' && selectKeys === item.$value) {
-          _active = true
+        if (multiple === 'true') {
+          _active = selectKeys.includes(item.$value)
+        } else {
+          _active = selectKeys === item.$value
         }
 
         return <Col span={width} key={item.key}>
-          <div className={'card-pic-cell ' + (_active ? 'active' : '') + (item.$disabled ? ' disabled' : '')} onClick={() => this.changeCard(item)} style={{...style, paddingTop, backgroundImage: `url(${item.$url})`}}>
+          <div className={'card-pic-cell ' + (_active ? 'active' : '') + (item.$disabled ? ' disabled' : '')} onClick={() => this.changeCard(item)} style={{paddingTop, backgroundImage: `url(${item.$url})`}}>
+            <div className="content-wrap">
+              <div className="content-center">
+                {fields.map(col => {
+                  return <span className="content-line" 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>
+              <CheckOutlined />
+            </div>
           </div>
         </Col>
       })
@@ -218,10 +254,16 @@
   }
 
   render() {
-    const { config } = this.state
+    const { config, options } = this.state
+
+    let extend = config.readonly ? 'readonly' : ''
+
+    if (options.length * config.width > 24) {
+      extend += ' mutile-line'
+    }
 
     return (
-      <div className={'check-card-form-box' + (config.readonly ? ' readonly' : '')}>
+      <div className={'check-card-form-box ' + extend}>
         <Row gutter={12}>{this.getCards()}</Row>
       </div>
     )

--
Gitblit v1.8.0