king
2022-09-18 0f6153ab337c4ecca5579a79b03f3ba5f831e0c4
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'
@@ -39,6 +38,7 @@
    formdata: null,
    selines: null,
    btnconfig: null,
    confirmLoading: false,
    loading: false,
    disabled: false,
    hidden: false,
@@ -320,9 +320,9 @@
              // 系统打印数据,校验data字段
              if (btn.verify.printMode !== 'custom' && (!cell.data || cell.data.length === 0)) return
              cell.templateID = baseTemp
              cell.printType = baseType
              cell.printCount = 0
              let templateID = baseTemp
              let printType = baseType
              let printCount = 0
              Object.keys(cell).forEach(key => {
                if (!cell[key]) return
@@ -330,13 +330,17 @@
                let _key = key.toLowerCase()
                if (_key === 'templateid') {
                  cell.templateID = cell[key]
                  templateID = cell[key]
                } else if (_key === 'printtype') {
                  cell.printType = cell[key]
                  printType = cell[key]
                } else if (_key === 'printcount') {
                  cell.printCount = +cell[key]
                  printCount = +cell[key]
                }
              })
              cell.templateID = templateID
              cell.printType = printType
              cell.printCount = printCount
              if (isNaN(cell.printCount) || cell.printCount < 1) {
                cell.printCount = baseCount
@@ -376,7 +380,7 @@
            param.rduri = window.GLOB.mainSystemApi
          }
    
          Api.getLocalConfig(param).then(result => {
          Api.genericInterface(param).then(result => {
            result.tempId = tempId
            resolve(result)
          })
@@ -723,9 +727,16 @@
            _param[setting.primaryKey] = cell[setting.primaryKey]
          }
          let _cell = {}
          if (index !== 0) {
            Object.keys(cell).forEach(key => {
              _cell[key.toLowerCase()] = cell[key]
            })
          }
          formlist.forEach(_data => {
            if (index !== 0 && _data.readin && cell.hasOwnProperty(_data.key)) {
              _param[_data.key] = cell[_data.key]
            if (index !== 0 && _data.readin && _cell.hasOwnProperty(_data.key.toLowerCase())) {
              _param[_data.key] = _cell[_data.key.toLowerCase()]
            } else {
              _param[_data.key] = _data.value
            }
@@ -812,9 +823,11 @@
      // 外部请求
      _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
          res.userid = sessionStorage.getItem('CloudUserID') || ''
          res.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
        } else if (btn.sysInterface !== 'true') {
          if (window.GLOB.systemType === 'production' && btn.proInterface) {
            res.rduri = btn.proInterface
@@ -830,6 +843,11 @@
            res.rduri = btn.proInterface
          } else {
            res.rduri = btn.interface
          }
          let host = window.GLOB.baseurl.replace(/http(s):\/\//, '')
          if (res.rduri.indexOf(host) === -1 && /\/dostars/.test(res.rduri)) {
            res.$login = true
          }
        }
      }
@@ -927,7 +945,18 @@
      if (!configParam) {
        error = '打印模板解析错误!'
      } else {
        let control = configParam.elements.map(element => {
        let control = []
        let rotate = configParam.rotate || 0
        let offsetTop = 0
        let offsetLeft = 0
        if (rotate === 90) {
          offsetTop = configParam.width - configParam.height
        } else if (rotate === 270) {
          offsetLeft = configParam.height - configParam.width
        }
        configParam.elements.forEach(element => {
          let _field = element.field
          if (_field === 'other_field') {
@@ -939,11 +968,12 @@
            Type: element.type,
            Value: element.value || '',
            Field: _field,
            Left: element.left,
            Top: element.top,
            Left: element.left + offsetLeft,
            Top: element.top + offsetTop,
            Width: element.width,
            Height: element.height,
            Rotate: element.rotate,
            Rotate: rotate,
            // Rotate: element.rotate,
            BorderSize: element.borderSize / 10,
            BorderColor: element.borderColor,
            Align: element.align,
@@ -963,11 +993,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
@@ -1007,8 +1038,14 @@
            }
          }
          return item
          control.push(item)
        })
        let down = false
        if (rotate === 90 || rotate === 270) {
          down = true
        }
        _configparam = {
          Version: '',
@@ -1017,8 +1054,8 @@
          Description: configParam.remark,
          PrintTempNO: configParam.PrintTempNO,
          PageSetting: {
            Width: configParam.width,
            Height: configParam.height,
            Width: down ? configParam.height : configParam.width,
            Height: down ? configParam.width : configParam.height,
            Left: '0',
            Right: '0',
            Top: '0',
@@ -1148,12 +1185,21 @@
    })
    if (list.length === 0) {
      this.execError({
        ErrCode: 'N',
        message: '未获取到打印信息!',
        ErrMesg: '',
        status: false
      })
      if (btn.verify.emptyTip === 'false') {
        this.execSuccess({
          ErrCode: '-1',
          message: '未获取到打印信息!',
          ErrMesg: '',
          status: true
        })
      } else {
        this.execError({
          ErrCode: 'N',
          message: '未获取到打印信息!',
          ErrMesg: '',
          status: false
        })
      }
      return
    } else if (_errors.length > 0) {
      let lackerror = []
@@ -1307,24 +1353,31 @@
   */
  execSuccess = (res) => {
    const { btn } = this.props
    const { autoMatic } = this.state
    const { autoMatic, btnconfig } = this.state
    if ((res && (res.ErrCode === 'S' || !res.ErrCode)) || autoMatic) { // 执行成功
    if ((res.ErrCode === 'S' || !res.ErrCode) || autoMatic) { // 执行成功
      notification.success({
        top: 92,
        message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
        duration: btn.verify && btn.verify.stime ? btn.verify.stime : 2
      })
    } else if (res && res.ErrCode === 'Y') { // 执行成功
    } else if (res.ErrCode === 'Y') { // 执行成功
      Modal.success({
        title: res.ErrMesg || this.state.dict['main.action.confirm.success']
      })
    } else if (res && res.ErrCode === '-1') { // 完成后不提示
    } else if (res.ErrCode === '-1') { // 完成后不提示
    }
    if (autoMatic || !btnconfig || btnconfig.setting.finish !== 'unclose') {
      this.setState({
        visible: false
      })
    }
    this.setState({
      loading: false
      loading: false,
      confirmLoading: false
    })
    if (autoMatic) {
@@ -1369,7 +1422,8 @@
    }
    
    this.setState({
      loading: false
      loading: false,
      confirmLoading: false
    })
    if (autoMatic) {
@@ -1489,16 +1543,10 @@
   * @description 模态框(表单),确认
   */
  handleOk = () => {
    const { btnconfig, autoMatic } = this.state
    if (!this.formRef) return
    this.formRef.handleConfirm().then(res => {
      if (btnconfig.setting.finish !== 'unclose' || autoMatic) {
        this.setState({
          visible: false
        })
      }
      this.setState({ confirmLoading: true })
      this.triggerPrint(this.state.selines, res)
    })
  }
@@ -1509,15 +1557,28 @@
  handleCancel = () => {
    this.setState({
      loading: false,
      visible: false
      visible: false,
      confirmLoading: false
    })
  }
  modelconfirm = () => {
    const { BData } = this.props
    const { btnconfig, selines } = this.state
    let _this = this
    let result = []
    let _data = {}
    let BData = {}
    if (selines[0]) {
      Object.keys(selines[0]).forEach(key => {
        _data[key.toLowerCase()] = selines[0][key]
      })
    }
    if (this.props.BData) {
      Object.keys(this.props.BData).forEach(key => {
        BData[key.toLowerCase()] = this.props.BData[key]
      })
    }
    
    btnconfig.fields.forEach(item => {
      if (!item.field) return
@@ -1528,10 +1589,10 @@
        _readin = false
      }
      if (item.type === 'linkMain' && BData && BData.hasOwnProperty(item.field)) {
        _initval = BData[item.field]
      } else if (_readin && selines[0] && selines[0].hasOwnProperty(item.field)) {
        _initval = selines[0][item.field]
      if (item.type === 'linkMain' && BData.hasOwnProperty(item.field.toLowerCase())) {
        _initval = BData[item.field.toLowerCase()]
      } else if (_readin && _data.hasOwnProperty(item.field.toLowerCase())) {
        _initval = _data[item.field.toLowerCase()]
      } else if (item.type === 'date' && _initval) {
        _initval = moment().subtract(_initval, 'days').format('YYYY-MM-DD')
      } else if (item.type === 'datemonth' && _initval) {
@@ -1627,6 +1688,7 @@
        getContainer={container}
        wrapClassName='action-modal'
        visible={this.state.visible}
        confirmLoading={this.state.confirmLoading}
        width={width}
        onOk={this.handleOk}
        onCancel={this.handleCancel}
@@ -1635,7 +1697,6 @@
        <MutilForm
          BID={BID}
          dict={this.state.dict}
          menuType={this.props.menuType}
          action={btnconfig}
          inputSubmit={this.handleOk}
          data={this.state.selines[0]}
@@ -1676,7 +1737,7 @@
      className = 'mk-btn mk-' + btn.class
    }
    return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}>
    return <>
      <Button
        type={type}
        title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')}
@@ -1685,21 +1746,11 @@
        style={btn.style || null}
        icon={icon}
        className={className}
        onClick={() => {this.actionTrigger()}}
        onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
      >{label}</Button>
      {this.getModels()}
    </div>
      <span onClick={(e) => {e.stopPropagation()}}>{this.getModels()}</span>
    </>
  }
}
const mapStateToProps = (state) => {
  return {
    menuType: state.editLevel
  }
}
const mapDispatchToProps = () => {
  return {}
}
export default connect(mapStateToProps, mapDispatchToProps)(PrintButton)
export default PrintButton