king
2020-11-24 0f79daefced8980fa571dd3d2c781a0e3646614f
src/templates/zshare/verifycard/uniqueform/index.jsx
@@ -3,7 +3,6 @@
import { Form, Row, Col, Select, Button } from 'antd'
import './index.scss'
class UniqueForm extends Component {
  static propTpyes = {
    btn: PropTypes.object,       // 字典项
@@ -12,53 +11,24 @@
    uniqueChange: PropTypes.func  // 修改函数
  }
  state = {
    editItem: null // 编辑元素
  }
  edit = (record) => {
    const { btn } = this.props
    this.setState({
      editItem: record
    })
    let _value = {
      field: record.field.split(',')
    }
    if (btn.Ot !== 'requiredOnce') {
      _value.errorCode = record.errorCode
      _value.verifyType = record.verifyType || 'physical'
    }
    this.props.form.setFieldsValue(_value)
  }
  handleConfirm = () => {
    const { fields } = this.props
    let change = {}
    fields.forEach(col => {
      change[col.field] = col.label
    })
    // 表单提交时检查输入值是否正确
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        values.uuid = this.state.editItem ? this.state.editItem.uuid : ''
        values.fieldlabel = values.field.map(field => {
          let item = fields.filter(cell => cell.field === field)[0]
          let label = ''
          if (item) {
            label = item.label
          }
          return label
          return change[field] || ''
        })
        values.fieldlabel = values.fieldlabel.join(',')
        values.field = values.field.join(',')
        this.setState({
          editItem: null
        }, () => {
          this.props.uniqueChange(values)
        })
        this.props.form.setFieldsValue({
          field: [],
        })
@@ -84,7 +54,7 @@
    return (
      <Form {...formItemLayout} className="verify-form" id="verifycard1">
        <Row gutter={24}>
          <Col span={8}>
          <Col span={7}>
            <Form.Item label={'字段名'}>
              {getFieldDecorator('field', {
                initialValue: [],
@@ -99,13 +69,13 @@
                  mode="multiple"
                >
                  {fields.map(item => (
                    <Select.Option key={item.uuid} value={item.field}>{item.field}</Select.Option>
                    <Select.Option key={item.uuid} value={item.field}>{item.label}</Select.Option>
                  ))}
                </Select>
              )}
            </Form.Item>
          </Col>
          {btn.Ot !== 'requiredOnce' ? <Col span={6}>
          {btn.Ot !== 'requiredOnce' ? <Col span={7}>
            <Form.Item label={'报错编码'}>
              {getFieldDecorator('errorCode', {
                initialValue: 'E',
@@ -125,7 +95,7 @@
              )}
            </Form.Item>
          </Col> : null}
          {btn.Ot !== 'requiredOnce' ? <Col span={6}>
          {btn.Ot !== 'requiredOnce' ? <Col span={7}>
            <Form.Item label={'验证类型'}>
              {getFieldDecorator('verifyType', {
                initialValue: 'physical',
@@ -143,9 +113,9 @@
              )}
            </Form.Item>
          </Col> : null}
          <Col span={4} className="add">
          <Col span={3} className="add">
            <Button onClick={this.handleConfirm} className="mk-green">
              保存
              {this.props.dict['model.add']}
            </Button>
          </Col>
        </Row>