king
2020-11-24 0f79daefced8980fa571dd3d2c781a0e3646614f
src/templates/zshare/verifycard/index.jsx
@@ -13,11 +13,13 @@
import CustomScript from './customscript'
import BillcodeForm from './billcodeform'
import VoucherForm from './voucherform'
import asyncComponent from '@/utils/asyncComponent'
import './index.scss'
const { TabPane } = Tabs
const { confirm } = Modal
const { Paragraph } = Typography
const EditTable = asyncComponent(() => import('@/templates/zshare/editTable'))
class VerifyCard extends Component {
  static propTpyes = {
@@ -43,25 +45,50 @@
    columnsFields: [],
    uniqueColumns: [
      {
        title: '字段名',
        title: '名称',
        dataIndex: 'fieldlabel',
        width: '20%'
      },
      {
        title: '字段',
        dataIndex: 'field',
        width: '35%'
        width: '20%',
        editable: true,
        inputType: 'multiStr',
        options: []
      },
      {
        title: '报错编码',
        dataIndex: 'errorCode',
        width: '12%'
        width: '12%',
        editable: true,
        inputType: 'select',
        options: [
          { value: 'E', text: 'E' },
          { value: 'N', text: 'N' },
          { value: 'F', text: 'F' },
          { value: 'NM', text: 'NM' }
        ]
      },
      {
        title: '验证类型',
        dataIndex: 'verifyType',
        width: '13%',
        render: (text, record) => record.verifyType === 'logic' ? '逻辑验证' : '物理验证'
        render: (text, record) => record.verifyType === 'logic' ? '逻辑验证' : '物理验证',
        inputType: 'select',
        editable: true,
        options: [
          { value: 'physical', text: '物理验证' },
          { value: 'logic', text: '逻辑验证' }
        ]
      },
      {
        title: '状态',
        title: '是否启用',
        dataIndex: 'status',
        width: '15%',
        width: '13%',
        editable: true,
        required: false,
        inputType: 'switch',
        render: (text, record) => record.status === 'false' ?
          (
            <div>
@@ -75,38 +102,29 @@
              <Icon style={{marginLeft: '5px'}} type="check-circle" theme="twoTone" twoToneColor="#52c41a" />
            </div>
          )
      },
      {
        title: '操作',
        align: 'center',
        width: '25%',
        dataIndex: 'operation',
        render: (text, record) =>
          (<div>
            <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record, 'unique')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <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>
            <Popconfirm
              overlayClassName="popover-confirm"
              title={this.props.dict['model.query.delete']}
              onConfirm={() => this.handleDelete(record, 'unique')
            }>
              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
            </Popconfirm>
          </div>)
      }
    ],
    onceUniqueColumns: [
      {
        title: '字段名',
        dataIndex: 'field',
        width: '45%'
        title: '名称',
        dataIndex: 'fieldlabel',
        width: '30%'
      },
      {
        title: '状态',
        dataIndex: 'status',
        title: '字段',
        dataIndex: 'field',
        width: '30%',
        editable: true,
        inputType: 'multiStr',
        options: []
      },
      {
        title: '是否启用',
        dataIndex: 'status',
        width: '20%',
        editable: true,
        required: false,
        inputType: 'switch',
        render: (text, record) => record.status === 'false' ?
          (
            <div>
@@ -121,57 +139,66 @@
            </div>
          )
      },
      {
        title: '操作',
        align: 'center',
        width: '25%',
        dataIndex: 'operation',
        render: (text, record) =>
          (<div>
            <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record, 'unique')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <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>
            <Popconfirm
              overlayClassName="popover-confirm"
              title={this.props.dict['model.query.delete']}
              onConfirm={() => this.handleDelete(record, 'unique')
            }>
              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
            </Popconfirm>
          </div>)
      }
    ],
    contrastColumns: [
      {
        title: '内容1',
        dataIndex: 'frontfield',
        width: '13%'
        width: '14%',
        inputType: 'input',
        editable: true
      },
      {
        title: '运算符',
        dataIndex: 'operator',
        width: '13%'
        width: '14%',
        editable: true,
        inputType: 'select',
        options: [
          { value: '=', text: '=' },
          { value: '!=', text: '!=' },
          { value: '>', text: '>' },
          { value: '<', text: '<' },
          { value: '>=', text: '>=' },
          { value: '<=', text: '<=' },
          { value: 'in', text: 'in' },
          { value: 'like', text: 'like' }
        ]
      },
      {
        title: '内容2',
        dataIndex: 'backfield',
        width: '13%',
        width: '14%',
        inputType: 'input',
        editable: true
      },
      {
        title: '提示信息',
        dataIndex: 'errmsg',
        width: '13%'
        width: '14%',
        inputType: 'input',
        editable: true
      },
      {
        title: '报错编码',
        dataIndex: 'errorCode',
        width: '13%'
        width: '14%',
        editable: true,
        inputType: 'select',
        options: [
          { value: 'E', text: 'E' },
          { value: 'N', text: 'N' },
          { value: 'F', text: 'F' },
          { value: 'NM', text: 'NM' }
        ]
      },
      {
        title: '状态',
        title: '是否启用',
        dataIndex: 'status',
        width: '15%',
        width: '13%',
        editable: true,
        required: false,
        inputType: 'switch',
        render: (text, record) => record.status === 'false' ?
          (
            <div>
@@ -185,26 +212,6 @@
              <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['model.edit']} onClick={() => this.handleEdit(record, 'contrast')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <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>
            <Popconfirm
              overlayClassName="popover-confirm"
              title={this.props.dict['model.query.delete']}
              onConfirm={() => this.handleDelete(record, 'contrast')
            }>
              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
            </Popconfirm>
          </div>)
      }
    ],
    customColumns: [
@@ -779,7 +786,19 @@
        columnsFields: _columns,
        initsql: _sql,
        defaultsql: _defaultsql,
        usefulfields: _usefulfields.join(', ')
        usefulfields: _usefulfields.join(', '),
        uniqueColumns: this.state.uniqueColumns.map(col => {
          if (col.dataIndex === 'field') {
            col.options = _fields
          }
          return col
        }),
        onceUniqueColumns: this.state.onceUniqueColumns.map(col => {
          if (col.dataIndex === 'field') {
            col.options = _columns
          }
          return col
        })
      })
    })
  }
