king
2020-02-05 b4744510a44b2f59b7ecece75085d4b70da2b059
src/templates/tableshare/verifycard/index.jsx
@@ -7,6 +7,7 @@
import Utils from '@/utils/utils.js'
import UniqueForm from './uniqueform'
import ContrastForm from './contrastform'
import CustomForm from './customform'
import CustomScript from './customscript'
import BillcodeForm from './billcodeform'
@@ -26,6 +27,7 @@
  state = {
    verify: {},
    fields: [],
    usefulfields: '',
    orderModular: [],
    orderModularDetail: [],
    voucher: [],
@@ -34,12 +36,18 @@
      {
        title: '字段名',
        dataIndex: 'field',
        width: '45%'
        width: '35%'
      },
      {
        title: '报错编码',
        dataIndex: 'errorCode',
        width: '15%'
        width: '12%'
      },
      {
        title: '验证类型',
        dataIndex: 'verifyType',
        width: '13%',
        render: (text, record) => record.verifyType === 'logic' ? '逻辑验证' : '物理验证'
      },
      {
        title: '状态',
@@ -78,6 +86,72 @@
            <span className="operation-btn" title={this.props.dict['header.form.up']} onClick={() => this.handleUpDown(record, 'unique', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
            <span className="operation-btn" title={this.props.dict['header.form.down']} onClick={() => this.handleUpDown(record, 'unique', 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span>
            <span className="operation-btn" title={this.props.dict['header.form.status.change']} onClick={() => this.handleStatus(record, 'unique')} style={{color: '#8E44AD'}}><Icon type="swap" /></span>
          </div>)
      }
    ],
    contrastColumns: [
      {
        title: '内容1',
        dataIndex: 'frontfield',
        width: '13%'
      },
      {
        title: '运算符',
        dataIndex: 'operator',
        width: '13%'
      },
      {
        title: '内容2',
        dataIndex: 'backfield',
        width: '13%',
      },
      {
        title: '提示信息',
        dataIndex: 'errmsg',
        width: '13%'
      },
      {
        title: '报错编码',
        dataIndex: 'errorCode',
        width: '13%'
      },
      {
        title: '状态',
        dataIndex: 'status',
        width: '15%',
        render: (text, record) => record.status === 'false' ?
          (
            <div>
              {this.props.dict['header.form.status.forbidden']}
              <Icon style={{marginLeft: '5px'}} type="stop" theme="twoTone" twoToneColor="#ff4d4f" />
            </div>
          ) :
          (
            <div>
              {this.props.dict['header.form.status.open']}
              <Icon style={{marginLeft: '5px'}} type="check-circle" theme="twoTone" twoToneColor="#52c41a" />
            </div>
          )
      },
      {
        title: '操作',
        align: 'center',
        width: '20%',
        dataIndex: 'operation',
        render: (text, record) =>
          (<div>
            <span className="operation-btn" title={this.props.dict['header.edit']} onClick={() => this.handleEdit(record, 'contrast')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <Popconfirm
              title={this.props.dict['header.form.query.delete']}
              okText={this.props.dict['header.confirm']}
              cancelText={this.props.dict['header.cancel']}
              onConfirm={() => this.handleDelete(record, 'contrast')
            }>
              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
            </Popconfirm>
            <span className="operation-btn" title={this.props.dict['header.form.up']} onClick={() => this.handleUpDown(record, 'contrast', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
            <span className="operation-btn" title={this.props.dict['header.form.down']} onClick={() => this.handleUpDown(record, 'contrast', 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span>
            <span className="operation-btn" title={this.props.dict['header.form.status.change']} onClick={() => this.handleStatus(record, 'contrast')} style={{color: '#8E44AD'}}><Icon type="swap" /></span>
          </div>)
      }
    ],
@@ -190,7 +264,7 @@
    ],
    orderColumns: [
      {
        title: '函数变量',
        title: this.props.dict['header.form.funcvar'],
        dataIndex: 'fieldName',
        width: '13%',
        render: (text, record) => (`${record.fieldName || ''}(${record.field})`)
@@ -282,12 +356,14 @@
  }
  UNSAFE_componentWillMount() {
    const { columns } = this.props
    let _verify = this.props.card.verify || {}
    this.setState({
      verify: {
        invalid: _verify.invalid || 'false',
        uniques: _verify.uniques || [],
        contrasts: _verify.contrasts || [],
        accountdate: _verify.accountdate || 'false',
        customverifys: _verify.customverifys || [],
        billcodes: _verify.billcodes || [],
@@ -325,8 +401,28 @@
            _fields = _LongParam.fields
          }
          let _usefulfields = []
          _fields.forEach(_f => {
            if (_f.field) {
              _usefulfields.push(_f.field)
            }
          })
          if (columns && columns.length > 0) {
            columns.forEach(_f => {
              if (_f.field) {
                _usefulfields.push(_f.field)
              }
            })
          }
          _usefulfields = Array.from(new Set(_usefulfields))
          _usefulfields = _usefulfields.join(', ')
          this.setState({
            fields: _fields
            fields: _fields,
            usefulfields: _usefulfields
          })
        } else {
          notification.warning({
@@ -488,6 +584,27 @@
    })
  }
  contrastChange = (values) => {
    let verify = JSON.parse(JSON.stringify(this.state.verify))
    if (values.uuid) {
      verify.contrasts = verify.contrasts.map(item => {
        if (item.uuid === values.uuid) {
          return values
        } else {
          return item
        }
      })
    } else {
      values.uuid = Utils.getuuid()
      verify.contrasts.push(values)
    }
    this.setState({
      verify: verify
    })
  }
  customChange = (values) => {
    let verify = JSON.parse(JSON.stringify(this.state.verify))
@@ -571,6 +688,8 @@
      verify.billcodes = verify.billcodes.filter(item => item.uuid !== record.uuid)
    } else if (type === 'scripts') {
      verify.scripts = verify.scripts.filter(item => item.uuid !== record.uuid)
    } else if (type === 'contrast') {
      verify.contrasts = verify.contrasts.filter(item => item.uuid !== record.uuid)
    }
    this.setState({ verify: verify })
@@ -585,6 +704,8 @@
      this.orderForm.edit(record)
    } else if (type === 'scripts') {
      this.scriptsForm.edit(record)
    } else if (type === 'contrast') {
      this.contrastForm.edit(record)
    }
  }
@@ -602,6 +723,14 @@
      })
    } else if (type === 'unique') {
      verify.uniques = verify.uniques.map(item => {
        if (item.uuid === record.uuid) {
          return record
        } else {
          return item
        }
      })
    } else if (type === 'contrast') {
      verify.contrasts = verify.contrasts.map(item => {
        if (item.uuid === record.uuid) {
          return record
        } else {
@@ -652,10 +781,6 @@
      } else {
        verify.customverifys.splice(index + 1, 0, record)
      }
      this.setState({
        verify: verify
      })
    } else if (type === 'unique') {
      verify.uniques = verify.uniques.filter((item, i) => {
        if (item.uuid === record.uuid) {
@@ -673,10 +798,23 @@
      } else {
        verify.uniques.splice(index + 1, 0, record)
      }
    } else if (type === 'contrast') {
      verify.contrasts = verify.contrasts.filter((item, i) => {
        if (item.uuid === record.uuid) {
          index = i
        }
  
      this.setState({
        verify: verify
        return item.uuid !== record.uuid
      })
      if ((index === 0 && direction === 'up') || (index === verify.contrasts.length && direction === 'down')) {
        return
      }
      if (direction === 'up') {
        verify.contrasts.splice(index - 1, 0, record)
      } else {
        verify.contrasts.splice(index + 1, 0, record)
      }
    } else if (type === 'ordercode') {
      verify.billcodes = verify.billcodes.filter((item, i) => {
        if (item.uuid === record.uuid) {
@@ -694,10 +832,6 @@
      } else {
        verify.billcodes.splice(index + 1, 0, record)
      }
      this.setState({
        verify: verify
      })
    } else if (type === 'scripts') {
      verify.scripts = verify.scripts.filter((item, i) => {
        if (item.uuid === record.uuid) {
@@ -715,11 +849,11 @@
      } else {
        verify.scripts.splice(index + 1, 0, record)
      }
    }
  
      this.setState({
        verify: verify
      })
    }
  }
  voucherChange = (voucher) => {
@@ -771,8 +905,7 @@
  }
  render() {
    // const { getFieldDecorator } = this.props.form
    const { verify, fields, uniqueColumns, customColumns, orderColumns, scriptsColumns, orderModular, orderModularDetail, voucher, voucherDetail } = this.state
    const { verify, fields, uniqueColumns, contrastColumns, customColumns, orderColumns, scriptsColumns, orderModular, orderModularDetail, voucher, voucherDetail } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
@@ -808,6 +941,21 @@
            </Row>
          </Form>
        </TabPane>
        <TabPane tab="比较验证" key="2x">
          <ContrastForm
            dict={this.props.dict}
            contrastChange={this.contrastChange}
            wrappedComponentRef={(inst) => this.contrastForm = inst}
          />
          <Table
            bordered
            rowKey="uuid"
            className="custom-table"
            dataSource={verify.contrasts}
            columns={contrastColumns}
            pagination={false}
          />
        </TabPane>
        <TabPane tab="唯一性验证" key="2">
          <UniqueForm
            fields={fields}
@@ -827,6 +975,7 @@
        <TabPane tab="自定义验证" key="3">
          <CustomForm
            dict={this.props.dict}
            usefulfields={this.state.usefulfields}
            customChange={this.customChange}
            wrappedComponentRef={(inst) => this.customForm = inst}
          />
@@ -873,7 +1022,7 @@
        </TabPane>
        <TabPane tab="自定义脚本" key="6">
          <CustomScript
            fields={fields}
            usefulfields={this.state.usefulfields}
            dict={this.props.dict}
            scriptsChange={this.scriptsChange}
            wrappedComponentRef={(inst) => this.scriptsForm = inst}