king
2021-11-17 c51f5e007a3e03c9d6731ab7f28f0080de009990
src/tabviews/zshare/actionList/normalbutton/index.jsx
@@ -13,7 +13,7 @@
import asyncSpinComponent from '@/utils/asyncSpinComponent'
import { updateForm } from '@/utils/utils-update.js'
import MKEmitter from '@/utils/events.js'
import './index.scss'
// import './index.scss'
const MutilForm = asyncSpinComponent(() => import('@/tabviews/zshare/mutilform'))
const { confirm } = Modal
@@ -37,13 +37,15 @@
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    visible: false,
    formdata: null,
    tabledata: null,
    selines: null,
    confirmLoading: false,
    btnconfig: null,
    loading: false,
    loadingNumber: '',
    disabled: false,
    checkParam: null
    hidden: false,
    checkParam: null,
    autoMatic: false
  }
  moduleParams = null
@@ -59,7 +61,7 @@
          disabled = true
        }
      })
      this.setState({disabled})
      this.setState({disabled, hidden: disabled && btn.control === 'hidden'})
    }
  }
@@ -68,13 +70,17 @@
  }
  componentDidMount () {
    const { position } = this.props
    const { position, btn } = this.props
    MKEmitter.addListener('triggerBtnId', this.actionTrigger)
    if (position === 'form') {
      MKEmitter.addListener('triggerFormSubmit', this.actionSubmit)
    }
    MKEmitter.addListener('returnModuleParam', this.resetModuleParam)
    if (btn.autoMatic) {
      MKEmitter.addListener('triggerBtnPopSubmit', this.triggerBtnPopSubmit)
    }
  }
  UNSAFE_componentWillReceiveProps (nextProps) {
@@ -91,7 +97,7 @@
          }
        })
      }
      this.setState({disabled})
      this.setState({disabled, hidden: disabled && btn.control === 'hidden'})
    }
  }
@@ -102,6 +108,15 @@
    MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
    MKEmitter.removeListener('triggerFormSubmit', this.actionSubmit)
    MKEmitter.removeListener('returnModuleParam', this.resetModuleParam)
    MKEmitter.removeListener('triggerBtnPopSubmit', this.triggerBtnPopSubmit)
  }
  triggerBtnPopSubmit = (id) => {
    const { btn } = this.props
    if (btn.uuid !== id) return
    this.handleOk()
  }
  actionSubmit = (res) => {
@@ -109,11 +124,9 @@
    if (btn.uuid !== res.menuId) return
    this.setState({
      loading: true
    })
    this.setState({ loading: true })
    this.execSubmit(this.state.tabledata, () => {}, res.form)
    this.execSubmit(this.state.selines, () => {}, res.form)
  }
  resetModuleParam = (menuId, btnId, param) => {
@@ -127,17 +140,12 @@
  /**
   * @description 按钮状态改变
   */
  updateStatus = (type) => {
    if (type === 'start') {
      this.setState({
        loading: true
      })
    } else if (type === 'over') {
      this.setState({
        loading: false,
        visible: false
      })
    }
  updateStatus = () => {
    this.setState({
      loading: false,
      visible: false,
      confirmLoading: false
    })
  }
  
  /**
@@ -145,9 +153,9 @@
   */
  actionTrigger = (triggerId, record, type) => {
    const { Tab, BID, btn, selectedData, setting } = this.props
    const { loading } = this.state
    const { loading, disabled } = this.state
    if ((triggerId && btn.uuid !== triggerId) || loading) return
    if ((triggerId && btn.uuid !== triggerId) || loading || disabled) return
    if (((Tab && Tab.supMenu) || setting.supModule) && !BID) {
      notification.warning({
@@ -161,6 +169,8 @@
        return
      }
    }
    this.setState({autoMatic: type === 'autoMatic'})
    let _this = this
    let data = record || selectedData || []
@@ -235,14 +245,15 @@
      return
    }
    this.setState({
      selines: data
    })
    if (btn.OpenType === 'formSubmit') {
      this.setState({
        tabledata: data
      })
      MKEmitter.emit('mkFormSubmit', btn.uuid)
      return
    } else if (btn.OpenType === 'prompt') {
      this.updateStatus('start')
      this.setState({loading: true})
      confirm({
        title: this.state.dict['main.action.confirm.tip'],
        onOk() {
@@ -251,22 +262,20 @@
          })
        },
        onCancel() {
          _this.updateStatus('over')
          _this.setState({loading: false})
        }
      })
    } else if (btn.OpenType === 'exec') {
      this.updateStatus('start')
      this.setState({loading: true})
      this.execSubmit(data, () => { this.setState({loading: false})})
    } else if (btn.OpenType === 'pop') {
      this.updateStatus('start')
      let modal = this.state.btnconfig
      if (!modal && btn.modal) {
        modal = this.handleModelConfig(btn.modal)
      }
      this.setState({
        tabledata: data,
        loading: true,
        btnconfig: modal
      }, () => {
        this.improveAction()
@@ -672,7 +681,18 @@
  }
  execRealSubmit = (data, _resolve, formdata) => {
    const { setting, btn } = this.props
    const { setting, btn, Tab, BID } = this.props
    if (((Tab && Tab.supMenu) || setting.supModule) && !BID) {
      notification.warning({
        top: 92,
        message: '需要上级主键值!',
        duration: 5
      })
      _resolve()
      return
    }
    if (btn.intertype === 'system' || btn.intertype === 'inner') { // 系统接口
      let params = []
@@ -700,19 +720,21 @@
                  delete _param.ErrMesg
                  delete _param.message
                  Api.genericInterface(_param).then(result => {
                    if (!result.status) {
                      notification.warning({
                        top: 92,
                        message: result.message,
                        duration: 5
                      })
                    }
                  })
                  setTimeout(() => {
                    Api.genericInterface(_param).then(result => {
                      if (!result.status) {
                        notification.warning({
                          top: 92,
                          message: result.message,
                          duration: 5
                        })
                      }
                    })
                  }, 600)
                }
                resolve(res)
              }, () => {
                this.updateStatus('over')
                this.updateStatus()
                _resolve()
              })
            }, 100 * i)
