king
2024-08-03 c18f79e01a2705d34d5ac2923a26913dba07ea14
src/tabviews/custom/components/table/edit-table/normalTable/mkPopSelect/index.jsx
@@ -6,6 +6,7 @@
import Api from '@/api'
import Utils from '@/utils/utils.js'
import MKEmitter from '@/utils/events.js'
import './index.scss'
const { Search } = Input
@@ -43,7 +44,7 @@
    let param = {
      func: 'sPC_Get_TableData',
      obj_name: 'data',
      exec_type: 'y',
      exec_type: window.GLOB.execType || 'y',
      arr_field: config.arr_field,
      default_sql: 'true',
      custom_script: '',
@@ -83,12 +84,12 @@
    // 测试系统打印查询语句
    if (window.GLOB.debugger === true) {
      console.info(`/*${config.label} 数据源*/\n` + sql.replace(/\n\s{6}/ig, '\n'))
      DateCount && console.info(`/*${config.label} 总数查询*/\n` + DateCount.replace(/\n\s{6}/ig, '\n'))
      window.mkInfo(`/*${config.label} 数据源*/\n` + sql.replace(/\n\s{6}/ig, '\n'))
      DateCount && window.mkInfo(`/*${config.label} 总数查询*/\n` + DateCount.replace(/\n\s{6}/ig, '\n'))
    }
    param.LText = Utils.formatOptions(sql)
    param.DateCount = Utils.formatOptions(DateCount)
    param.LText = Utils.formatOptions(sql, param.exec_type)
    param.DateCount = Utils.formatOptions(DateCount, param.exec_type)
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt('', param.timestamp)
@@ -162,19 +163,9 @@
  }
  changeRow = (record) => {
    const { config } = this.props
    if (record.$disabled) return
    let values = {[config.field]: record.$$uuid}
    if (config.linkSubField) {
      config.linkSubField.forEach(m => {
        values[m] = record[m] === undefined ? '' : record[m]
      })
    }
    this.props.onChange(values, record.$$uuid)
    this.props.onChange(record)
  }
  changeTable = (pagination, filters, sorter) => {
@@ -243,7 +234,18 @@
    
    this.state = {
      value: props.defaultValue,
      showValue: props.showValue,
      visible: false
    }
  }
  componentDidMount() {
    const { autoFocus, config } = this.props
    MKEmitter.addListener('setFocus' + config.tableId, this.setFocus)
    if (autoFocus) {
      this.trigger()
    }
  }
@@ -255,55 +257,111 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('setFocus' + this.props.config.tableId, this.setFocus)
  }
  selectChange = (values, val) => {
    this.props.onChange(values)
    this.setState({value: val, visible: false})
  setFocus = (lId, colId) => {
    const { config, lineId } = this.props
    if (lId !== lineId || config.uuid !== colId) return
    if (config.$ctrl) {
      MKEmitter.emit('colFocus' + config.tableId, lineId, config.uuid)
    }
    this.setState({visible: true})
  }
  selectChange = (record) => {
    const { config, lineId } = this.props
    let values = {[config.field]: record.$$uuid}
    let showValue = ''
    if (config.showField) {
      showValue = record[config.showField] || ''
    }
    if (config.linkSubField) {
      config.linkSubField.forEach((m, i) => {
        values[m] = record[m] !== undefined ? record[m] : ''
      })
    }
    this.props.onChange(values, record.$$uuid)
    this.setState({visible: false, value: record.$$uuid, showValue})
    if (config.$ctrl) {
      MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid)
    }
    this.props.onBlur && this.props.onBlur()
    if (/\$noAct/.test(config.enter)) return
    setTimeout(() => {
      if (/\$next/.test(config.enter)) {
        MKEmitter.emit('nextLine' + config.tableId, lineId, config.enter.replace('$next_', ''))
      } else {
        MKEmitter.emit('setFocus' + config.tableId, lineId, config.enter)
      }
    }, 10)
  }
  trigger = (e) => {
    const { config, lineId } = this.props
    e && e.stopPropagation()
    if (config.$ctrl) {
      MKEmitter.emit('colFocus' + config.tableId, lineId, config.uuid)
    }
    this.setState({visible: true})
  }
  clear = (e) => {
    const { config } = this.props
    const { config, lineId } = this.props
    e.stopPropagation()
    
    let values = {[config.field]: ''}
    if (config.linkSubField) {
      config.linkSubField.forEach(m => {
      config.linkSubField.forEach((m, i) => {
        values[m] = ''
      })
    }
    this.props.onChange(values)
    this.setState({value: ''})
  }
    this.props.onChange(values, '')
    this.setState({value: '', showValue: ''})
  cancel = () => {
    const { mask } = this.props
    this.setState({visible: false})
    if (mask) {
      this.props.blur()
    if (config.$ctrl) {
      MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid)
    }
  }
  cancel = () => {
    const { config, lineId } = this.props
    this.setState({visible: false})
    if (config.$ctrl) {
      MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid)
    }
    this.props.onBlur && this.props.onBlur()
  }
  render() {
    const { mask, BID, ID, config } = this.props
    const { value, visible } = this.state
    const { autoFocus, BID, lineId, config } = this.props
    const { showValue, value, visible } = this.state
    
    return <>
      {mask ? <div className="mk-pop-select-mask" onClick={this.trigger}></div> : null}
      {autoFocus ? <div className="mk-pop-select-mask" onClick={this.trigger}></div> : null}
      <div className="mk-pop-select-wrap" onClick={this.trigger}>
        {value}
        {value && !mask ? <CloseCircleFilled onClick={this.clear} /> : null}
        {showValue || value}
        {value && !autoFocus ? <CloseCircleFilled onClick={this.clear} /> : null}
        <TableOutlined onClick={this.trigger}/>
      </div>
      <Modal
@@ -321,11 +379,11 @@
        {config.pops ? <Tabs>
          {config.pops.map(tab => (
            <TabPane tab={tab.tabName} key={tab.uuid}>
              <PopTable config={tab} BID={BID} ID={ID} value={value} onChange={this.selectChange}/>
              <PopTable config={tab} BID={BID} ID={lineId} value={value} onChange={this.selectChange}/>
            </TabPane>
          ))}
        </Tabs> :
        <PopTable config={config} BID={BID} ID={ID} value={value} onChange={this.selectChange}/>}
        <PopTable config={config} BID={BID} ID={lineId} value={value} onChange={this.selectChange}/>}
      </Modal>
    </>
  }