From e5fc2d92b1036aabf9ffc2c9706ed401bd9735c8 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 09 九月 2021 18:14:29 +0800
Subject: [PATCH] 2021-09-09

---
 src/tabviews/zshare/actionList/printbutton/index.jsx |  382 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 328 insertions(+), 54 deletions(-)

diff --git a/src/tabviews/zshare/actionList/printbutton/index.jsx b/src/tabviews/zshare/actionList/printbutton/index.jsx
index 0117190..95a955f 100644
--- a/src/tabviews/zshare/actionList/printbutton/index.jsx
+++ b/src/tabviews/zshare/actionList/printbutton/index.jsx
@@ -3,7 +3,7 @@
 import moment from 'moment'
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { Button, Modal, notification, message } from 'antd'
+import { Button, Modal, notification, message, Icon } from 'antd'
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
@@ -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 { 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: '闇�瑕佷笂绾т富閿�硷紒',
@@ -177,17 +211,17 @@
 
     let printlist = []
     let templates = []
-    let printCount = 1
+    let printCount = +(formdata.printCount || formdata.PrintCount || formdata.printcount || formdata.Printcount || 1)
 
-    if (formdata.printCount && typeof(formdata.printCount) === 'number' && formdata.printCount >= 1) {
-      printCount = formdata.printCount
+    if (isNaN(printCount) || printCount < 1) {
+      printCount = 1
     }
 
     new Promise(resolve => {
       if (btn.intertype === 'system') { // 浣跨敤绯荤粺鏃讹紝鐩存帴浠庤〃鏍兼垨琛ㄥ崟涓�夊彇鏁版嵁
         let printcell = {}
 
-        printcell.printType = formdata.printType || ''
+        printcell.printType = formdata.printType || formdata.PrintType || formdata.printtype || formdata.Printtype || ''
         printcell.printCount = printCount
         printcell.templateID = btn.verify.Template || ''
 
@@ -211,12 +245,13 @@
               // 绯荤粺鎵撳嵃鏁版嵁锛屾牎楠宒ata瀛楁
               if (btn.verify.printMode !== 'custom' && (!cell.data || cell.data.length === 0)) return
 
-              cell.templateID = cell.templateID || btn.verify.Template
-              cell.printType = cell.printType || formdata.printType || ''
+              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 _printCount = printCount
-              if (cell.printCount && typeof(cell.printCount) === 'number' && cell.printCount >= 1) {
-                _printCount = cell.printCount
+              let _printCount = +(cell.printCount || cell.PrintCount || cell.printcount || cell.Printcount || 0)
+
+              if (isNaN(_printCount) || _printCount < 1) {
+                _printCount = printCount
               }
               
               cell.printCount = _printCount
@@ -268,6 +303,7 @@
 
       let errorMsg = ''
       let _temps = {}
+      let images = []
 
       result.forEach(res => {
         if (res.status && !errorMsg) {
@@ -281,6 +317,7 @@
               status: false
             }
           } else {
+            images = [...images, ..._temp.imgs]
             _temps[res.tempId] = _temp
           }
         } else if (!errorMsg) {
@@ -289,7 +326,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)
       }
@@ -313,6 +381,186 @@
       // eslint-disable-next-line
       let func = new Function('data', 'form', 'printer', 'notification', btn.verify.printFunc)
       func(printlist, formdata, btn.verify, notification)
+
+      // 鑷畾涔夋墦鍗扮ず渚�
+      // let defaultPrinter = printer.defaultPrinter || 'lackprinter'
+      // let printers = {}
+      // let getuuid = () => {
+      //   let uuid = []
+      //   let _options = '0123456789abcdefghigklmnopqrstuv'
+      //   for (let i = 0; i < 32; i++) {
+      //     uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1))
+      //   }
+      //   uuid = uuid.join('')
+      //   return uuid
+      // }
+      // if (printer.printerTypeList && printer.printerTypeList.length > 0) {
+      //   printer.printerTypeList.forEach(cell => {
+      //     if (cell.printer) {
+      //       printers[cell.Value] = cell.printer
+      //     }
+      //   })
+      // }
+
+      // let jdList = []
+      // let otherList = []
+      // data.forEach(item => {
+      //   if (item.CustomData) {
+      //     item.CustomData = JSON.parse(item.CustomData.replace(/\n/g,"\\n").replace(/\r/g,"\\r"))
+      //   }
+      //   if (item.PrintData) {
+      //     item.PrintData = JSON.parse(item.PrintData.replace(/\n/g,"\\n").replace(/\r/g,"\\r"))
+      //     item.PrintData.data = {...form, ...item.PrintData.data}
+      //   }
+        
+      //   if (!item.PrintData) {
+      //     return
+      //   }
+
+      //   if (item.PrintData.ectype === 'jdpop') {
+      //     jdList.push(item)
+      //   } else {
+      //     otherList.push(item)
+      //   }
+      // })
+
+      // if (jdList.length === 0 && otherList.length === 0) {
+      //   notification.warning({
+      //     top: 92,
+      //     message: '鏃犳墦鍗版暟鎹紒',
+      //     duration: 5
+      //   })
+      //   return
+      // }
+
+      // let execPrint = (list, linkUrl) => {
+      //   let printdata = {}
+
+      //   list.forEach(res => {
+      //     let _printer = defaultPrinter
+
+      //     if (res.printType && printers[res.printType]) {
+      //       _printer = printers[res.printType]
+      //     }
+
+      //     printdata[_printer] = printdata[_printer] || []
+
+      //     printdata[_printer].push(res)
+      //   })
+
+      //   let printerList = []
+
+      //   Object.keys(printdata).forEach(printer => {
+      //     let _documents = []
+      //     printdata[printer].forEach(item => {
+      //       let _cell = {
+      //         documentID: getuuid(),
+      //         contents: []
+      //       }
+
+      //       if (item.PrintData) {
+      //         _cell.contents.push(item.PrintData)
+      //       }
+      //       if (item.CustomData) {
+      //         _cell.contents.push(item.CustomData)
+      //       }
+
+      //       for (let i = 0; i < item.printCount; i++) {
+      //         _documents.push(_cell)
+      //       }
+      //     })
+      //     printerList.push({
+      //       cmd: 'print',
+      //       requestID: '',
+      //       version: '',
+      //       task: {
+      //         taskID: getuuid(),
+      //         preview: false,
+      //         printer: printer,
+      //         documents: _documents
+      //       }
+      //     })
+      //   })
+
+      //   let lackItems = printerList.filter(cell => cell.task.printer === 'lackprinter')[0]
+
+      //   let socket = new WebSocket('ws://' + linkUrl)
+
+      //   // 鎵撳紑Socket
+      //   socket.onopen = () =>{
+      //     if (lackItems) {
+      //       let request  = {
+      //         requestID: '',
+      //         version: '',
+      //         cmd: 'getPrinters'
+      //       }
+      //       socket.send(JSON.stringify(request))
+      //     } else {
+      //       printerList.forEach(cell => {
+      //         socket.send(JSON.stringify(cell).replace(/\\r/g,"\r").replace(/\\n/g,"\n"))
+      //       })
+
+      //       notification.success({
+      //         top: 92,
+      //         message: '鎵撳嵃璇锋眰宸插彂鍑恒��',
+      //         duration: 2
+      //       })
+      //     }
+      //   }
+      //   // 鐩戝惉娑堟伅
+      //   socket.onmessage = (event) => {
+      //     let data = ''
+
+      //     if (event.data) {
+      //       try {
+      //         data = JSON.parse(event.data)
+      //       } catch (e) {
+      //         notification.warning({
+      //           top: 92,
+      //           message: event.data,
+      //           duration: 10
+      //         })
+      //         data = ''
+      //       }
+      //     }
+
+      //     if (data && data.cmd === 'getPrinters' && data.status) {
+      //       printerList.forEach(cell => {
+      //         if (cell.task.printer === 'lackprinter') {
+      //           cell.task.printer = data.defaultPrinter
+      //         }
+      //         socket.send(JSON.stringify(cell).replace(/\\r/g,"\r").replace(/\\n/g,"\n"))
+      //       })
+
+      //       notification.success({
+      //         top: 92,
+      //         message: '鎵撳嵃璇锋眰宸插彂鍑恒��',
+      //         duration: 2
+      //       })
+      //     } else if (data && data.message && !data.status) {
+      //       notification.warning({
+      //         top: 92,
+      //         message: data.message,
+      //         duration: 10
+      //       })
+      //     }
+      //   }
+
+      //   socket.onerror = () => {
+      //     notification.warning({
+      //       top: 92,
+      //       message: '鏃犳硶杩炴帴鍒�:' + linkUrl,
+      //       duration: 10
+      //     })
+      //   }
+      // }
+
+      // if (jdList.length > 0) {
+      //   execPrint(jdList, '127.0.0.1:13529')
+      // }
+      // if (otherList.length > 0) {
+      //   execPrint(otherList, '127.0.0.1:13528')
+      // }
     } catch (e) {
       console.warn(e)
 
@@ -567,6 +815,7 @@
     let _configparam = ''  // 鎵撳嵃閰嶇疆淇℃伅
     let fields = []        // 妯℃澘涓墍闇�瀛楁
     let nonEFields = []    // 闈炵┖瀛楁
+    let imgs = []
 
     if (!res.ConfigParam) {
       error = '鏈幏鍙栧埌鎵撳嵃妯℃澘淇℃伅锛�'
@@ -580,7 +829,6 @@
       if (!configParam) {
         error = '鎵撳嵃妯℃澘瑙f瀽閿欒锛�'
       } else {
-        
         let control = configParam.elements.map(element => {
           let _field = element.field
 
@@ -627,6 +875,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
@@ -687,7 +941,8 @@
       error: error,
       config: _configparam,
       fields: fields,
-      nonEFields: nonEFields
+      nonEFields: nonEFields,
+      imgs: imgs
     }
   }
 
@@ -786,7 +1041,7 @@
             task: {
               taskID: Utils.getuuid(),
               preview: false,
-              printer: printer,
+              printer: printer === 'lackprinter' ? '' : printer,
               documents: [_cell]
             }
           })
@@ -833,19 +1088,19 @@
       return
     }
 
-    let lackItems = printerList.filter(cell => cell.task.printer === 'lackprinter')[0]
+    // let lackItems = printerList.filter(cell => cell.task.printer === 'lackprinter')[0]
 
     if (!socket || socket.readyState !== 1 || socket.url !== 'ws://' + btn.verify.linkUrl) {
       socket = new WebSocket('ws://' + btn.verify.linkUrl)
     } else {
-      if (lackItems) {
-        let request  = {
-          requestID: '',
-          version: '',
-          cmd: 'getPrinters'
-        }
-        socket.send(JSON.stringify(request))
-      } else {
+      // if (lackItems) {
+      //   let request  = {
+      //     requestID: '',
+      //     version: '',
+      //     cmd: 'getPrinters'
+      //   }
+      //   socket.send(JSON.stringify(request))
+      // } else {
         this.syncMessageSend(printerList)
 
         this.execSuccess({
@@ -854,19 +1109,19 @@
           ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��',
           status: true
         })
-      }
+      // }
     }
 
     // 鎵撳紑Socket
     socket.onopen = () =>{
-      if (lackItems) {
-        let request  = {
-          requestID: '',
-          version: '',
-          cmd: 'getPrinters'
-        }
-        socket.send(JSON.stringify(request))
-      } else {
+      // if (lackItems) {
+      //   let request  = {
+      //     requestID: '',
+      //     version: '',
+      //     cmd: 'getPrinters'
+      //   }
+      //   socket.send(JSON.stringify(request))
+      // } else {
         this.syncMessageSend(printerList)
 
         this.execSuccess({
@@ -875,7 +1130,7 @@
           ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��',
           status: true
         })
-      }
+      // }
     }
     // 鐩戝惉娑堟伅
     socket.onmessage = (event) => {
@@ -884,7 +1139,7 @@
       if (event.data) {
         try {
           data = JSON.parse(event.data)
-        } catch {
+        } catch (e) {
           this.execError({
             ErrCode: 'N',
             message: event.data,
@@ -896,23 +1151,24 @@
         }
       }
 
-      if (data && data.cmd === 'getPrinters' && data.status) {
-        printerList = printerList.map(cell => {
-          if (cell.task.printer === 'lackprinter') {
-            cell.task.printer = data.defaultPrinter
-          }
-          return cell
-        })
+      // if (data && data.cmd === 'getPrinters' && data.status) {
+      //   printerList = printerList.map(cell => {
+      //     if (cell.task.printer === 'lackprinter') {
+      //       cell.task.printer = data.defaultPrinter
+      //     }
+      //     return cell
+      //   })
 
-        this.syncMessageSend(printerList)
+      //   this.syncMessageSend(printerList)
 
-        this.execSuccess({
-          ErrCode: 'S',
-          message: '',
-          ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��',
-          status: true
-        })
-      } else if (data && data.message && !data.status) {
+      //   this.execSuccess({
+      //     ErrCode: 'S',
+      //     message: '',
+      //     ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��',
+      //     status: true
+      //   })
+      // } else if (data && data.message && !data.status) {
+      if (data && data.message && !data.status) {
         this.execError({
           ErrCode: 'N',
           message: data.message,
@@ -1250,28 +1506,46 @@
 
   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>
         {this.getModels()}
       </div>
     } else { // icon銆乼ext銆� all 鍗$墖
+      let label = ''
+      let icon = ''
+
+      if (show === 'button') {
+        label = btn.label
+        icon = btn.icon || ''
+      } else if (show === 'link') {
+        label = <span>{btn.label}{btn.icon ? <Icon 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={show === 'text' ? '' : (btn.icon || '')}
+          icon={icon}
           onClick={() => {this.actionTrigger()}}
-        >{show === 'icon' && btn.icon ? '' : btn.label}</Button>
+        >{label}</Button>
         {this.getModels()}
       </div>
     }

--
Gitblit v1.8.0