king
2021-07-28 137fb8ea6af2789b3238b22bac31d80bced41dfe
src/tabviews/zshare/actionList/printbutton/index.jsx
@@ -40,7 +40,23 @@
    tabledata: null,
    btnconfig: null,
    loading: false,
    disabled: false,
    loadingNumber: ''
  }
  UNSAFE_componentWillMount () {
    const { btn, selectedData } = this.props
    let disabled = false
    if (btn.controlField && selectedData && selectedData.length > 0) { // 表格中按钮隐藏控制
      selectedData.forEach(item => {
        let s = item[btn.controlField] + ''
        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
          disabled = true
        }
      })
      this.setState({disabled})
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -52,6 +68,24 @@
    if (position === 'toolbar') {
      MKEmitter.addListener('triggerBtnId', this.actionTrigger)
    }
  }
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { btn, selectedData } = this.props
    if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) {
      let disabled = false
      if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 表格中按钮隐藏控制
        nextProps.selectedData.forEach(item => {
          let s = item[btn.controlField] + ''
          if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
            disabled = true
          }
        })
      }
      this.setState({disabled})
    }
  }
@@ -81,12 +115,12 @@
   * @description 触发按钮操作
   */
  actionTrigger = (triggerId, record) => {
    const { setting, Tab, BID, btn, selectedData } = this.props
    const { Tab, BID, btn, selectedData, setting } = this.props
    const { loading } = this.state
    if ((triggerId && btn.uuid !== triggerId) || loading) return
    if (Tab && Tab.supMenu && !BID) {
    if (((Tab && Tab.supMenu) || setting.supModule) && !BID) {
      notification.warning({
        top: 92,
        message: '需要上级主键值!',
@@ -111,14 +145,6 @@
      notification.warning({
        top: 92,
        message: this.state.dict['main.action.confirm.selectSingleLine'],
        duration: 5
      })
      return
    } else if (!setting.primaryKey) {
      // 需要选择行时,校验是否设置主键
      notification.warning({
        top: 92,
        message: '未设置主键!',
        duration: 5
      })
      return
@@ -276,6 +302,7 @@
      let errorMsg = ''
      let _temps = {}
      let images = []
      result.forEach(res => {
        if (res.status && !errorMsg) {
@@ -289,6 +316,7 @@
              status: false
            }
          } else {
            images = [...images, ..._temp.imgs]
            _temps[res.tempId] = _temp
          }
        } else if (!errorMsg) {
@@ -297,7 +325,38 @@
      })
      if (!errorMsg) {
        this.execPrint(printlist, _temps, formdata)
        if (images.length > 0) {
          let errorUrls = []
          images.forEach(url => {
            let img = new Image()
            img.onerror = () => {
              errorUrls.push(url)
            }
            img.src = url
          })
          setTimeout(() => {
            if (errorUrls.length > 0) {
              notification.warning({
                top: 92,
                message: '模板中图片 ' + errorUrls.join(',') + ' 已失效!',
                duration: 5
              })
              Object.keys(_temps).forEach(key => {
                _temps[key].config.ReportHeader.Control = _temps[key].config.ReportHeader.Control.map(item => {
                  if (item.Type === 'image' && errorUrls.includes(item.Value)) {
                    item.Value = ''
                  }
                  return item
                })
              })
            }
            this.execPrint(printlist, _temps, formdata)
          }, 500)
        } else {
          this.execPrint(printlist, _temps, formdata)
        }
      } else {
        this.execError(errorMsg)
      }
@@ -358,17 +417,21 @@
        let _param = { ...param, ...formdata }
        params.push(_param)
      } else if (btn.Ot === 'requiredSgl') {
        param[setting.primaryKey] = data[0][setting.primaryKey]
        if (setting.primaryKey) {
          param[setting.primaryKey] = data[0][setting.primaryKey]
        }
        let _param = { ...param, ...formdata }
        params.push(_param)
      } else if (btn.Ot === 'requiredOnce') {
        let ids = data.map(d => { return d[setting.primaryKey]})
        ids = ids.filter(Boolean)
        ids = ids.join(',')
        param[setting.primaryKey] = ids
        if (setting.primaryKey) {
          let ids = data.map(d => { return d[setting.primaryKey]})
          ids = ids.filter(Boolean)
          ids = ids.join(',')
          param[setting.primaryKey] = ids
        }
        let _param = { ...param, ...formdata }
@@ -376,7 +439,10 @@
      } else if (btn.Ot === 'required') {
        params = data.map((cell, index) => {
          let _param = { ...param }
          _param[setting.primaryKey] = cell[setting.primaryKey]
          if (setting.primaryKey) {
            _param[setting.primaryKey] = cell[setting.primaryKey]
          }
          formlist.forEach(_data => {
            if (index !== 0 && _data.readin && cell.hasOwnProperty(_data.key)) {
@@ -568,6 +634,7 @@
    let _configparam = ''  // 打印配置信息
    let fields = []        // 模板中所需字段
    let nonEFields = []    // 非空字段
    let imgs = []
    if (!res.ConfigParam) {
      error = '未获取到打印模板信息!'
@@ -581,7 +648,6 @@
      if (!configParam) {
        error = '打印模板解析错误!'
      } else {
        let control = configParam.elements.map(element => {
          let _field = element.field
@@ -628,6 +694,12 @@
            item.ImageWidth = element.imgWidth
            item.ImageHeight = element.imgHeight
            item.Trimming = ''
            if (element.productValue && window.GLOB.systemType === 'production') {
              item.Value = element.productValue
              imgs.push(item.Value)
            } else if (item.Value) {
              imgs.push(item.Value)
            }
          } else if (item.Type === 'text') {
            item.FontFamily = element.fontFamily
            item.FontSize = element.fontSize
@@ -688,7 +760,8 @@
      error: error,
      config: _configparam,
      fields: fields,
      nonEFields: nonEFields
      nonEFields: nonEFields,
      imgs: imgs
    }
  }
@@ -1251,13 +1324,14 @@
  render() {
    const { btn, show } = this.props
    const { loadingNumber, loading } = this.state
    const { loadingNumber, loading, disabled } = this.state
    if (show === 'actionList') {
      return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}>
        <Button
          icon={btn.icon}
          loading={loading}
          disabled={disabled}
          className={'mk-btn mk-' + btn.class}
          onClick={() => {this.actionTrigger()}}
        >{loadingNumber ? `(${loadingNumber})` : '' + btn.label}</Button>
@@ -1269,7 +1343,8 @@
          type="link"
          title={show === 'icon' ? btn.label : ''}
          loading={loading}
          style={btn.btnstyle}
          disabled={disabled}
          style={btn.style}
          icon={show === 'text' ? '' : (btn.icon || '')}
          onClick={() => {this.actionTrigger()}}
        >{show === 'icon' && btn.icon ? '' : btn.label}</Button>