king
2025-01-05 fd47b0ad8062eee8af364c656b59a5378ef918ae
src/templates/zshare/verifycard/uniqueform/index.jsx
@@ -1,55 +1,33 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Row, Col, Select, Button } from 'antd'
import './index.scss'
// import './index.scss'
class UniqueForm extends Component {
  static propTpyes = {
    dict: PropTypes.object,       // 字典项
    btn: PropTypes.object,
    fields: PropTypes.array,      // 表单字段
    uniqueChange: PropTypes.func  // 修改函数
  }
  state = {
    editItem: null // 编辑元素
  }
  edit = (record) => {
    this.setState({
      editItem: record
    })
    this.props.form.setFieldsValue({
      field: record.field.split(','),
      errorCode: record.errorCode,
      verifyType: record.verifyType || 'physical'
    })
  }
  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.props.uniqueChange(values)
        this.setState({
          editItem: null
        })
        this.props.form.setFieldsValue({
          field: [],
        })
@@ -59,7 +37,7 @@
  render() {
    const { getFieldDecorator } = this.props.form
    const { fields } = this.props
    const { fields, btn } = this.props
    const formItemLayout = {
      labelCol: {
@@ -75,35 +53,33 @@
    return (
      <Form {...formItemLayout} className="verify-form" id="verifycard1">
        <Row gutter={24}>
          <Col span={10}>
            <Form.Item label={'字段名'}>
          <Col span={7}>
            <Form.Item label="字段名">
              {getFieldDecorator('field', {
                initialValue: [],
                rules: [
                  {
                    required: true,
                    message: this.props.dict['form.required.select'] + '字段名!'
                    message: '请选择字段名!'
                  }
                ]
              })(
                <Select
                  mode="multiple"
                >
                <Select 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}(${item.field})`}</Select.Option>
                  ))}
                </Select>
              )}
            </Form.Item>
          </Col>
          <Col span={6}>
            <Form.Item label={'报错编码'}>
          {btn.Ot !== 'requiredOnce' ? <Col span={7}>
            <Form.Item label="报错编码">
              {getFieldDecorator('errorCode', {
                initialValue: 'E',
                rules: [
                  {
                    required: true,
                    message: this.props.dict['form.required.select'] + '报错编码!'
                    message: '请选择报错编码!'
                  }
                ]
              })(
@@ -115,28 +91,28 @@
                </Select>
              )}
            </Form.Item>
          </Col>
          <Col span={6}>
            <Form.Item label={'验证类型'}>
          </Col> : null}
          {btn.Ot !== 'requiredOnce' ? <Col span={7}>
            <Form.Item label="验证类型">
              {getFieldDecorator('verifyType', {
                initialValue: 'physical',
                initialValue: 'logic',
                rules: [
                  {
                    required: true,
                    message: this.props.dict['form.required.select'] + '验证类型!'
                    message: '请选择验证类型!'
                  }
                ]
              })(
                <Select>
                  <Select.Option value="physical"> 物理验证 </Select.Option>
                  <Select.Option value="logic"> 逻辑验证 </Select.Option>
                  <Select.Option value="physical"> 物理验证 </Select.Option>
                </Select>
              )}
            </Form.Item>
          </Col>
          <Col span={2} className="add">
            <Button onClick={this.handleConfirm} type="primary" className="add-row">
              确定
          </Col> : null}
          <Col span={3} className="add">
            <Button onClick={this.handleConfirm} className="mk-green">
              添加
            </Button>
          </Col>
        </Row>