From 0f6153ab337c4ecca5579a79b03f3ba5f831e0c4 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 18 九月 2022 02:03:48 +0800
Subject: [PATCH] 2022-09-18

---
 src/tabviews/zshare/actionList/printbutton/index.jsx |  389 ++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 257 insertions(+), 132 deletions(-)

diff --git a/src/tabviews/zshare/actionList/printbutton/index.jsx b/src/tabviews/zshare/actionList/printbutton/index.jsx
index 2c2e490..776ede5 100644
--- a/src/tabviews/zshare/actionList/printbutton/index.jsx
+++ b/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,8 +21,6 @@
 
 class PrintButton extends Component {
   static propTpyes = {
-    show: PropTypes.any,              // 鎸夐挳鏄剧ず鏍峰紡鎺у埗
-    position: PropTypes.any,          // 鎸夐挳浣嶇疆锛屽伐鍏锋爮涓簍oolbar
     BID: PropTypes.string,            // 涓昏〃ID
     BData: PropTypes.any,             // 涓昏〃鏁版嵁
     selectedData: PropTypes.any,      // 瀛愯〃涓�夋嫨鏁版嵁
@@ -32,6 +29,7 @@
     btn: PropTypes.object,            // 鎸夐挳
     setting: PropTypes.any,           // 椤甸潰閫氱敤璁剧疆
     ContainerId: PropTypes.any,       // tab椤甸潰ID锛岀敤浜庡脊绐楁帶鍒�
+    disabled: PropTypes.any,          // 琛屾寜閽鐢�
   }
 
   state = {
@@ -40,25 +38,40 @@
     formdata: null,
     selines: null,
     btnconfig: null,
+    confirmLoading: false,
     loading: false,
     disabled: false,
     hidden: false,
-    loadingNumber: '',
     autoMatic: false
   }
 
   UNSAFE_componentWillMount () {
-    const { btn, selectedData } = this.props
+    const { btn, selectedData, BData } = this.props
     let disabled = false
 
     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
         }
       })
-      this.setState({disabled, hidden: disabled && btn.control === 'hidden'})
+      this.setState({hidden: disabled && btn.control === 'hidden'})
+    } else if (btn.control === 'parent') {
+      if (!BData || !BData.hasOwnProperty(btn.controlField)) {
+        this.setState({hidden: true})
+      } else {
+        let s = BData[btn.controlField] + ''
+        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
+          this.setState({hidden: true})
+        } else {
+          this.setState({hidden: false})
+        }
+      }
+    }
+
+    if (this.props.disabled || disabled) {
+      this.setState({disabled: true})
     }
   }
 
@@ -77,20 +90,36 @@
   }
 
   UNSAFE_componentWillReceiveProps (nextProps) {
-    const { btn, selectedData } = this.props
+    const { btn, selectedData, BData } = this.props
 
+    let disabled = false
     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] + ''
+          let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
           if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
             disabled = true
           }
         })
       }
       this.setState({disabled, hidden: disabled && btn.control === 'hidden'})
+    } else if (btn.control === 'parent' && !is(fromJS(nextProps.BData || {}), fromJS(BData || {}))) {
+      if (!nextProps.BData || !nextProps.BData.hasOwnProperty(btn.controlField)) {
+        this.setState({hidden: true})
+      } else {
+        let s = nextProps.BData[btn.controlField] + ''
+        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
+          this.setState({hidden: true})
+        } else {
+          this.setState({hidden: false})
+        }
+      }
+    }
+
+    if (nextProps.disabled || disabled) {
+      this.setState({disabled: true})
+    } else {
+      this.setState({disabled: false})
     }
   }
 
@@ -117,7 +146,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({
@@ -126,10 +156,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'})
@@ -212,38 +240,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 {
@@ -253,16 +320,31 @@
               // 绯荤粺鎵撳嵃鏁版嵁锛屾牎楠宒ata瀛楁
               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)
 
@@ -298,7 +380,7 @@
             param.rduri = window.GLOB.mainSystemApi
           }
     
-          Api.getLocalConfig(param).then(result => {
+          Api.genericInterface(param).then(result => {
             result.tempId = tempId
             resolve(result)
           })
@@ -645,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
             }
@@ -734,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
@@ -752,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
           }
         }
       }
@@ -849,7 +945,18 @@
       if (!configParam) {
         error = '鎵撳嵃妯℃澘瑙f瀽閿欒锛�'
       } 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') {
@@ -861,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,
@@ -885,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
@@ -929,8 +1038,14 @@
             }
           }
 
-          return item
+          control.push(item)
         })
+
+        let down = false
+
+        if (rotate === 90 || rotate === 270) {
+          down = true
+        }
 
         _configparam = {
           Version: '',
@@ -939,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',
@@ -1070,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 = []
@@ -1229,24 +1353,31 @@
    */
   execSuccess = (res) => {
     const { btn } = this.props
-    const { autoMatic } = this.state
+    const { autoMatic, btnconfig } = this.state
 
-    if ((res && res.ErrCode === 'S') || 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) {
@@ -1291,7 +1422,8 @@
     }
     
     this.setState({
-      loading: false
+      loading: false,
+      confirmLoading: false
     })
 
     if (autoMatic) {
@@ -1411,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)
     })
   }
@@ -1431,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
@@ -1450,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) {
@@ -1525,8 +1664,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
 
@@ -1534,7 +1673,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)
     }
 
@@ -1549,6 +1688,7 @@
         getContainer={container}
         wrapClassName='action-modal'
         visible={this.state.visible}
+        confirmLoading={this.state.confirmLoading}
         width={width}
         onOk={this.handleOk}
         onCancel={this.handleCancel}
@@ -1557,7 +1697,6 @@
         <MutilForm
           BID={BID}
           dict={this.state.dict}
-          menuType={this.props.menuType}
           action={btnconfig}
           inputSubmit={this.handleOk}
           data={this.state.selines[0]}
@@ -1569,63 +1708,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銆乼ext銆� 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>
+      <span onClick={(e) => {e.stopPropagation()}}>{this.getModels()}</span>
+    </>
   }
 }
 
-const mapStateToProps = (state) => {
-  return {
-    menuType: state.editLevel
-  }
-}
-
-const mapDispatchToProps = () => {
-  return {}
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(PrintButton)
\ No newline at end of file
+export default PrintButton
\ No newline at end of file

--
Gitblit v1.8.0