From c7aece35a62b6e91fd98a625bf0e53f64bfbd18d Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 17 八月 2023 16:22:15 +0800
Subject: [PATCH] 2023-08-17

---
 src/templates/sharecomponent/fieldscomponent/editcard/index.jsx |  112 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 72 insertions(+), 40 deletions(-)

diff --git a/src/templates/sharecomponent/fieldscomponent/editcard/index.jsx b/src/templates/sharecomponent/fieldscomponent/editcard/index.jsx
index 2d89188..4387911 100644
--- a/src/templates/sharecomponent/fieldscomponent/editcard/index.jsx
+++ b/src/templates/sharecomponent/fieldscomponent/editcard/index.jsx
@@ -1,5 +1,7 @@
 import React, {Component} from 'react'
-import { Row, Col, Icon, Radio, Input, Button } from 'antd'
+import { is, fromJS } from 'immutable'
+import { Row, Col, Radio, Input, Button } from 'antd'
+import { CheckOutlined } from '@ant-design/icons'
 import './index.scss'
 
 const { Search } = Input
@@ -9,18 +11,25 @@
     super(props)
 
     let _type = props.card.type
-    if (props.type === 'columns') {
-      if (_type === 'date' || _type === 'datetime') {
-        _type = 'text'
+
+    if (!props.card.origin) {
+      if (props.type === 'columns') {
+        if (_type !== 'number') {
+          _type = 'text'
+        }
+      } else if (props.type === 'search') {
+        if (_type === 'date' || _type === 'datetime') {
+          _type = 'date'
+        } else if (_type !== 'select') {
+          _type = 'text'
+        }
+      } else if (props.type === 'form') {
+        if (_type === 'datetime' || _type === 'date') {
+          _type = 'date'
+        } else if (_type !== 'number') {
+          _type = 'text'
+        }
       }
-    } else if (props.type === 'search') {
-      if (_type === 'number') {
-        _type = 'text'
-      } else if (_type === 'datetime') {
-        _type = 'daterange'
-      }
-    } else if (props.type === 'form') {
-      
     }
 
     this.state = {
@@ -29,8 +38,21 @@
     }
   }
 
+  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}
     }, () => {
@@ -40,38 +62,40 @@
 
   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>
+          <CheckOutlined />
+          <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 value="date">date</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>
@@ -88,18 +112,31 @@
     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)
@@ -107,42 +144,37 @@
 
     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="璇疯緭鍏ュ瓧娈�" autoFocus 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 {

--
Gitblit v1.8.0