@@ -885,18 +904,9 @@
  contrastChange = (values) => {
    let verify = fromJS(this.state.verify).toJS()
    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)
    }
    values.status = 'true'
    values.uuid = Utils.getuuid()
    verify.contrasts.push(values)
    this.setState({ verify })
  }
@@ -980,14 +990,10 @@
    if (type === 'customverify') {
      verify.customverifys = verify.customverifys.filter(item => item.uuid !== record.uuid)
    } else if (type === 'unique') {
      verify.uniques = verify.uniques.filter(item => item.uuid !== record.uuid)
    } else if (type === 'ordercode') {
      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 })
@@ -996,14 +1002,10 @@
  handleEdit = (record, type) => {
    if (type === 'customverify') {
      this.customForm.edit(record)
    } else if (type === 'unique') {
      this.uniqueForm.edit(record)
    } else if (type === 'ordercode') {
      this.orderForm.edit(record)
    } else if (type === 'scripts') {
      this.scriptsForm.edit(record)
    } else if (type === 'contrast') {
      this.contrastForm.edit(record)
    }
    let node = document.getElementById('verify-card-box-tab').parentNode
@@ -1028,22 +1030,6 @@
    if (type === 'customverify') {
      verify.customverifys = verify.customverifys.map(item => {
        if (item.uuid === record.uuid) {
          return record
        } else {
          return item
        }
      })
    } 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 {
@@ -1091,40 +1077,6 @@
        verify.customverifys.splice(index - 1, 0, record)
      } else {
        verify.customverifys.splice(index + 1, 0, record)
      }
    } else if (type === 'unique') {
      verify.uniques = verify.uniques.filter((item, i) => {
        if (item.uuid === record.uuid) {
          index = i
        }
        return item.uuid !== record.uuid
      })
      if ((index === 0 && direction === 'up') || (index === verify.uniques.length && direction === 'down')) {
        return
      }
      if (direction === 'up') {
        verify.uniques.splice(index - 1, 0, record)
      } 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
        }
        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) => {
@@ -1217,6 +1169,40 @@
    })
  }
  changeUniques = (uniques) => {
    const { card } = this.props
    const { verify, fields, columnsFields } = this.state
    let _fields = []
    let change = {}
    if (card.Ot !== 'requiredOnce') {
      _fields = fields
    } else {
      _fields = columnsFields
    }
    _fields.forEach(col => {
      change[col.field] = col.label
    })
    uniques = uniques.map(item => {
      item.status = item.status || 'true'
      if (Array.isArray(item.field)) {
        item.fieldlabel = item.field.map(field => {
          return change[field] || ''
        })
        item.fieldlabel = item.fieldlabel.join(',')
        item.field = item.field.join(',')
      }
      return item
    })
    this.setState({verify: {...verify, uniques}})
  }
  handleConfirm = () => {
    const { card } = this.props
    let verify = fromJS(this.state.verify).toJS()
@@ -1235,13 +1221,9 @@
      let _loading = false
      if (this.customForm && this.customForm.state.editItem) {
        _loading = true
      } else if (this.uniqueForm && this.uniqueForm.state.editItem) {
        _loading = true
      } else if (this.orderForm && this.orderForm.state.editItem) {
        _loading = true
      } else if (this.scriptsForm && this.scriptsForm.state.editItem) {
        _loading = true
      } else if (this.contrastForm && this.contrastForm.state.editItem) {
        _loading = true
      }
@@ -1383,19 +1365,8 @@
              {verify.contrasts.length ? <span className="count-tip">{verify.contrasts.length}</span> : null}
            </span>
          } 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}
            />
            <ContrastForm dict={this.props.dict} contrastChange={this.contrastChange}/>
            <EditTable data={verify.contrasts} columns={contrastColumns} onChange={(contrasts) => this.setState({verify: {...verify, contrasts}})}/>
          </TabPane>
          <TabPane tab={
            <span>
@@ -1457,16 +1428,8 @@
              fields={card.Ot !== 'requiredOnce' ? fields : columnsFields}
              dict={this.props.dict}
              uniqueChange={this.uniqueChange}
              wrappedComponentRef={(inst) => this.uniqueForm = inst}
            />
            <Table
              bordered
              rowKey="uuid"
              className="custom-table"
              dataSource={verify.uniques}
              columns={card.Ot !== 'requiredOnce' ? uniqueColumns : onceUniqueColumns}
              pagination={false}
            />
            <EditTable data={verify.uniques} columns={card.Ot !== 'requiredOnce' ? uniqueColumns : onceUniqueColumns} onChange={this.changeUniques}/>
          </TabPane>
          <TabPane tab={
            <span>