king
2020-04-29 9b6ce1a5778c6e1a813237e87588c0052aae1bbb
src/templates/zshare/verifycard/index.jsx
@@ -13,6 +13,7 @@
import BillcodeForm from './billcodeform'
import VoucherForm from './voucherform'
import './index.scss'
import { fromJS } from 'immutable';
const { TabPane } = Tabs
const { confirm } = Modal
@@ -23,7 +24,7 @@
    btnTab: PropTypes.any,     // 表单标签页(按钮)参数
    config: PropTypes.any,     // 表单标签页参数
    dict: PropTypes.object,    // 字典项
    card: PropTypes.object,
    card: PropTypes.object,    // 按钮信息
    columns: PropTypes.array
  }
@@ -32,6 +33,7 @@
    verify: {},
    fields: [],
    usefulfields: '',
    defaultsql: '',         // 默认Sql
    orderModular: [],
    orderModularDetail: [],
    voucher: [],
@@ -79,13 +81,13 @@
        dataIndex: 'operation',
        render: (text, record) =>
          (<div>
            <span className="operation-btn" title={this.props.dict['header.edit']} onClick={() => this.handleEdit(record, 'unique')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <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
              title={this.props.dict['header.form.query.delete']}
              okText={this.props.dict['header.confirm']}
              okText={this.props.dict['model.confirm']}
              cancelText={this.props.dict['header.cancel']}
              onConfirm={() => this.handleDelete(record, 'unique')
            }>
@@ -145,13 +147,13 @@
        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>
            <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
              title={this.props.dict['header.form.query.delete']}
              okText={this.props.dict['header.confirm']}
              okText={this.props.dict['model.confirm']}
              cancelText={this.props.dict['header.cancel']}
              onConfirm={() => this.handleDelete(record, 'contrast')
            }>
@@ -206,13 +208,13 @@
        dataIndex: 'operation',
        render: (text, record) =>
          (<div>
            <span className="operation-btn" title={this.props.dict['header.edit']} onClick={() => this.handleEdit(record, 'customverify')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record, 'customverify')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <span className="operation-btn" title={this.props.dict['header.form.up']} onClick={() => this.handleUpDown(record, 'customverify', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
            <span className="operation-btn" title={this.props.dict['header.form.down']} onClick={() => this.handleUpDown(record, 'customverify', '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, 'customverify')} style={{color: '#8E44AD'}}><Icon type="swap" /></span>
            <Popconfirm
              title={this.props.dict['header.form.query.delete']}
              okText={this.props.dict['header.confirm']}
              okText={this.props.dict['model.confirm']}
              cancelText={this.props.dict['header.cancel']}
              onConfirm={() => this.handleDelete(record, 'customverify')
            }>
@@ -266,13 +268,13 @@
        dataIndex: 'operation',
        render: (text, record) =>
          (<div>
            <span className="operation-btn" title={this.props.dict['header.edit']} onClick={() => this.handleEdit(record, 'scripts')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record, 'scripts')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <span className="operation-btn" title={this.props.dict['header.form.up']} onClick={() => this.handleUpDown(record, 'scripts', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
            <span className="operation-btn" title={this.props.dict['header.form.down']} onClick={() => this.handleUpDown(record, 'scripts', '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, 'scripts')} style={{color: '#8E44AD'}}><Icon type="swap" /></span>
            <Popconfirm
              title={this.props.dict['header.form.query.delete']}
              okText={this.props.dict['header.confirm']}
              okText={this.props.dict['model.confirm']}
              cancelText={this.props.dict['header.cancel']}
              onConfirm={() => this.handleDelete(record, 'scripts')
            }>
@@ -370,13 +372,13 @@
        dataIndex: 'operation',
        render: (text, record) =>
          (<div>
            <span className="operation-btn" title={this.props.dict['header.edit']} onClick={() => this.handleEdit(record, 'ordercode')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record, 'ordercode')} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <span className="operation-btn" title={this.props.dict['header.form.up']} onClick={() => this.handleUpDown(record, 'ordercode', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
            <span className="operation-btn" title={this.props.dict['header.form.down']} onClick={() => this.handleUpDown(record, 'ordercode', '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, 'ordercode')} style={{color: '#8E44AD'}}><Icon type="swap" /></span>
            <Popconfirm
              title={this.props.dict['header.form.query.delete']}
              okText={this.props.dict['header.confirm']}
              okText={this.props.dict['model.confirm']}
              cancelText={this.props.dict['header.cancel']}
              onConfirm={() => this.handleDelete(record, 'ordercode')
            }>
@@ -414,7 +416,8 @@
      verify: _verify
    })
    if (this.props.card.btnType) { // 按钮-表单标签页
    // 按钮-表单标签页
    if (this.props.card.btnType) {
      let _fields = []
      config.groups.forEach(group => {
@@ -488,13 +491,118 @@
        Select ${_select.join(', ')}
      `
      // 默认sql
      let _insertsql = ''
      let _updatesql = ''
      if (this.props.card.sqlType === 'insert' || this.props.card.sqlType === 'insertOrUpdate') {
        let keys = []
        let values = []
        _fields.forEach(item => {
          if (!item.field) return
          keys.push(item.field.toLowerCase())
          values.push('@' + item.field)
        })
        if (config.setting.primaryKey && !keys.includes(config.setting.primaryKey.toLowerCase())) {
          keys.push(config.setting.primaryKey.toLowerCase())
          values.push('\'\'')
        }
        if (!keys.includes('createuserid')) {
          keys.push('createuserid')
          values.push('@userid@')
        }
        if (!keys.includes('createuser')) {
          keys.push('createuser')
          values.push('@username')
        }
        if (!keys.includes('createstaff')) {
          keys.push('createstaff')
          values.push('@fullname')
        }
        if (!keys.includes('bid')) {
          keys.push('bid')
          values.push('@BID@')
        }
        keys = keys.join(',')
        values = values.join(',')
        _insertsql = `insert into ${this.props.card.sql} (${keys}) select ${values};`
      }
      if (this.props.card.sqlType === 'update' || this.props.card.sqlType === 'insertOrUpdate') {
        let _form = []
        let _arr = []
        _fields.forEach(item => {
          if (!item.field) return
          _arr.push(item.field.toLowerCase())
          _form.push(item.field + '=@' + item.field)
        })
        if (!_arr.includes('modifydate')) {
          _form.push('modifydate=getdate()')
        }
        if (!_arr.includes('modifyuserid')) {
          _form.push('modifyuserid=@userid@')
        }
        if (_verify.voucher && _verify.voucher.enabled) {
          if (!_arr.includes('bvoucher')) {
            _form.push('BVoucher=@BVoucher')
          }
          if (!_arr.includes('fibvoucherdate')) {
            _form.push('FIBVoucherDate=@FIBVoucherDate')
          }
          if (!_arr.includes('fiyear')) {
            _form.push('FiYear=@FiYear')
          }
        }
        let primaryKeyName = config.setting.primaryKey
        if (primaryKeyName && ['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'].includes(primaryKeyName.toLowerCase())) {
          primaryKeyName = primaryKeyName + '@'
        }
        _form = _form.join(',')
        _updatesql = `update ${this.props.card.sql} set ${_form} where ${config.setting.primaryKey}=@${primaryKeyName};`
      }
      let _defaultsql = ''
      if (this.props.card.sqlType === 'insert') {
        _defaultsql = _insertsql
      } else if (this.props.card.sqlType === 'update') {
        _defaultsql = _updatesql
      } else if (this.props.card.sqlType === 'insertOrUpdate') {
        _defaultsql += `select @tbid=''
          select @tbid='X' from ${this.props.card.sql} where ${config.setting.primaryKey}=@ID@
          if @tbid=''
            begin
            ${_insertsql}
            end
          else
            begin
            ${_updatesql}
            end
        `
      }
      this.setState({
        fields: _fields,
        initsql: _sql,
        defaultsql: _defaultsql,
        usefulfields: _usefulfields
      }, () => {
        this.getsysScript()
      })
      return
    }
    // 通用按钮
    if (this.props.card.OpenType === 'pop') {
      Api.getSystemConfig({
        func: 'sPC_Get_LongParam',
@@ -511,7 +619,17 @@
            }
          }
  
          if (!_LongParam) return
          if (!_LongParam) {
            notification.warning({
              top: 92,
              message: '表单未添加或解析错误,请检查表单设置!',
              duration: 5
            })
            this.getsysScript()
            return
          }
          
          let _fields = []
          if (_LongParam.groups.length > 0) {
@@ -527,6 +645,7 @@
          let _select = ['@UserName=\'\'', '@FullName=\'\'', '@ErrorCode=\'\'', '@retmsg=\'\'']
          let hasBid = false
          let fieldArr = _usefulfields.map(_f => _f.toLowerCase())
          let _defaultfields = fromJS(_fields).toJS()
          _fields.forEach(_f => {
            if (_f.field) {
@@ -602,10 +721,89 @@
            Select ${_select.join(', ')}
          `
          // 默认sql
          let _defaultsql = ''
          if (this.props.card.sqlType === 'insert') {
            let keys = []
            let values = []
            _defaultfields.forEach(item => {
              if (!item.field) return
              keys.push(item.field.toLowerCase())
              values.push('@' + item.field)
            })
            if (config.setting.primaryKey && !keys.includes(config.setting.primaryKey.toLowerCase())) {
              keys.push(config.setting.primaryKey.toLowerCase())
              values.push('\'\'')
            }
            if (!keys.includes('createuserid')) {
              keys.push('createuserid')
              values.push('@userid@')
            }
            if (!keys.includes('createuser')) {
              keys.push('createuser')
              values.push('@username')
            }
            if (!keys.includes('createstaff')) {
              keys.push('createstaff')
              values.push('@fullname')
            }
            if (!keys.includes('bid')) {
              keys.push('bid')
              values.push('@BID@')
            }
            keys = keys.join(',')
            values = values.join(',')
            _defaultsql = `insert into ${this.props.card.sql} (${keys}) select ${values};`
          } else if (this.props.card.sqlType === 'update') {
            let _form = []
            let _arr = []
            _defaultfields.forEach(item => {
              if (!item.field) return
              _arr.push(item.field.toLowerCase())
              _form.push(item.field + '=@' + item.field)
            })
            if (!_arr.includes('modifydate')) {
              _form.push('modifydate=getdate()')
            }
            if (!_arr.includes('modifyuserid')) {
              _form.push('modifyuserid=@userid@')
            }
            if (_verify.voucher && _verify.voucher.enabled) {
              if (!_arr.includes('bvoucher')) {
                _form.push('BVoucher=@BVoucher')
              }
              if (!_arr.includes('fibvoucherdate')) {
                _form.push('FIBVoucherDate=@FIBVoucherDate')
              }
              if (!_arr.includes('fiyear')) {
                _form.push('FiYear=@FiYear')
              }
            }
            let primaryKeyName = config.setting.primaryKey
            if (primaryKeyName && ['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'].includes(primaryKeyName.toLowerCase())) {
              primaryKeyName = primaryKeyName + '@'
            }
            _form = _form.join(',')
            _defaultsql = `update ${this.props.card.sql} set ${_form} where ${config.setting.primaryKey}=@${primaryKeyName};`
          }
          this.setState({
            fields: _fields,
            initsql: _sql,
            defaultsql: _defaultsql,
            usefulfields: _usefulfields
          }, () => {
            this.getsysScript()
          })
        } else {
          notification.warning({
@@ -613,6 +811,7 @@
            message: res.message,
            duration: 5
          })
          this.getsysScript()
        }
      })
    } else {
@@ -652,9 +851,36 @@
        Select ${_select.join(', ')}
      `
      // 默认sql
      let _defaultsql = ''
      let primaryKeyName = config.setting.primaryKey
      if (primaryKeyName && ['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'].includes(primaryKeyName.toLowerCase())) {
        primaryKeyName = primaryKeyName + '@'
      }
      if (this.props.card.sqlType === 'LogicDelete') {
        _defaultsql = `update ${this.props.card.sql} set deleted=1,modifydate=getdate(),modifyuserid=@userid@ where ${config.setting.primaryKey}=@${primaryKeyName};`
      } else if (this.props.card.sqlType === 'delete') {
        let _msg = ''
        if (columns && columns.length > 0 && this.props.card.Ot !== 'notRequired') {
          let _index = 0
          columns.forEach(col => {
            if (col.field && col.Hide !== 'true' && _index < 4) {
              _msg += col.label + '=\'\','
              _index++
            }
          })
        }
        _defaultsql += `insert into snote (remark,createuserid,CreateUser,CreateStaff) select left('删除表:${this.props.card.sql} 数据: ${_msg}${config.setting.primaryKey}='+@${primaryKeyName},200),@userid@,@username,@fullname delete ${this.props.card.sql} where ${config.setting.primaryKey}=@${primaryKeyName};`
      }
      this.setState({
        initsql: _sql,
        defaultsql: _defaultsql,
        usefulfields: _usefulfields
      }, () => {
        this.getsysScript()
      })
    }
  }
@@ -785,7 +1011,11 @@
        voucherDetail: result[1].data
      })
    })
  }
  getsysScript = () => {
    const { defaultsql } = this.state
    let _scriptSql = `Select distinct func+Remark as funcname,longparam, s.Sort from  s_custom_script s inner join (select OpenID from sapp where ID=@Appkey@) p on s.openid = case when s.appkey='' then s.openid else p.OpenID end order by s.Sort`
    _scriptSql = Utils.formatOptions(_scriptSql)
@@ -802,13 +1032,26 @@
    
    Api.getSystemConfig(_sParam).then(res => {
      if (res.status) {
        this.setState({
          systemScripts: res.data.map(item => {
            return {
              name: item.funcname,
              value: Utils.formatOptions(item.longparam, true)
            }
        let _scripts = []
        if (defaultsql) {
          _scripts.push({
            name: '默认sql',
            value: defaultsql
          })
        }
        res.data.forEach(item => {
          let _item = {
            name: item.funcname,
            value: Utils.formatOptions(item.longparam, true)
          }
          _scripts.push(_item)
        })
        this.setState({
          systemScripts: _scripts
        })
      } else {
        notification.warning({
@@ -1216,7 +1459,7 @@
      if (_loading) {
        confirm({
          content: `存在未保存项,确定提交吗?`,
          okText: this.props.dict['header.confirm'],
          okText: this.props.dict['model.confirm'],
          cancelText: this.props.dict['header.cancel'],
          onOk() {
            resolve(verify)
@@ -1328,6 +1571,7 @@
          <TabPane tab="自定义验证" key="3">
            <CustomForm
              dict={this.props.dict}
              btn={this.props.card}
              initsql={this.state.initsql}
              usefulfields={this.state.usefulfields}
              customChange={this.customChange}
@@ -1379,6 +1623,7 @@
              usefulfields={this.state.usefulfields}
              initsql={this.state.initsql}
              dict={this.props.dict}
              btn={this.props.card}
              customScripts={verify.scripts}
              systemScripts={this.state.systemScripts}
              scriptsChange={this.scriptsChange}