@@ -867,7 +889,7 @@
                }
                resolve()
              }, () => {
                _this.updateStatus('over')
                _this.updateStatus()
                resolve()
                _resolve()
              })
@@ -884,7 +906,7 @@
        _resolve()
      }
    }, () => {
      this.updateStatus('over')
      this.updateStatus()
      _resolve()
    })
  }
@@ -1136,7 +1158,7 @@
        _resolve()
      }
    }, () => {
      this.updateStatus('over')
      this.updateStatus()
      _resolve()
    })
  }
@@ -1168,15 +1190,17 @@
          delete _param.ErrMesg
          delete _param.message
  
          Api.genericInterface(_param).then(result => {
            if (!result.status) {
              notification.warning({
                top: 92,
                message: result.message,
                duration: 5
              })
            }
          })
          setTimeout(() => {
            Api.genericInterface(_param).then(result => {
              if (!result.status) {
                notification.warning({
                  top: 92,
                  message: result.message,
                  duration: 5
                })
              }
            })
          }, 600)
        }
        if (params.length === 0) {
          this.execSuccess(res)
@@ -1189,7 +1213,7 @@
        _resolve()
      }
    }, () => {
      this.updateStatus('over')
      this.updateStatus()
      _resolve()
    })
  }
@@ -1242,7 +1266,7 @@
            _resolve()
          }
        }, () => {
          this.updateStatus('over')
          this.updateStatus()
          _resolve()
        })
      } else {
@@ -1348,9 +1372,9 @@
   */
  execSuccess = (res) => {
    const { btn } = this.props
    const { btnconfig } = this.state
    const { btnconfig, autoMatic } = this.state
    if (res && res.ErrCode === 'S') { // 执行成功
    if ((res && res.ErrCode === 'S') || autoMatic) { // 执行成功
      notification.success({
        top: 92,
        message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
@@ -1364,7 +1388,14 @@
    }
    
    if (btn.OpenType !== 'pop' || !btnconfig || btnconfig.setting.finish !== 'unclose') {
    if (autoMatic) {
      this.setState({
        loading: false,
        visible: false
      })
      MKEmitter.emit('autoExecOver', btn.uuid, 'success')
      return
    } else if (btn.OpenType !== 'pop' || !btnconfig || btnconfig.setting.finish !== 'unclose') {
      this.setState({
        loading: false,
        visible: false
@@ -1383,7 +1414,7 @@
    if (btn.execSuccess === 'closetab') {
      MKEmitter.emit('closeTabView', btn.$MenuID)
    } else if (btn.execSuccess !== 'never') {
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, id)
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, id, this.state.selines)
    }
    if (btn.refreshTab && btn.refreshTab.length > 0) {
@@ -1530,12 +1561,13 @@
   */
  execError = (res) => {
    const { btn } = this.props
    const { btnconfig, autoMatic } = this.state
    if (res.ErrCode === 'E') {
    if (res.ErrCode === 'E' && !autoMatic) {
      Modal.error({
        title: res.message || res.ErrMesg,
      })
    } else if (res.ErrCode === 'N') {
    } else if (res.ErrCode === 'N' || autoMatic) {
      notification.error({
        top: 92,
        message: res.message || res.ErrMesg,
@@ -1550,6 +1582,16 @@
      })
    } else if (res.ErrCode === 'NM') {
      message.error(res.message || res.ErrMesg)
    }
    if (autoMatic) {
      this.setState({
        loading: false,
        loadingNumber: '',
        visible: false
      })
      MKEmitter.emit('autoExecOver', btn.uuid, 'error')
      return
    }
    
    this.setState({
@@ -1586,7 +1628,7 @@
              visible: false
            })
            if (btn.execError !== 'never') {
              MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn)
              MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines)
            }
          }
        })
@@ -1599,8 +1641,12 @@
      }
    }
    if (btnconfig && btnconfig.setting && btnconfig.setting.errFocus) {
      MKEmitter.emit('mkFC', 'focus', btnconfig.setting.errFocus)
    }
    if (btn.execError !== 'never') {
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn)
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines)
    }
  }
