king
2022-07-22 0c439ced2c97905cb2b02f5f689a37b19369fb8a
src/tabviews/zshare/actionList/printbutton/index.jsx
@@ -1,7 +1,6 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import moment from 'moment'
import {connect} from 'react-redux'
import { is, fromJS } from 'immutable'
import { Button, Modal, notification, message } from 'antd'
@@ -22,7 +21,6 @@
class PrintButton extends Component {
  static propTpyes = {
    show: PropTypes.any,              // 按钮显示样式控制
    BID: PropTypes.string,            // 主表ID
    BData: PropTypes.any,             // 主表数据
    selectedData: PropTypes.any,      // 子表中选择数据
@@ -43,7 +41,6 @@
    loading: false,
    disabled: false,
    hidden: false,
    loadingNumber: '',
    autoMatic: false
  }
@@ -53,7 +50,7 @@
    if (btn.controlField && selectedData && selectedData.length > 0) { // 表格中按钮隐藏控制
      selectedData.forEach(item => {
        let s = item[btn.controlField] + ''
        let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
          disabled = true
        }
@@ -98,7 +95,7 @@
    if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) {
      if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 表格中按钮隐藏控制
        nextProps.selectedData.forEach(item => {
          let s = item[btn.controlField] + ''
          let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
          if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
            disabled = true
          }
@@ -148,7 +145,8 @@
    const { Tab, BID, btn, selectedData, setting } = this.props
    const { loading, disabled } = this.state
    if ((triggerId && btn.uuid !== triggerId) || loading || disabled) return
    if (loading || disabled) return
    if (triggerId && btn.uuid !== triggerId) return
    if (((Tab && Tab.supMenu) || setting.supModule) && !BID) {
      notification.warning({
@@ -157,10 +155,8 @@
        duration: 5
      })
      return
    } else if (type === 'linkbtn' && selectedData && selectedData.length === 1) {
      if (record[0].$Index !== selectedData[0].$Index) {
        return
      }
    } else if (type === 'linkbtn' && !btn.$toolbtn && !is(fromJS(selectedData || []), fromJS(record))) {
      return
    }
    this.setState({autoMatic: type === 'autoMatic'})
@@ -243,38 +239,77 @@
  triggerPrint = (data, formlist = []) => {
    const { btn } = this.props
    let formdata = {}
    let baseCount = 1
    let baseType = ''
    let baseTemp = btn.verify.Template || ''
    
    formlist.forEach(_data => {
      formdata[_data.key] = _data.value
      if (!_data.value) return
      if (_data.key.toLowerCase() === 'printcount') {
        baseCount = +_data.value
      } else if (_data.key.toLowerCase() === 'printtype') {
        baseType = _data.value
      } else if (_data.key.toLowerCase() === 'templateid') {
        baseTemp = _data.value
      }
    })
    let printlist = []
    let templates = []
    let printCount = +(formdata.printCount || formdata.PrintCount || formdata.printcount || formdata.Printcount || 1)
    if (isNaN(printCount) || printCount < 1) {
      printCount = 1
    if (isNaN(baseCount) || baseCount < 1) {
      baseCount = 1
    }
    new Promise(resolve => {
      if (btn.intertype === 'system') { // 使用系统时,直接从表格或表单中选取数据
        let printcell = {}
        printcell.printType = formdata.printType || formdata.PrintType || formdata.printtype || formdata.Printtype || ''
        printcell.printCount = printCount
        printcell.templateID = btn.verify.Template || ''
        if (btn.Ot === 'notRequired') {
          let printcell = {}
          printcell.printType = baseType
          printcell.printCount = baseCount
          printcell.templateID = baseTemp
          printcell.data = [formdata]
          templates.push(printcell.templateID)
          printlist.push(printcell)
        } else {
          printcell.data = data.map(cell => {
            return {...cell, ...formdata}
          data.forEach(cell => {
            let _cell = {...cell, ...formdata}
            let printcell = {data: [_cell]}
            printcell.templateID = baseTemp
            printcell.printType = baseType
            printcell.printCount = 0
            Object.keys(_cell).forEach(key => {
              if (!_cell[key]) return
              let _key = key.toLowerCase()
              if (_key === 'templateid') {
                printcell.templateID = _cell[key]
              } else if (_key === 'printtype') {
                printcell.printType = _cell[key]
              } else if (_key === 'printcount') {
                printcell.printCount = +_cell[key]
              }
            })
            if (isNaN(printcell.printCount) || printcell.printCount < 1) {
              printcell.printCount = baseCount
            }
            templates.push(printcell.templateID)
            printlist.push(printcell)
          })
        }
        templates.push(printcell.templateID)
        printlist.push(printcell)
        resolve(true)
      } else {
@@ -284,16 +319,31 @@
              // 系统打印数据,校验data字段
              if (btn.verify.printMode !== 'custom' && (!cell.data || cell.data.length === 0)) return
              cell.templateID = cell.templateID || cell.TemplateID || cell.Templateid || cell.templateid || btn.verify.Template
              cell.printType = cell.printType || cell.PrintType || cell.printtype || cell.Printtype || formdata.printType || formdata.PrintType || formdata.printtype || formdata.Printtype || ''
              let templateID = baseTemp
              let printType = baseType
              let printCount = 0
              let _printCount = +(cell.printCount || cell.PrintCount || cell.printcount || cell.Printcount || 0)
              Object.keys(cell).forEach(key => {
                if (!cell[key]) return
              if (isNaN(_printCount) || _printCount < 1) {
                _printCount = printCount
                let _key = key.toLowerCase()
                if (_key === 'templateid') {
                  templateID = cell[key]
                } else if (_key === 'printtype') {
                  printType = cell[key]
                } else if (_key === 'printcount') {
                  printCount = +cell[key]
                }
              })
              cell.templateID = templateID
              cell.printType = printType
              cell.printCount = printCount
              if (isNaN(cell.printCount) || cell.printCount < 1) {
                cell.printCount = baseCount
              }
              cell.printCount = _printCount
              templates.push(cell.templateID)
@@ -765,7 +815,7 @@
      // 外部请求
      _outParam = JSON.parse(JSON.stringify(res))
      if (this.props.menuType === 'HS') {
      if (window.GLOB.mkHS) {
        if (btn.sysInterface === 'true' && options.cloudServiceApi) {
          res.rduri = options.cloudServiceApi
        } else if (btn.sysInterface !== 'true') {
@@ -880,7 +930,8 @@
      if (!configParam) {
        error = '打印模板解析错误!'
      } else {
        let control = configParam.elements.map(element => {
        let control = []
        configParam.elements.forEach(element => {
          let _field = element.field
          if (_field === 'other_field') {
@@ -916,11 +967,12 @@
            item.Trimming = ''
            if (!item.Width) {
              item.Width = item.BorderSize
              item.Left = item.Left - item.Width
              item.Left = item.Left - item.Width + 0.1
            } else if (!item.Height) {
              item.Height = item.BorderSize
              item.Top = item.Top - item.Height
              item.Top = item.Top - item.Height + 0.1
            }
            item.BackColor = element.borderColor
            item.BorderSize = 0
          } else if (item.Type === 'image') {
            item.ImageWidth = element.imgWidth
@@ -960,7 +1012,7 @@
            }
          }
          return item
          control.push(item)
        })
        _configparam = {
@@ -1262,7 +1314,7 @@
    const { btn } = this.props
    const { autoMatic } = this.state
    if ((res && res.ErrCode === 'S') || autoMatic) { // 执行成功
    if ((res && (res.ErrCode === 'S' || !res.ErrCode)) || autoMatic) { // 执行成功
      notification.success({
        top: 92,
        message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
@@ -1556,8 +1608,8 @@
    if (!this.state.visible || !btnconfig || !btnconfig.setting) return null
    let title = btnconfig.setting.title
    let width = btnconfig.setting.width + 'vw'
    let title = btn.label
    let width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + 'vw'
    let clickouter = false
    let container = document.body
@@ -1565,7 +1617,7 @@
      (setting.tabType === 'main' && btnconfig.setting.container === 'tab' && this.props.ContainerId) ||
      (btnconfig.setting.container === 'tab' && btn.ContainerId)
    ) {
      width = btnconfig.setting.width + '%'
      width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + '%'
      container = () => document.getElementById(this.props.ContainerId || btn.ContainerId)
    }
@@ -1588,7 +1640,6 @@
        <MutilForm
          BID={BID}
          dict={this.state.dict}
          menuType={this.props.menuType}
          action={btnconfig}
          inputSubmit={this.handleOk}
          data={this.state.selines[0]}
@@ -1600,63 +1651,49 @@
  }
  render() {
    const { btn, show } = this.props
    const { loadingNumber, loading, disabled, hidden } = this.state
    const { btn } = this.props
    const { loading, disabled, hidden } = this.state
    if (hidden) return null
    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>
        {this.getModels()}
      </div>
    } else { // icon、text、 all 卡片
      let label = ''
      let icon = ''
    let label = ''
    let icon = ''
    let type = 'link'
    let className = ''
      if (show === 'button') {
        label = btn.label
        icon = btn.icon || ''
      } else if (show === 'link') {
        label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span>
        icon = ''
      } else if (show === 'icon') {
        icon = btn.icon || ''
      // } else if (show === 'text') {
      } else {
        label = btn.label
      }
      return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}>
        <Button
          type="link"
          title={show === 'icon' ? btn.label : ''}
          loading={loading}
          disabled={disabled}
          style={btn.style}
          icon={icon}
          onClick={() => {this.actionTrigger()}}
        >{label}</Button>
        {this.getModels()}
      </div>
    if (btn.show === 'button') {
      label = btn.label
      icon = btn.icon || ''
    } else if (btn.show === 'link') {
      label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span>
      icon = ''
    } else if (btn.show === 'icon') {
      icon = btn.icon || ''
    } else if (!btn.$toolbtn) {
      icon = btn.icon || ''
      label = btn.label
      className = 'mk-btn mk-' + btn.class
    } else {
      type = ''
      icon = btn.icon || ''
      label = btn.label
      className = 'mk-btn mk-' + btn.class
    }
    return <>
      <Button
        type={type}
        title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')}
        loading={loading}
        disabled={disabled}
        style={btn.style || null}
        icon={icon}
        className={className}
        onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
      >{label}</Button>
      {this.getModels()}
    </>
  }
}
const mapStateToProps = (state) => {
  return {
    menuType: state.editLevel
  }
}
const mapDispatchToProps = () => {
  return {}
}
export default connect(mapStateToProps, mapDispatchToProps)(PrintButton)
export default PrintButton