king
2023-06-30 0519dcda8b6fb2914987f8d4d58e1d14bcf98dc3
src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
@@ -2,21 +2,19 @@
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Table, Typography, Modal, Input, InputNumber, Button, notification, message, Select } from 'antd'
import { EditOutlined } from '@ant-design/icons'
import { EditOutlined, QuestionCircleOutlined } from '@ant-design/icons'
import moment from 'moment'
import Api from '@/api'
import asyncComponent from '@/utils/asyncComponent'
import Utils, { getEditTableSql, getMark } from '@/utils/utils.js'
import MkIcon from '@/components/mk-icon'
import MKEmitter from '@/utils/events.js'
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import CusSwitch from './cusSwitch'
import Encrypts from '@/components/encrypts'
import './index.scss'
const { Paragraph } = Typography
const MkIcon = asyncComponent(() => import('@/components/mk-icon'))
const CardCellComponent = asyncComponent(() => import('@/tabviews/custom/components/card/cardcellList'))
class BodyRow extends React.Component {
@@ -121,7 +119,7 @@
    this.setState({editing: false})
    setTimeout(() => {
      if (col.enter === '$next') {
      if (/\$next/.test(col.enter)) {
        MKEmitter.emit('nextLine', col, record.$$uuid)
      } else if (col.enter === '$sub') {
        MKEmitter.emit('subLine', col, record)
@@ -210,7 +208,7 @@
    this.setState({editing: false})
    setTimeout(() => {
      if (col.enter === '$next') {
      if (/\$next/.test(col.enter)) {
        MKEmitter.emit('nextLine', col, record.$$uuid)
      } else if (col.enter === '$sub') {
        MKEmitter.emit('subLine', col, record)
@@ -220,15 +218,7 @@
      }
    }, 50)
    let values = {}
    if (col.editField) {
      values[col.field] = label
      values[col.editField] = val
    } else {
      values[col.field] = val
    }
    MKEmitter.emit('changeRecord', col.tableId, {...record, ...values})
    MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: val})
  }
  onSelectChange = (val, option) => {
@@ -244,18 +234,13 @@
        })
      }
      if (col.editField) {
        values[col.field] = _option.label
        values[col.editField] = val
      } else {
        values[col.field] = val
      }
      values[col.field] = val
    }
    this.setState({editing: false})
    setTimeout(() => {
      if (col.enter === '$next') {
      if (/\$next/.test(col.enter)) {
        MKEmitter.emit('nextLine', col, record.$$uuid)
      } else if (col.enter === '$sub') {
        MKEmitter.emit('subLine', col, record)
@@ -290,6 +275,10 @@
      let content = ''
      if (record[col.field] !== undefined) {
        content = `${record[col.field]}`
      }
      if (col.editType === 'select' && col.options.length > 0) {
        content = col.map.get(content) || content
      }
      if (content !== '') {
@@ -329,22 +318,14 @@
              <Input className={err ? 'has-error' : ''} title={err} id={col.uuid + record.$$uuid} defaultValue={value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
            </td>)
          } else if (col.editType === 'switch') {
            let _value = ''
            if (col.editField) {
              _value = record[col.editField] !== undefined ? record[col.editField] : ''
            } else {
              _value = record[col.field] !== undefined ? record[col.field] : ''
            }
            let _value = record[col.field] !== undefined ? record[col.field] : ''
            return (<td className="editing_table_cell">
              <CusSwitch config={col} defaultValue={_value} autoFocus={true} onChange={this.onSwitchChange} onBlur={this.switchBlur}/>
            </td>)
          } else {
            let _value = ''
            if (col.editField) {
              _value = record[col.editField] !== undefined ? record[col.editField] : ''
            } else {
              _value = record[col.field] !== undefined ? record[col.field] : ''
            }
            let _value = record[col.field] !== undefined ? record[col.field] : ''
            return (<td className="editing_table_cell">
              <Select
                showSearch
@@ -425,7 +406,7 @@
            val = ''
          }
          return (<td className="editing_table_cell">
            <InputNumber className={err ? 'has-error' : ''} title={err} id={col.uuid + record.$$uuid} defaultValue={val} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
            <InputNumber className={err ? 'has-error' : ''} precision={col.decimal || 0} title={err} id={col.uuid + record.$$uuid} defaultValue={val} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
          </td>)
        } else {
          return (<td className={className + ' pointer'} style={style}>
@@ -462,6 +443,10 @@
          // eslint-disable-next-line
          content = eval(content)
        } catch (e) {
          if (window.debugger) {
            console.info(content)
            console.warn(e)
          }
          content = ''
        }
      }
@@ -470,6 +455,11 @@
      if (col.noValue === 'hide' && content === 0) {
        content = ''
      }
      if (col.round && typeof(content) === 'number') {
        content = Math.round(content * col.round) / col.round
        content = content.toFixed(col.decimal)
      }
      if (content !== '') {
@@ -501,14 +491,6 @@
        style = {...style, ...col.style}
      }
      children = (
        <CardCellComponent data={record} cards={config} elements={col.elements}/>
      )
    } else if (col.type === 'action') {
      style.padding = '0px'
      if (col.style) {
        style = {...style, ...col.style}
      }
      children = (
        <CardCellComponent data={record} cards={config} elements={col.elements}/>
      )
@@ -560,7 +542,7 @@
    this.onBlur()
    setTimeout(() => {
      if (col.enter === '$next') {
      if (/\$next/.test(col.enter)) {
        MKEmitter.emit('nextLine', col, record.$$uuid)
      } else if (col.enter === '$sub') {
        MKEmitter.emit('subLine', col, record)
@@ -620,7 +602,7 @@
    const { col, record } = this.props
    setTimeout(() => {
      if (col.enter === '$next') {
      if (/\$next/.test(col.enter)) {
        MKEmitter.emit('nextLine', col, record.$$uuid)
      } else if (col.enter === '$sub') {
        MKEmitter.emit('subLine', col, record)
@@ -636,15 +618,7 @@
      }
    }, 50)
    let values = {}
    if (col.editField) {
      values[col.field] = label
      values[col.editField] = val
    } else {
      values[col.field] = val
    }
    MKEmitter.emit('changeRecord', col.tableId, {...record, ...values})
    MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: val})
  }
  onSelectChange = (val, option) => {
@@ -660,16 +634,11 @@
        })
      }
      if (col.editField) {
        values[col.field] = _option.label
        values[col.editField] = val
      } else {
        values[col.field] = val
      }
      values[col.field] = val
    }
    setTimeout(() => {
      if (col.enter === '$next') {
      if (/\$next/.test(col.enter)) {
        MKEmitter.emit('nextLine', col, record.$$uuid)
      } else if (col.enter === '$sub') {
        MKEmitter.emit('subLine', col, record)
@@ -702,12 +671,7 @@
    let children = null
    if (col.type === 'text') {
      if (col.editable === 'true' && !disabled) {
        let _value = ''
        if (col.editField) {
          _value = record[col.editField] !== undefined ? record[col.editField] : ''
        } else {
          _value = record[col.field] !== undefined ? record[col.field] : ''
        }
        let _value = record[col.field] !== undefined ? record[col.field] : ''
        
        if (!col.editType || col.editType === 'text') {
          children = (<>
@@ -736,6 +700,10 @@
        let content = ''
        if (record[col.field] !== undefined) {
          content = `${record[col.field]}`
        }
        if (col.editType === 'select' && col.options.length > 0) {
          content = col.map.get(content) || content
        }
        if (content !== '') {
@@ -767,6 +735,11 @@
            content = <span style={mark.innerStyle}>{content}</span>
          }
        }
        if (col.editable === 'true' && disabled) {
          content = <span style={{display: 'inline-block', padding: '0 6px'}}>{content}</span>
        }
        children = content
      }
    } else if (col.type === 'number') {
@@ -778,7 +751,7 @@
        }
        children = (<>
          <InputNumber className={err ? 'has-error' : ''} title={err} id={col.uuid + record.$$uuid} defaultValue={_value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
          <InputNumber className={err ? 'has-error' : ''} title={err} precision={col.decimal || 0} id={col.uuid + record.$$uuid} defaultValue={_value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
        </>)
      } else {
        let content = ''
@@ -829,6 +802,11 @@
            content = <span style={mark.innerStyle}>{content}</span>
          }
        }
        if (col.editable === 'true' && disabled) {
          content = <span style={{display: 'inline-block', padding: '0 6px'}}>{content}</span>
        }
        children = content
      }
    } else if (col.type === 'textarea') {
@@ -858,6 +836,10 @@
          // eslint-disable-next-line
          content = eval(content)
        } catch (e) {
          if (window.debugger) {
            console.info(content)
            console.warn(e)
          }
          content = ''
        }
      }
@@ -866,6 +848,11 @@
      if (col.noValue === 'hide' && content === 0) {
        content = ''
      }
      if (col.round && typeof(content) === 'number') {
        content = Math.round(content * col.round) / col.round
        content = content.toFixed(col.decimal)
      }
      if (content !== '') {
@@ -900,14 +887,6 @@
      children = (
        <CardCellComponent data={record} cards={config} elements={col.elements}/>
      )
    } else if (col.type === 'action') {
      style.padding = '0px'
      if (col.style) {
        style = {...style, ...col.style}
      }
      children = (
        <CardCellComponent data={record} cards={config} elements={col.elements}/>
      )
    }
    return (<td className={'editing_all_table_cell ' + className} style={style}>{children}</td>)
@@ -929,7 +908,6 @@
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    edData: [],
    selectedRowKeys: [],  // 表格中选中行
    tableId: '',          // 表格ID
@@ -940,7 +918,9 @@
    orderfields: {},      // 排序id与field转换
    loading: false,
    pageOptions: [],
    deForms: null
    deForms: null,
    visible: false,
    midData: null
  }
  UNSAFE_componentWillMount () {
@@ -967,17 +947,24 @@
              item.ctrlValue = item.ctrlValue.split(',')
            }
            
            if (item.type === 'text' && item.editType === 'select' && item.resourceType === '1') {
              let _option = Utils.getSelectQueryOptions(item)
              if (/@BID@/ig.test(_option.sql)) {
                hasBid = true
            if (item.type === 'text' && item.editType === 'select') {
              item.map = new Map()
              if (item.resourceType === '1') {
                let _option = Utils.getSelectQueryOptions(item)
                if (/@BID@/ig.test(_option.sql)) {
                  hasBid = true
                }
                item.base_sql = _option.sql
                item.arr_field = _option.field
                deForms.push(item)
              } else {
                item.options.forEach(cell => {
                  item.map.set(cell.value, cell.label)
                })
              }
              item.base_sql = _option.sql
              item.arr_field = _option.field
              deForms.push(item)
            }
          }
    
@@ -995,7 +982,7 @@
            onCell: record => ({
              record,
              col: item,
              config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
              config: item.type === 'custom' ? {setting, columns: fields} : null,
            })
          }
        }
@@ -1089,17 +1076,18 @@
  }
  transferData = (menuid, data, type) => {
    const { MenuID, setting } = this.props
    const { MenuID } = this.props
    const { edData } = this.state
    if (menuid !== MenuID) return
    if (type !== 'line') {
      this.setState({edData: data})
      let index = edData.findIndex(item => !item.$origin && !item.$forbid)
      if (setting.addable && data.length === 0) {
        setTimeout(() => {
          this.plusLine(true)
        }, 10)
      if (index > -1) {
        this.setState({visible: true, midData: data})
      } else {
        this.updateMutil(data)
      }
    } else if (type === 'line') {
      let _edData = this.state.edData.map(item => {
@@ -1111,6 +1099,24 @@
      })
      this.setState({edData: _edData})
    }
  }
  updateMutil = (data) => {
    const { setting } = this.props
    if (setting.editType === 'multi' && data.length > 0) {
      this.setState({edData: []}, () => {
        this.setState({edData: data, visible: false, midData: null})
      })
    } else {
      this.setState({edData: data, visible: false, midData: null})
    }
    if (setting.addable && data.length === 0) {
      setTimeout(() => {
        this.plusLine(true)
      }, 10)
    }
  }
@@ -1234,7 +1240,7 @@
  }
  resetFormList = (result) => {
    const { columns } = this.state
    const { columns, edData } = this.state
    let _edColumns = []
@@ -1242,7 +1248,6 @@
    this.props.columns.forEach(item => {
      if (item.resourceType === '1' && result[item.uuid] && result[item.uuid].length > 0) {
        let options = []
        let _map = new Map()
        let all = false
        result[item.uuid].forEach(cell => {
          let _cell = {key: Utils.getuuid()}
@@ -1259,8 +1264,8 @@
            }
          }
          if (_map.has(_cell.value)) return
          _map.set(_cell.value, 0)
          if (item.map.has(_cell.value)) return
          item.map.set(_cell.value, _cell.label)
          if (item.linkSubField) {
            item.linkSubField.forEach(m => {
@@ -1277,7 +1282,7 @@
        item.options = options
        reCols[item.uuid] = item
        reCols[item.uuid] = fromJS(item).toJS()
      }
    })
@@ -1292,8 +1297,8 @@
      return item
    })
    this.setState({columns: []}, () => {
      this.setState({columns: _edColumns})
    this.setState({columns: [], edData: []}, () => {
      this.setState({columns: _edColumns, edData: edData})
    })
  }
  
@@ -1307,7 +1312,12 @@
    let next = edData[index + 1] || null
    
    if (next) {
      let node = document.getElementById(setting.initId + next.$$uuid)
      let nextId = setting.initId + next.$$uuid
      if (/^\$next_/.test(col.enter)) {
        nextId = col.enter.split('_')[1] + next.$$uuid
      }
      let node = document.getElementById(nextId)
      if (node) {
        if (setting.editType === 'multi') {
          if (setting.triType === 'click') {
@@ -1399,19 +1409,18 @@
      let _data = edData.filter(item => item.$$uuid !== record.$$uuid)
      this.setState({edData: _data})
    } else {
      let _data = edData.map(item => {
      let _data = fromJS(edData).toJS().map(item => {
        if (item.$$uuid === record.$$uuid) {
          record.$deleted = true
          record.$origin = false
          record.$type = 'del'
          return record
        } else {
          return item
          item.$deleted = true
          item.$origin = false
          item.$type = 'del'
        }
        return item
      })
      this.setState({edData: _data}, () => {
        if (setting.commit === 'simple' && record.$deleted) {
        if (setting.commit === 'simple') {
          this.submit()
        }
      })
@@ -1603,6 +1612,8 @@
    const { submit, BID, setting } = this.props
    const { forms } = this.state
    this.setState({visible: false, midData: null})
    if (setting.supModule && !BID) {
      notification.warning({
        top: 92,
@@ -1660,7 +1671,9 @@
        } else {
          this.execError(res)
        }
      }, () => {
      }, (error) => {
        if (error && error.ErrCode === 'LoginError') return
        this.execError({})
      })
    } else if (submit.intertype === 'inner' && submit.innerFunc) { // 自定义存储过程
@@ -1672,50 +1685,44 @@
        } else {
          this.execError(res)
        }
      }, () => {
      }, (error) => {
        if (error && error.ErrCode === 'LoginError') return
        this.execError({})
      })
    }
  }
  updataLine = (item) => {
    if (item.$type === 'del') {
      let _data = this.state.edData.filter(m => m.$$uuid !== item.$$uuid)
      this.setState({edData: _data})
    } else {
      let _data = this.state.edData.map(m => {
        if (m.$$uuid === item.$$uuid) {
          item.$origin = true
          return item
        }
        return m
      })
      this.setState({edData: _data})
    }
    MKEmitter.emit('reloadData', this.props.MenuID, item.$$uuid, item)
  }
  execSuccess = (res) => {
    const { submit } = this.props
    const { edData } = this.state
    if (res && res.ErrCode === 'S') { // 执行成功
      notification.success({
        top: 92,
        message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
        message: res.ErrMesg || '执行成功',
        duration: submit.stime ? submit.stime : 2
      })
    } else if (res && res.ErrCode === 'Y') { // 执行成功
      Modal.success({
        title: res.ErrMesg || this.state.dict['main.action.confirm.success']
        title: res.ErrMesg || '执行成功'
      })
    } else if (res && res.ErrCode === '-1') { // 完成后不提示
    }
    let _edData = fromJS(edData).toJS()
    _edData = _edData.map(item => {
      if (!item.$forbid) {
        item.$origin = true
      }
      return item
    })
    this.setState({
      loading: false
      loading: false,
      edData: _edData
    })
    if (submit.closetab === 'true') {
@@ -1725,6 +1732,8 @@
    if (submit.execSuccess !== 'never') {
      MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execSuccess, submit)
    }
    submit.syncComponentId && MKEmitter.emit('reloadData', submit.syncComponentId)
  }
  execError = (res) => {
@@ -1862,7 +1871,7 @@
  render() {
    const { setting, lineMarks, submit } = this.props
    const { tableId, edData, columns, loading, pageOptions, selectedRowKeys } = this.state
    const { tableId, edData, columns, loading, pageOptions, selectedRowKeys, visible, midData } = this.state
    const components = {
      body: {
@@ -1871,7 +1880,6 @@
      }
    }
    // 数据收起时,过滤已选数据
    let _data = edData.filter(item => !item.$deleted)
    // 设置表格选择属性:单选、多选、不可选
@@ -1896,8 +1904,6 @@
      }
    }
    let _footer = ''
    let height = setting.height || false
    if (height && height <= 100) {
      height = height + 'vh'
@@ -1905,9 +1911,9 @@
    return (
      <>
        <div className="edit-custom-table-btn-wrap" style={submit.wrapStyle}>
        {setting.hasSubmit ? <div className="edit-custom-table-btn-wrap" style={submit.wrapStyle}>
          <Button style={submit.style} onClick={() => setTimeout(() => {this.submit()}, 10)} loading={loading} className="submit-table" type="link">提交</Button>
        </div>
        </div> : null}
        <div className={`edit-custom-table ${setting.tableHeader || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || ''} mk-edit-${setting.editType || 'simple'}`} id={tableId}>
          <Table
            rowKey="$$uuid"
@@ -1930,9 +1936,23 @@
            onChange={this.changeTable}
            pagination={_pagination}
          />
          {_footer ? <div className={'normal-table-footer ' + (_pagination ? 'pagination' : '')}>{_footer}</div> : null}
          {_data.length > 10 ? <Button style={submit.style} onClick={() => setTimeout(() => {this.submit()}, 10)} loading={loading} className="submit-footer-table" type="link">提交</Button> : null}
          {setting.hasSubmit && _data.length > 10 ? <Button style={submit.style} onClick={() => setTimeout(() => {this.submit()}, 10)} loading={loading} className="submit-footer-table" type="link">提交</Button> : null}
        </div>
        <Modal
          className="mk-user-confirm"
          visible={visible}
          width={450}
          maskClosable={false}
          closable={false}
          footer={[
            <Button key="cancel" onClick={() => { this.setState({ visible: false, midData: null }) }}>取消</Button>,
            <Button key="refresh" className="table-refresh" onClick={() => { midData && this.updateMutil(midData) }}>刷新表格</Button>,
            <Button key="confirm" type="primary" onClick={() => setTimeout(() => {this.submit()}, 10)}>提交数据</Button>
          ]}
          destroyOnClose
        >
          <div><QuestionCircleOutlined />表格中有数据尚未提交</div>
        </Modal>
      </>
    )
  }