@@ -1643,10 +1689,10 @@
   */
  improveAction = () => {
    const { btn } = this.props
    const { btnconfig } = this.state
    const { btnconfig, autoMatic } = this.state
    if (btnconfig) {
      if (btnconfig.setting.display === 'prompt') { // 如果表单以是否框展示
      if (!autoMatic && btnconfig.setting.display === 'prompt') { // 如果表单以是否框展示
        this.modelconfirm()
      } else {
        this.setState({
@@ -1675,14 +1721,14 @@
            message: res.message,
            duration: 5
          })
          this.updateStatus('over')
          this.setState({ loading: false })
        } else if (!_LongParam || (btn.OpenType === 'pop' && _LongParam.type !== 'Modal')) {
          notification.warning({
            top: 92,
            message: '未获取到按钮配置信息!',
            duration: 5
          })
          this.updateStatus('over')
          this.setState({ loading: false })
        } else {
          _LongParam = updateForm(_LongParam)
          _LongParam = this.handleModelConfig(_LongParam)
@@ -1690,7 +1736,7 @@
          this.setState({
            btnconfig: _LongParam
          }, () => {
            if (_LongParam.setting.display === 'prompt') { // 如果表单以是否框展示
            if (!autoMatic && _LongParam.setting.display === 'prompt') { // 如果表单以是否框展示
              this.modelconfirm()
            } else {
              this.setState({
@@ -1707,16 +1753,11 @@
   * @description 模态框(表单),确认
   */
  handleOk = () => {
    if (!this.formRef) return
    this.formRef.handleConfirm().then(res => {
      this.setState({
        confirmLoading: true
      })
      this.setState({ confirmLoading: true })
      this.execSubmit(this.state.tabledata, () => {
        this.setState({
          confirmLoading: false
        })
      }, res)
      this.execSubmit(this.state.selines, () => { this.setState({ confirmLoading: false }) }, res)
    })
  }
@@ -1725,15 +1766,15 @@
   */
  handleCancel = () => {
    this.setState({
      loading: false,
      visible: false,
      confirmLoading: false
    })
    this.updateStatus('over')
  }
  modelconfirm = () => {
    const { BData } = this.props
    const { btnconfig, tabledata } = this.state
    const { btnconfig, selines } = this.state
    let _this = this
    let result = []
@@ -1748,8 +1789,8 @@
      if (item.type === 'linkMain' && BData && BData.hasOwnProperty(item.field)) {
        _initval = BData[item.field]
      } else if (_readin && tabledata[0] && tabledata[0].hasOwnProperty(item.field)) {
        _initval = tabledata[0][item.field]
      } else if (_readin && selines[0] && selines[0].hasOwnProperty(item.field)) {
        _initval = selines[0][item.field]
      } else if (item.type === 'date' && _initval) {
        _initval = moment().subtract(_initval, 'days').format('YYYY-MM-DD')
      } else if (item.type === 'datemonth' && _initval) {
@@ -1790,11 +1831,11 @@
      title: this.state.dict['main.action.confirm.tip'],
      onOk() {
        return new Promise(resolve => {
          _this.execSubmit(tabledata, resolve, result)
          _this.execSubmit(selines, resolve, result)
        })
      },
      onCancel() {
        _this.updateStatus('over')
        _this.setState({ loading: false })
      }
    })
  }
@@ -1836,7 +1877,7 @@
            menuType={this.props.menuType}
            action={btnconfig}
            inputSubmit={this.handleOk}
            data={this.state.tabledata[0]}
            data={this.state.selines[0]}
            BData={BData}
            wrappedComponentRef={(inst) => this.formRef = inst}
          />
@@ -1879,7 +1920,7 @@
            menuType={this.props.menuType}
            action={btnconfig}
            inputSubmit={this.handleOk}
            data={this.state.tabledata[0]}
            data={this.state.selines[0]}
            BData={BData}
            wrappedComponentRef={(inst) => this.formRef = inst}
          />
@@ -1890,7 +1931,9 @@
  render() {
    const { btn, show, style } = this.props
    const { loadingNumber, loading, disabled } = this.state
    const { loadingNumber, loading, disabled, hidden } = this.state
    if (hidden) return null
    if (show === 'actionList') {
      return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}>
@@ -1905,7 +1948,7 @@
        {this.getModels()}
      </div>
    } else if (show && show.indexOf('plus') > -1) {
      return <div className="mk-btn-wrap">
      return <div style={{display: 'inline-block'}}>
        <Button
          type="link"
          loading={loading}